예제 #1
0
        public void SaveCurrencyRate_RateIsNotNull_NewRateIsSaved()
        {
            var expected = new Database.Models.CurrencyRate {
                Id = 4, Day = DateTime.Today, BaseCurrency = "EUR", TargetCurrency = "GBP", Rate = 0.85m
            };

            var initialData = new List <Database.Models.CurrencyRate>
            {
                new Database.Models.CurrencyRate {
                    Id = 1, Day = DateTime.Today.AddDays(-3), BaseCurrency = "EUR", TargetCurrency = "GBP", Rate = 0.85m
                },
                new Database.Models.CurrencyRate {
                    Id = 2, Day = DateTime.Today.AddDays(-2), BaseCurrency = "EUR", TargetCurrency = "GBP", Rate = 0.85m
                },
                new Database.Models.CurrencyRate {
                    Id = 3, Day = DateTime.Today.AddDays(-1), BaseCurrency = "EUR", TargetCurrency = "GBP", Rate = 0.85m
                }
            };

            var context = new Mock <ICurrencyRatesContext>();

            context.Setup(_ => _.CurrencyRates).Returns(DbSetMocking.CreateMockSet(initialData.AsQueryable()).Object);
            context.Setup(_ => _.SaveChanges()).Returns(1);

            var agent  = new CurrencyRatesDataAgent(context.Object);
            var result = agent.SaveCurrencyRate(expected);

            Assert.True(result);
        }
예제 #2
0
        public void GetCurrencyRate_RatesIsInDb_ShouldReturnSpecificRate()
        {
            var expected = new List <Database.Models.CurrencyRate>
            {
                new Database.Models.CurrencyRate {
                    Id = 1, Day = DateTime.Today.AddDays(-2), BaseCurrency = "EUR", TargetCurrency = "GBP", Rate = 0.85m
                },
                new Database.Models.CurrencyRate {
                    Id = 2, Day = DateTime.Today.AddDays(-1), BaseCurrency = "EUR", TargetCurrency = "GBP", Rate = 0.85m
                },
                new Database.Models.CurrencyRate {
                    Id = 3, Day = DateTime.Today, BaseCurrency = "EUR", TargetCurrency = "GBP", Rate = 0.85m
                }
            };

            var context = new Mock <ICurrencyRatesContext>();

            context.Setup(_ => _.CurrencyRates).Returns(DbSetMocking.CreateMockSet(expected.AsQueryable()).Object);

            var agent = new CurrencyRatesDataAgent(context.Object);
            var rate  = agent.GetCurrencyRate(DateTime.Today.AddDays(-2), "EUR", "GBP");

            Assert.AreEqual(expected[0].Id, rate.Id);
        }