Example #1
0
        private void SyncRatesFromFile(File file)
        {
            var currencyRateCollection = CurrencyRateCollection.BuildFromXml(file.Content);

            var newCurrencies = currencyRateCollection
                .Select(cr => new Currency { Code = cr.CurrencyCode, Name = cr.CurrencyName })
                .Except(this.context.Currencies.Select(c => c).AsEnumerable(), new CurrencyComparer());

            this.context.Currencies.AddRange(newCurrencies);

            foreach (var currencyRate in currencyRateCollection)
            {
                var rate = new Rate
                {
                    Date = currencyRateCollection.PublicationDate, 
                    Value = currencyRate.AverageValue, 
                    Multiplier = currencyRate.Multiplier, 
                    CurrencyCode = currencyRate.CurrencyCode, 
                    FileId = file.Id
                };

                this.context.Rates.Add(rate);
            }

            file.Processed = true;

            this.context.SaveChanges();
        }
Example #2
0
        public void TestDetails()
        {
            var currencyRatesService = new Mock<ICurrencyRatesService>();
            var rate = new Rate { Id = 123, CurrencyCode = "EUR" };

            currencyRatesService.Setup(crs => crs.Find(123)).Returns(rate);

            var controller = new RatesController(currencyRatesService.Object);
            var result = controller.Details(123) as ViewResult;

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Model, Is.EqualTo(rate));
        }