public async Task ShouldReturnARateAndIndicateThatItShouldDivideTheAmountWhenConvertingToAccountCurrency() { //Arrange var wrapperExchangeRateAPI = NSubstitute.Substitute.For <IWrapperExchangeRateAPI>(); var cachedExchangeRateRepository = NSubstitute.Substitute.For <ICachedExchangeRateRepository>(); cachedExchangeRateRepository.GetRate(Arg.Any <DateTime>(), "USD", "EUR").Returns(new System.Collections.Generic.List <CachedExchangeRate> { new CachedExchangeRate { CurrencyCodeFrom = "EUR", CurrencyCodeTo = "USD", Rate = 1.18M, RateDate = DateTime.Today } }); var exchangeRateService = new ExchangeRateService(wrapperExchangeRateAPI, cachedExchangeRateRepository); //Act var result = await exchangeRateService.GetExchangeRate(DateTime.Today, "USD", "EUR"); //Assert result.Should().NotBeNull(); result.Rate.Should().Be(1.18M); result.IsBaseCurrencySameAsTo.Should().BeTrue(); }
public void Should_Return_the_expected_exchange() { var effortContext = new BankSystemContext(Effort.DbConnectionFactory.CreateTransient()); var exchangeCheck = new ExchangeRateModel() { FromCurrency = (Currency)840, ToCurrency = (Currency)975, }; var exchangeAdd = new ExchangeRate() { FromCurrency = (Currency)840, ToCurrency = (Currency)975, Rate = 0.5m, IsDeleted = false }; effortContext.ExchangeRates.Add(exchangeAdd); effortContext.SaveChanges(); var sut = new ExchangeRateService(effortContext); //Act & Assert Assert.IsTrue(sut.GetExchangeRate(exchangeCheck) == 0.5m); }
public async Task ShouldNotCallTheVendorAPIWhenThereIsDataInTheDatabase() { //Arrange var wrapperExchangeRateAPI = NSubstitute.Substitute.For <IWrapperExchangeRateAPI>(); var cachedExchangeRateRepository = NSubstitute.Substitute.For <ICachedExchangeRateRepository>(); cachedExchangeRateRepository.GetRate(Arg.Any <DateTime>(), "USD", "EUR").Returns(new System.Collections.Generic.List <CachedExchangeRate> { new CachedExchangeRate { CurrencyCodeFrom = "EUR", CurrencyCodeTo = "USD", Rate = 1.18M, RateDate = DateTime.Today } }); var exchangeRateService = new ExchangeRateService(wrapperExchangeRateAPI, cachedExchangeRateRepository); //Act await exchangeRateService.GetExchangeRate(DateTime.Today, "USD", "EUR"); //Assert await wrapperExchangeRateAPI.DidNotReceive().GetLatestRates(); }
public void GetExchangeRate_DoesNotThrowException() { // arrange ExchangeRateService svc = new ExchangeRateService(); // act assert Assert.DoesNotThrow(() => svc.GetExchangeRate("EUR", "RUB")); }
public void Should_Return_ArgumentNullException_When_ExchangeModel_is_Null() { var effortContext = new BankSystemContext(Effort.DbConnectionFactory.CreateTransient()); var sut = new ExchangeRateService(effortContext); Assert.ThrowsException <ArgumentNullException>(() => sut.GetExchangeRate(null)); }
public void GetExchangeRate_EURToRUB_ReturnsGreaterThanZero() { // arrange ExchangeRateService svc = new ExchangeRateService(); // act var exchangeRate = svc.GetExchangeRate("EUR", "RUB"); // assert Assert.Greater(exchangeRate, 0); }
public async Task ShouldReturnARateEqualsTo1WhenBothCurrenciesAreTheSame() { //Arrange var wrapperExchangeRateAPI = NSubstitute.Substitute.For <IWrapperExchangeRateAPI>(); var cachedExchangeRateRepository = NSubstitute.Substitute.For <ICachedExchangeRateRepository>(); var exchangeRateService = new ExchangeRateService(wrapperExchangeRateAPI, cachedExchangeRateRepository); //Act var result = await exchangeRateService.GetExchangeRate(DateTime.Today, "EUR", "EUR"); //Assert result.Rate.Should().Be(1); }
public async Task ShouldReturnAnEmptyResultWhenThereIsNoDataAvailable() { //Arrange var wrapperExchangeRateAPI = NSubstitute.Substitute.For <IWrapperExchangeRateAPI>(); var cachedExchangeRateRepository = NSubstitute.Substitute.For <ICachedExchangeRateRepository>(); cachedExchangeRateRepository.GetRate(Arg.Any <DateTime>(), "EUR", "USD").Returns(new System.Collections.Generic.List <CachedExchangeRate>()); var exchangeRateService = new ExchangeRateService(wrapperExchangeRateAPI, cachedExchangeRateRepository); //Act var result = await exchangeRateService.GetExchangeRate(DateTime.Today, "EUR", "USD"); //Assert result.Should().BeNull(); }
public void Should_Return_1_When_The_Same_Currency_is_used() { var effortContext = new BankSystemContext(Effort.DbConnectionFactory.CreateTransient()); var sut = new ExchangeRateService(effortContext); var exchange = new ExchangeRateModel() { FromCurrency = (Currency)840, ToCurrency = (Currency)840 }; //Act & Assert Assert.IsTrue(sut.GetExchangeRate(exchange) == 1); }
public void Should_Return_ArgumentNullException_When_Exchange_is_Null() { var effortContext = new BankSystemContext(Effort.DbConnectionFactory.CreateTransient()); var sut = new ExchangeRateService(effortContext); var exchange = new ExchangeRateModel() { FromCurrency = (Currency)840, ToCurrency = (Currency)986 }; //Act & Assert Assert.ThrowsException <ArgumentException>(() => sut.GetExchangeRate(exchange)); }
public async Task ShouldReturnEmptyResultInCaseTheVendorApiFails() { //Arrange var cachedExchangeRateRepository = NSubstitute.Substitute.For <ICachedExchangeRateRepository>(); var httpClientFactory = NSubstitute.Substitute.For <IHttpClientFactory>(); var logger = NSubstitute.Substitute.For <ILogger <WrapperExchangeRateAPI> >(); var wrapperExchangeRateAPI = new WrapperExchangeRateAPI(httpClientFactory, logger); cachedExchangeRateRepository.GetRate(Arg.Any <DateTime>(), "USD", "EUR").Returns(new System.Collections.Generic.List <CachedExchangeRate>()); var exchangeRateService = new ExchangeRateService(wrapperExchangeRateAPI, cachedExchangeRateRepository); //Act var result = await exchangeRateService.GetExchangeRate(DateTime.Today, "USD", "EUR"); //Assert result.Should().BeNull(); }