예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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)));
 }
예제 #4
0
 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)));
 }
예제 #5
0
 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));
 }
예제 #6
0
 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));
 }
예제 #7
0
 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)));
 }