public void SumGoodsTest_4筆一組_取Revenue總和() { IGroupPagingContext context = Substitute.For<IGroupPagingContext>(); context.Goodies.Returns(_goods); GroupPagingService target = new GroupPagingService(context); List<int> actual = target.SumGoods(GroupPagingType.Revenue, 4).ToList(); List<int> expected = new List<int> { 50, 66, 60 }; CollectionAssert.AreEqual(expected, actual); }
public void SumGoodsTest_3筆一組_取Cost總和() { IGroupPagingContext context = Substitute.For<IGroupPagingContext>(); context.Goodies.Returns(_goods); GroupPagingService target = new GroupPagingService(context); List<int> actual = target.SumGoods(GroupPagingType.Cost, 3).ToList(); List<int> expected = new List<int> { 6, 15, 24, 21 }; 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); IGroupPagingService service = new GroupPagingService(context); List<int> actual = service.SumGoodsCost(3).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void SumGoodsRevenueTest_4筆一組_取Revenue總和() { List<decimal> expected = new List<decimal>() { 50, 66, 60 }; IGroupPagingContext context = Substitute.For<IGroupPagingContext>(); context.Goodies.Returns(_target); IGroupPagingService service = new GroupPagingService(context); List<decimal> actual = service.SumGoodsRevenue(4).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); }