-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathStockLogicTests.cs
92 lines (69 loc) · 3.23 KB
/
StockLogicTests.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
using GetStock.Adapters;
using GetStock.Adapters.Exceptions;
using GetStock.Adapters.Model;
using GetStock.Domains;
using GetStock.Domains.Models;
using static GetStock.Utilities.CollectionUtils;
namespace GetStock.UnitTest.Domains
{
public class StockLogicTests
{
[Fact]
public async Task RetrieveStockValues_With_StockInDBNoCurrenciesInService_Should_ReturnOnlyStockValueInUSD()
{
using var fake = new AutoFake();
var fakeStockDb = fake.Resolve<IStockDB>();
A.CallTo(() => fakeStockDb.GetStockValueAsync(A<string>._)).Returns(Task.FromResult(new StockData
{
StockId = "stock-1",
Value = 100
}));
var fakeCurrencyConverter = fake.Resolve<ICurrencyConverter>();
IDictionary<string, double> emptyDictionary = new Dictionary<string, double>();
A.CallTo(() => fakeCurrencyConverter.GetCurrencies(A<string>._, An<IEnumerable<string>>._))
.Returns(Task.FromResult(emptyDictionary));
var target = fake.Resolve<StockLogic>();
var result = await target.RetrieveStockValuesAsync("stock-1");
var expected = new StockWithCurrencies("stock-1", new[] { ToPair("EUR", 100.0) });
result.Should().BeEquivalentTo(expected);
}
[Fact]
public async Task RetrieveStockValues_With_StockInDbCurrenciesReturnedFromSewrvice_Should_ReturnListOfCurrencyValues()
{
using var fake = new AutoFake();
var fakeStockDb = fake.Resolve<IStockDB>();
A.CallTo(() => fakeStockDb.GetStockValueAsync(A<string>._)).Returns(Task.FromResult(new StockData
{
StockId = "stock-1",
Value = 100
}));
var fakeCurrencyConverter = fake.Resolve<ICurrencyConverter>();
IDictionary<string, double> currency = new Dictionary<string, double>
{
{"USD", 2 }
};
A.CallTo(() => fakeCurrencyConverter.GetCurrencies(A<string>._, An<IEnumerable<string>>._))
.Returns(Task.FromResult(currency));
var target = fake.Resolve<StockLogic>();
var result = await target.RetrieveStockValuesAsync("stock-1");
var expected = new StockWithCurrencies("stock-1", new[]
{
ToPair("EUR", 100.0),
ToPair("USD", 200.0)
});
result.Should().BeEquivalentTo(expected);
}
[Fact]
public async Task RetrieveStockValues_With_StockNotFoundInDb_Should_ReturnEmptyList()
{
using var fake = new AutoFake();
var fakeStockDb = fake.Resolve<IStockDB>();
A.CallTo(() => fakeStockDb.GetStockValueAsync(A<string>._))
.Throws<StockNotFoundException>();
var target = fake.Resolve<StockLogic>();
var result = await target.RetrieveStockValuesAsync("stock-1");
var expected = new StockWithCurrencies("stock-1", Array.Empty<KeyValuePair<string, double>>());
result.Should().BeEquivalentTo(expected);
}
}
}