/
Day1HomeWorkTest.cs
70 lines (59 loc) · 2.34 KB
/
Day1HomeWorkTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExpectedObjects;
using NSubstitute;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace InternalLibTests
{
[TestClass()]
class Day1HomeWorkTest
{
private List<Product> _products;
[ClassInitialize]
public void ProductInitialize(TestContext testContext)
{
_products = new List<Product>
{
new Product {Id = 1, Cost= 1, Revenue = 11, SellPrice = 21},
new Product {Id = 2, Cost= 2, Revenue = 12, SellPrice = 22},
new Product {Id = 3, Cost= 3, Revenue = 13, SellPrice = 23},
new Product {Id = 4, Cost= 4, Revenue = 14, SellPrice = 24},
new Product {Id = 5, Cost= 5, Revenue = 15, SellPrice = 25},
new Product {Id = 6, Cost= 6, Revenue = 16, SellPrice = 26},
new Product {Id = 7, Cost= 7, Revenue = 17, SellPrice = 27},
new Product {Id = 8, Cost= 8, Revenue = 18, SellPrice = 28},
new Product {Id = 9, Cost= 9, Revenue = 19, SellPrice = 29},
new Product {Id = 10, Cost=10, Revenue = 20, SellPrice = 30},
new Product {Id = 11, Cost=11, Revenue = 21, SellPrice = 31},
};
}
[TestMethod()]
public void getCostSumBy3()
{
//arrange
IProductDao products = Substitute.For<IProductDao>();
products.getData().Returns(_products);
var target = new ProductPaging();
string fieldName = "Cost";
int groupNumber = 3;
//act
var actual = target.getSumByFieldName(fieldName, groupNumber);
var excepted = new int[] { 6, 15, 24, 24 };
//assert
excepted.ToExpectedObject().ShouldEqual(actual);
}
[TestMethod()]
public void getRevenueSumBy4()
{
var target = new ProductPaging();
string fieldName = "Revenue";
int groupNumber = 4;
var actual = target.getSumByFieldName(fieldName, groupNumber);
var excepted = new int[] { 50, 66, 60 };
excepted.ToExpectedObject().ShouldEqual(actual);
}
}
}