Пример #1
0
        public void Insert_Prices_Successfully()
        {
            try
            {
                IQueryable <FuelPrice> fuelPrices = new List <FuelPrice>
                {
                    new FuelPrice
                    {
                        Date  = DateTime.Now.AddDays(-1),
                        Price = 5
                    },
                    new FuelPrice
                    {
                        Date  = DateTime.Now.AddDays(-2),
                        Price = 3
                    },
                }.AsQueryable();
                var mockSet = new Mock <DbSet <FuelPrice> >();
                mockSet.As <IQueryable <FuelPrice> >().Setup(m => m.Provider).Returns(fuelPrices.Provider);
                mockSet.As <IQueryable <FuelPrice> >().Setup(m => m.Expression).Returns(fuelPrices.Expression);
                mockSet.As <IQueryable <FuelPrice> >().Setup(m => m.ElementType).Returns(fuelPrices.ElementType);
                mockSet.As <IQueryable <FuelPrice> >().Setup(m => m.GetEnumerator()).Returns(fuelPrices.GetEnumerator);

                var mockContext = new Mock <WebJobContext>();
                mockContext.Setup(c => c.FuelPrices).Returns(mockSet.Object);

                var command = new AddPriceRecordCommand(mockContext.Object);
                command.Execute(new EditableList <FuelPrice>()
                {
                    new FuelPrice()
                    {
                        Date  = DateTime.Now,
                        Price = 1
                    }
                });
            }
            catch (Exception e)
            {
                Assert.Null(e);
            }
        }
Пример #2
0
        public async void Run(TimerInfo timer, TraceWriter log)
        {
            try
            {
                if (timer.IsPastDue)
                {
                    log.Info("Timer is running late");
                }
                log.Info($"Running job at {DateTime.Now}");
                var prices = await _query.ExecuteAsync();

                log.Info($"Prices: {prices}");
                _command.Execute(prices);
                log.Info("Inserted successfully");
            }
            catch (Exception e)
            {
                log.Error($"Error: {e}");
            }
            finally
            {
                log.Info("Exiting Run method");
            }
        }