public void Can_Get_All()
        {
            // Act
            var rates = Service.GetAsync().Result;

            // Assert
            OnlineRepository.Verify(x => x.GetAll(), Times.Once);
            Assert.Single(rates);
        }
        public void Can_Get_All()
        {
            // Act
            var rates = TestController.Get().Result;

            // Assert
            OnlineRepository.Verify(x => x.GetAll(), Times.Once);
            Assert.Single(rates.Result);
        }
        public void Can_Filter_Rates()
        {
            // Arrange
            var From = "USD";

            // Act
            var filteredRates = Service.Where(s => s.From == From).First();

            // Assert
            OnlineRepository.Verify(x => x.Where(s => s.From == From), Times.Once);
            Assert.Equal(From, filteredRates.From);
            Assert.Equal("CAD", filteredRates.To);
        }
Пример #4
0
        public void Can_Filter_Rates()
        {
            // Arrange
            var SKU = "2600";

            // Act
            var filteredRates = Service.Where(s => s.SKU == SKU).First();

            // Assert
            OnlineRepository.Verify(x => x.Where(s => s.SKU == SKU), Times.Once);
            Assert.Equal(SKU, filteredRates.SKU);
            Assert.Equal("CAD", filteredRates.Currency);
        }
        public void Can_Get_From_Local_When_Online_Empty()
        {
            // Arrange
            var From = "USD";

            OnlineRepository.Setup(x => x.GetAll())
            .ReturnsAsync(Enumerable.Empty <CurrencyRate>());
            OnlineRepository.Setup(x => x.Where(It.IsAny <Expression <Func <CurrencyRate, bool> > >()))
            .Returns((Expression <Func <CurrencyRate, bool> > exp) => Enumerable.Empty <CurrencyRate>());

            // Act
            var rates         = TestController.Get().Result;
            var filteredRates = Service.Where(s => s.From == From).First();

            // Assert
            OnlineRepository.Verify(x => x.GetAll(), Times.Once);
            LocalRepository.Verify(x => x.GetAll(), Times.Once);
            Assert.Single(rates.Result);
            OnlineRepository.Verify(x => x.Where(s => s.From == From), Times.Once);
            LocalRepository.Verify(x => x.Where(s => s.From == From), Times.Once);
            Assert.Equal(From, filteredRates.From);
            Assert.Equal("CAD", filteredRates.To);
        }
        public void Can_Get_From_Local_When_Online_Not_Available()
        {
            // Arrange
            var From = "USD";

            OnlineRepository.Setup(x => x.GetAll())
            .Throws(new Exception());
            OnlineRepository.Setup(x => x.Where(It.IsAny <Expression <Func <CurrencyRate, bool> > >()))
            .Throws(new Exception());

            // Act
            var transactions         = TestController.Get().Result;
            var filteredTransactions = Service.Where(s => s.From == From).First();

            // Assert
            OnlineRepository.Verify(x => x.GetAll(), Times.Once);
            LocalRepository.Verify(x => x.GetAll(), Times.Once);
            Assert.Single(transactions.Result);
            OnlineRepository.Verify(x => x.Where(s => s.From == From), Times.Once);
            LocalRepository.Verify(x => x.Where(s => s.From == From), Times.Once);
            Assert.Equal(From, filteredTransactions.From);
            Assert.Equal("CAD", filteredTransactions.To);
        }
Пример #7
0
        public void Can_Get_From_Local_When_Online_Empty()
        {
            // Arrange
            var SKU = "2600";

            OnlineRepository.Setup(x => x.GetAll())
            .ReturnsAsync(Enumerable.Empty <ProductTransaction>());
            OnlineRepository.Setup(x => x.Where(It.IsAny <Expression <Func <ProductTransaction, bool> > >()))
            .Returns((Expression <Func <CurrencyRate, bool> > exp) => Enumerable.Empty <ProductTransaction>());

            // Act
            var rates         = Service.GetAsync().Result;
            var filteredRates = Service.Where(s => s.SKU == SKU).First();

            // Assert
            OnlineRepository.Verify(x => x.GetAll(), Times.Once);
            LocalRepository.Verify(x => x.GetAll(), Times.Once);
            Assert.Single(rates);
            OnlineRepository.Verify(x => x.Where(s => s.SKU == SKU), Times.Once);
            LocalRepository.Verify(x => x.Where(s => s.SKU == SKU), Times.Once);
            Assert.Equal(SKU, filteredRates.SKU);
            Assert.Equal("CAD", filteredRates.Currency);
        }
Пример #8
0
        public void Can_Get_From_Local_When_Online_Not_Available()
        {
            // Arrange
            var SKU = "2600";

            OnlineRepository.Setup(x => x.GetAll())
            .Throws(new Exception());
            OnlineRepository.Setup(x => x.Where(It.IsAny <Expression <Func <ProductTransaction, bool> > >()))
            .Throws(new Exception());

            // Act
            var rates         = Service.GetAsync().Result;
            var filteredRates = Service.Where(s => s.SKU == SKU).First();

            // Assert
            OnlineRepository.Verify(x => x.GetAll(), Times.Once);
            LocalRepository.Verify(x => x.GetAll(), Times.Once);
            Assert.Single(rates);
            OnlineRepository.Verify(x => x.Where(s => s.SKU == SKU), Times.Once);
            LocalRepository.Verify(x => x.Where(s => s.SKU == SKU), Times.Once);
            Assert.Equal(SKU, filteredRates.SKU);
            Assert.Equal("CAD", filteredRates.Currency);
        }