-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoreTests.cs
93 lines (87 loc) · 3.18 KB
/
StoreTests.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using FluentAssertions;
using NUnit.Framework;
using System;
using System.Collections.Generic;
namespace ProductManager
{
[TestFixture]
public class StoreTests
{
[TestCase(2020, ExpectedResult = "1) Product 1 - 3 item(s)\r\n2) Product 2 - 1 item(s)\r\n3) Product 3 - 1 item(s)")]
[TestCase(2021, ExpectedResult = "1) Product 4 - 8 item(s)\r\n2) Product 5 - 2 item(s)")]
public string ShouldProductStatisticsReturnReportOnYear(int year)
{
Store store = new Store()
{
Orders = TestDataFixture.GetOrderList,
Products = TestDataFixture.GetProductList
};
return store.GetProductStatistics(year);
}
[Test]
public void ShouldStoreGetYearsStatistics()
{
Store store = new Store()
{
Orders = TestDataFixture.GetOrderList,
Products = TestDataFixture.GetProductList
};
store.GetYearsStatistics()
.Should()
.Be("2021 - 802 руб.\r\nMost selling: Product 4 (8 item(s))\r\n\r\n2020 - 16000 руб.\r\nMost selling: Product 1 (3 item(s))");
}
}
public static class TestDataFixture
{
public static List<Product> GetProductList => new List<Product>
{
new() { Id = 1, Name = "Product 1", Price = 1000d },
new() { Id = 2, Name = "Product 2", Price = 3000d },
new() { Id = 3, Name = "Product 3", Price = 10000d },
new() { Id = 4, Name = "Product 4", Price = 100d },
new() { Id = 5, Name = "Product 5", Price = 1d }
};
public static List<Order> GetOrderList => new List<Order>
{
new()
{
UserId = 1,
OrderDate = DateTime.UtcNow.AddYears(-2),
Items = new List<Order.OrderItem>
{
new() { ProductId = 1, Quantity = 2 }
}
},
new()
{
UserId = 3,
OrderDate = DateTime.UtcNow.AddYears(-2),
Items = new List<Order.OrderItem>
{
new() { ProductId = 1, Quantity = 1 },
new() { ProductId = 2, Quantity = 1 },
new() { ProductId = 3, Quantity = 1 }
}
},
new()
{
UserId = 2,
OrderDate = DateTime.UtcNow.AddYears(-1),
Items = new List<Order.OrderItem>
{
new() { ProductId = 4, Quantity = 2 },
}
},
new()
{
UserId = 2,
OrderDate = DateTime.UtcNow.AddYears(-1),
Items = new List<Order.OrderItem>
{
new() { ProductId = 4, Quantity = 6 },
new() { ProductId = 5, Quantity = 2 }
}
},
};
}
}