0

这是我的代码:

public int GetTotalIssuedCount()
{
    var storeCode = Store.Current.Code.ToLower();
    return (from i in Context.Instance.EduContainer.IssueDetailsSet
            where i.Status.ToLower() == "issued" && i.Store.Code == storeCode
            select i).Count();
}

这是我的测试代码:

[TestMethod]
public void GetTotalIssuedCountTest()
{
    StoreRepository sr = new StoreRepository();
    Assert.IsInstanceOfType();
}

哪种断言方法适合这里?

4

1 回答 1

2

给定基础数据集状态,您需要断言 count 是否符合您的预期:

[TestMethod]
public void GetTotalIssuedCountTest()
{
   // The 5 is exemplary value -
   // you need to determine actual one basing data set contents
   const int expectedIssuedCount = 5;
   var storeRepository = new StoreRepository();
   // Here you'll most likely need to prepare fake data set
   var actualIssuedCount = storeRepository.GetTotalIssuedCount();

   Assert.AreEqual(expectedIssuedCount, actualIssuedCount);
}

要使其工作,您需要设置您的方法将访问的数据集 ( )。EduContainer.IssueDetailsSet您很可能需要模拟依赖注入来实现这一点。

于 2013-07-13T12:52:16.550 回答