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(); A.CallTo(() => fakeStockDb.GetStockValueAsync(A._)).Returns(Task.FromResult(new StockData { StockId = "stock-1", Value = 100 })); var fakeCurrencyConverter = fake.Resolve(); IDictionary emptyDictionary = new Dictionary(); A.CallTo(() => fakeCurrencyConverter.GetCurrencies(A._, An>._)) .Returns(Task.FromResult(emptyDictionary)); var target = fake.Resolve(); 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(); A.CallTo(() => fakeStockDb.GetStockValueAsync(A._)).Returns(Task.FromResult(new StockData { StockId = "stock-1", Value = 100 })); var fakeCurrencyConverter = fake.Resolve(); IDictionary currency = new Dictionary { {"USD", 2 } }; A.CallTo(() => fakeCurrencyConverter.GetCurrencies(A._, An>._)) .Returns(Task.FromResult(currency)); var target = fake.Resolve(); 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(); A.CallTo(() => fakeStockDb.GetStockValueAsync(A._)) .Throws(); var target = fake.Resolve(); var result = await target.RetrieveStockValuesAsync("stock-1"); var expected = new StockWithCurrencies("stock-1", Array.Empty>()); result.Should().BeEquivalentTo(expected); } } }