-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetUp.cs
50 lines (44 loc) · 1.27 KB
/
SetUp.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
[SetUp]
public async Task SetUp()
{
await _collection.DeleteManyAsync(FilterDefinition<Product>.Empty);
var products = new[]
{
new Product { Category = "Books", Price = 10 },
new Product { Category = "Books", Price = 15 },
new Product { Category = "Electronics", Price = 100 },
new Product { Category = "Electronics", Price = 150 },
};
await _collection.InsertManyAsync(products);
}
[Test]
public async Task Test_Aggregate_GroupByCategory_SumsPrices_StronglyTyped()
{
// Act
var aggregation = _collection.Aggregate()
.Group(
p => p.Category,
g => new CategoryTotal
{
Category = g.Key,
TotalPrice = g.Sum(p => p.Price)
});
var resultList = await aggregation.ToListAsync();
// Assert
Assert.AreEqual(2, resultList.Count);
foreach (var categoryTotal in resultList)
{
if (categoryTotal.Category == "Books")
{
Assert.AreEqual(25, categoryTotal.TotalPrice);
}
else if (categoryTotal.Category == "Electronics")
{
Assert.AreEqual(250, categoryTotal.TotalPrice);
}
else
{
Assert.Fail("Unexpected category found.");
}
}
}