0

私はテストを始めたばかりで、MSpec を使用したことがありません。私はチュートリアルを見ましたが、唯一の例は のような「ライト」です1 + 1 should be 2。この実際の方法をテストする必要がありますが、どこから始めればよいかわかりません。

 public ILineItem CreateLineItem(BaseVariationContent sku, int quantityToAdd)
 {
    var price = sku.GetDefaultPrice();
    var parent = sku.GetParentProducts().FirstOrDefault() != null ? _contentLoader.Get<ProductContent>(sku.GetParentProducts().FirstOrDefault()).Code : string.Empty;

    return new LineItem
       {
          Code = sku.Code,
          DisplayName = sku.DisplayName,
          Description = sku.Description,
          Quantity = quantityToAdd,
          PlacedPrice = price.UnitPrice.Amount,
          ListPrice = price.UnitPrice.Amount,
          Created = DateAndTime.Now,
          MaxQuantity = sku.MaxQuantity ?? 100,
          MinQuantity = sku.MinQuantity ?? 1,
          InventoryStatus = sku.TrackInventory ? (int)InventoryStatus.Enabled : (int)InventoryStatus.Disabled, 
          WarehouseCode = string.Empty, // TODO: Add warehouse id
          ParentCatalogEntryId = parent,
       };
 }

BaseVariationContent多くのプロパティを持つ単なるクラスであり、拡張機能があります。

4

1 に答える 1

3

MSpec github リポジトリには、MSpec テスト クラスとテスト ケースの基本的な構文コンポーネントを説明する非常に優れた README があります。

https://github.com/machine/machine.specifications#machinespecifications

テストの詳細については説明しませんが、mspec テストをセットアップするための重要な部分を示します。

[Subject("Line Item")]
public class When_creating_a_basic_line_item_from_generic_sku()
{
    Establish context = () => 
    {
        // you would use this if the Subject's constructor
        // required more complicated setup, mocks, etc.
    }

    Because of = () => Subject.CreateLineItem(Sku, Quantity);

    It should_be_in_some_state = () => Item.InventoryStatus.ShouldEqual(InventoryStatus.Enabled);

    private static Whatever Subject = new Whatever();
    private static BaseVariationContent Sku = new GenericSku();
    private static int Quantity = 1;
    private static ILineItem Item;
}

これらのテストを実行する必要があるため、コマンドライン ツールを使用します。

https://github.com/machine/machine.specifications#command-line-reference

または統合の1つ

https://github.com/machine/machine.specifications#resharper-integration

于 2015-11-16T23:28:28.820 に答える