public async Task ExchangeRate_SekToNokOn20180201_Returns0954686939716339() { var unitUnderTest = new ExchangeRateFetcher(new RestClient()); var rate = await unitUnderTest.FetchExchangeRate("SEK", "NOK", new DateTime(2018, 03, 01)); Assert.Equal(0.9546869397, rate.Rate, 10); }
public async Task FetchExchangeRate_ValidRequest_Success() { var restClientMock = new Mock <IRestClient>(); var restResponseMock = new Mock <IRestResponse>(); restResponseMock.Setup(m => m.Content).Returns("{\"base\":\"EUR\",\"rates\":{\"2018-03-01\":{\"USD\":1}},\"end_at\":\"2018-03-01\",\"start_at\":\"2018-03-01\"}"); restClientMock.Setup(m => m.ExecuteGetTaskAsync(It.IsAny <IRestRequest>())).ReturnsAsync(restResponseMock.Object); var unitUnderTest = new ExchangeRateFetcher(restClientMock.Object); var rate = await unitUnderTest.FetchExchangeRate("EUR", "USD", DateTime.Now.AddDays(-1)); Assert.Equal(1, rate.Rate); }
public async Task FetchExchangeRate_ExchangeRateBefore1999_ThrowsException() { var restClientMock = new Mock <IRestClient>(); var unitUnderTest = new ExchangeRateFetcher(restClientMock.Object); await Assert.ThrowsAsync <ArgumentException>(() => unitUnderTest.FetchExchangeRate("EUR", "USD", new DateTime(1990, 2, 1))); }
public async Task FetchExchangeRate_ExchangeRateInFuture_ThrowsException() { var restClientMock = new Mock <IRestClient>(); var unitUnderTest = new ExchangeRateFetcher(restClientMock.Object); await Assert.ThrowsAsync <ArgumentException>(() => unitUnderTest.FetchExchangeRate("EUR", "USD", DateTime.Now.AddDays(1))); }
public async Task FetchExchangeRate_TargetCurrencyIsNull_ThrowsException() { var restClientMock = new Mock <IRestClient>(); var unitUnderTest = new ExchangeRateFetcher(restClientMock.Object); await Assert.ThrowsAsync <ArgumentNullException>(() => unitUnderTest.FetchExchangeRate("EUR", null, DateTime.Now)); }
public async Task FetchExchangeRate_InvalidTargetCurrency_ThrowsException(string targetCurrency) { var restClientMock = new Mock <IRestClient>(); var unitUnderTest = new ExchangeRateFetcher(restClientMock.Object); await Assert.ThrowsAsync <ArgumentException>(() => unitUnderTest.FetchExchangeRate("EUR", targetCurrency, DateTime.Now)); }
public async Task ExchangeRate_UnknownCurrency_ThrowsException() { var unitUnderTest = new ExchangeRateFetcher(new RestClient()); await Assert.ThrowsAsync <Exception>(() => unitUnderTest.FetchExchangeRate("AAA", "NOK", new DateTime(2018, 03, 01))); }