public void SumGoodsCostTest_3筆一組_取Cost總和() { List<int> expected = new List<int>() { 6, 15, 24, 21 }; IGroupPagingContext context = Substitute.For<IGroupPagingContext>(); context.Goodies.Returns(_target); IGroupPagingService service = new GroupPagingService(context); List<int> actual = service.SumGoodsCost(3).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void SumGoodsCostTest_3筆一組_取Cost總和() { List<int> expected = new List<int>() { 6, 15, 24, 21 }; IGroupPagingContext context = Substitute.For<IGroupPagingContext>(); context.Goodies.Returns(_target); // 既然是測試 GroupPagingService,建議宣告的部分就不要用 IGroupPagingService,在所有的單元測試中,測試目標的宣告都不需要用 interface, 因為我要測的就是測試目標,而不是介面。 IGroupPagingService service = new GroupPagingService(context); // SumGoodsCost(int pageSize)的方法比較沒有彈性,需求是希望用同一個方法,就可以讓呼叫端決定這一次要「幾筆一組」,「取哪個欄位的總和」 List<int> actual = service.SumGoodsCost(3).ToList(); CollectionAssert.AreEqual(expected, actual); }