public void WhenRatesRequestIsNull_ThenGetThrows()
        {
            var cachingAccess = new CachingExchangeRatesAccess(
                new MemoryCache("rates"),
                Mock.Of <IExchangeRatesAccess>());

            var getFunc = new Func <Task>(() => cachingAccess.GetRates(null));

            getFunc.Should().Throw <ArgumentNullException>().WithMessage("*request*");
        }
        public void WhenDefaultRequestIsRetrieved_ThenItIsTheDefaultOfTheInjectedAccess()
        {
            var expectedRequest = new ExchangeRatesRequest("BASEBASE", DateTime.UtcNow);

            var injectedAccess = new Mock <IExchangeRatesAccess>();

            injectedAccess.SetupGet(m => m.DefaultRequest).Returns(expectedRequest);

            var cachingAccess = new CachingExchangeRatesAccess(
                new MemoryCache("name"),
                injectedAccess.Object);

            var defaultRequest = cachingAccess.DefaultRequest;

            defaultRequest.Should().BeEquivalentTo(expectedRequest);
        }
        public async Task WhenCacheDoesNotContainItem_ThenAccessIsInvoked()
        {
            var expectedRequest = new ExchangeRatesRequest("BASE", DateTime.UtcNow);
            var accessMock      = new Mock <IExchangeRatesAccess>();

            ExchangeRatesRequest actualRequest = null;

            accessMock.Setup(m => m.GetRates(It.IsAny <ExchangeRatesRequest>()))
            .Callback <ExchangeRatesRequest>(request => actualRequest = request)
            .ReturnsAsync(new ExchangeRatesResponse(
                              expectedRequest.BaseCurrency,
                              expectedRequest.Date,
                              new Dictionary <string, decimal>()));

            var cachingAccess = new CachingExchangeRatesAccess(new MemoryCache("rates"), accessMock.Object);

            await cachingAccess.GetRates(expectedRequest);

            actualRequest.Should().BeEquivalentTo(expectedRequest);
        }