static async Task UpdateCurrencies(RatesContext context, IDictionary <string, string> symbols)
        {
            var currencies = await context.Currencies.ToListAsync();

            var toUpdate = new List <Currency>();
            var toAdd    = new List <Currency>();

            foreach ((var symbol, var name) in symbols)
            {
                var currency = currencies.SingleOrDefault(c => c.Symbol == symbol);
                if (currency is null)
                {
                    currency = new Currency {
                        Symbol = symbol, FullName = name
                    };
                    toAdd.Add(currency);
                }
                else
                {
                    currency.FullName = name;
                    toUpdate.Add(currency);
                }
            }

            context.AddRange(toAdd);
            context.UpdateRange(toUpdate);
            await context.SaveChangesAsync();
        }
Exemple #2
0
        public RatesReaderRepoEfTests()
        {
            var opts = new DbContextOptionsBuilder <RatesContext>()
                       .UseInMemoryDatabase(fixture.Create <string>())
                       .Options;

            context = new RatesContext(opts);;
            repo    = new RatesReaderRepoEf(context);
        }
        public RatesWriterEfTests()
        {
            var opts = new DbContextOptionsBuilder <RatesContext>()
                       .UseInMemoryDatabase(fixture.Create <string>())
                       .Options;

            var provider = new ServiceCollection()
                           .AddEasyRatesModel()
                           .BuildServiceProvider();

            mapper = provider.GetService <IMapper>();

            context = new RatesContext(opts);
            writer  = new RatesWriterEf(context, mapper);
        }
        public static void Initialize(RatesContext context)
        {
            if (context.RateItems.Any())
            {
                //Data already populated
                return;
            }

            var rateItems = new RateItem[]
            {
                new RateItem
                {
                    Days  = "mon,tues,thurs",
                    Times = "0900-2100",
                    Price = 1500
                },
                new RateItem
                {
                    Days  = "fri,sat,sun",
                    Times = "0900-2100",
                    Price = 2000
                },
                new RateItem
                {
                    Days  = "wed",
                    Times = "0600-1800",
                    Price = 1750
                },
                new RateItem
                {
                    Days  = "mon,wed,sat",
                    Times = "0100-0500",
                    Price = 1000
                },
                new RateItem
                {
                    Days  = "sun,tues",
                    Times = "0100-0700",
                    Price = 925
                }
            };

            foreach (var rateItem in rateItems)
            {
                context.AddRateItem(rateItem);
            }
        }
Exemple #5
0
        public void SetupData()
        {
            var connectionString = "Server=localhost\\SQLExpress;Database=ratesdb;Trusted_Connection=True;";
            var year             = 2018;
            var month            = 2;
            var rawCurrencies    = "1 AUD|1 BGN|1 BRL|1 CAD|1 CHF|1 CNY|1 DKK|1 EUR|1 GBP|1 HKD|1 HRK|100 HUF|1000 IDR|1 ILS|100 INR|100 ISK|100 JPY|100 KRW|1 MXN|1 MYR|1 NOK|1 NZD|100 PHP|1 PLN|1 RON|100 RUB|1 SEK|1 SGD|100 THB|1 TRY|1 USD|1 XDR|1 ZAR";

            var currencies = rawCurrencies.Split("|").Select(x => x.Split(" ")[1]).ToArray();// new string[] { "USD", "RUB", "AUD", "BGN", "CAD", "CHF" , "CNY" , "GBP", "HKD", "INR", "ISK" };
            //_reportService = new ReportService(new DBContextFactory());
            var optionsBuilder = new DbContextOptionsBuilder <RatesContext>();

            optionsBuilder.UseSqlServer(connectionString);
            using (var context = new RatesContext(optionsBuilder.Options))
            {
                data = context.DailyCurrencyRates
                       .Where(x => x.Date.Year == year && x.Date.Month == month && currencies.Contains(x.CurrencyCode))
                       .Select(x => new ReportCurrencyRate {
                    CurrencyCode = x.CurrencyCode, Date = x.Date, FinalRate = x.FinalRate
                })
                       .GroupBy(x => x.Date)
                       .OrderBy(x => x.Key).ToList();
            }
        }
Exemple #6
0
        // TODO: Weird quirk with this test.
        // DateTime.Parse converts to GMT, while the model [FromBody] parser does not
        // This causes this test to fail (when it should succeed) ¯\_(ツ)_/¯
        // Quick fix would be to ignore all those pesky timezones
        // Real fix would be to accept timezones and also make rate time spans Date agnostic
        public void RateTimeTest()
        {
            List <RateDomainItem> domainItems = new List <RateDomainItem>();

            foreach (var item in rateItems)
            {
                domainItems.Add(RatesContext.CreateRateDomainItem(item));
            }

            long?result = RatesController.RateGivenTime(
                DateTimeOffset.Parse(startTime).DateTime,
                DateTimeOffset.Parse(endTime).DateTime,
                domainItems);

            Assert.Equal(1500, result);

            long?result_iOS = RatesController.RateGivenTime(
                DateTimeOffset.Parse(startTime_iOS).DateTime,
                DateTimeOffset.Parse(endTime_iOS).DateTime,
                domainItems);

            Assert.Equal(1500, result_iOS);
        }
Exemple #7
0
 public RatesWriterEf(RatesContext context, IMapper mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
Exemple #8
0
 public RatesController(RatesContext context)
 {
     _context = context;
 }
Exemple #9
0
 public ConvertController(RatesContext context, IFixerClient api)
 {
     this.context = context;
     this.api     = api;
 }
 public RatesReaderRepoEf(RatesContext context)
 {
     this.context = context;
 }