コード例 #1
0
        public async Task <ManageOrder> GetOrdersByGasStationIdAsync(Guid gasStationId)
        {
            var orders = await _orderContext.Orders
                         .Where(o => o.GasStationId == gasStationId).ToListAsync();

            var manageOrder = new ManageOrder();

            foreach (var order in orders)
            {
                manageOrder.Add(order);
            }

            return(manageOrder);
        }
コード例 #2
0
        public async Task ShouldReturnOrderByGasStationIdAndDeliveryDate()
        {
            var order       = _orderData.GetOrders().First();
            var manageOrder = new ManageOrder();

            manageOrder.Add(order);

            await _manageOrderRepository.UpsertAsync(manageOrder);

            var res = await _manageOrderRepository.GetOrderByGasStationIdDeliveryDateAsync(order.GasStationId,
                                                                                           order.DispatchDate);

            Assert.NotNull(res);
            Assert.True(res.Id > 0);
        }
コード例 #3
0
        public async Task ShouldCreateOrderWhenThereIsNoOverlappingDatesWithPreviousOrders()
        {
            var order = _orderData.GetOrders().First();

            order.State = TrackingState.Added;
            var manageOrder = new ManageOrder();

            manageOrder.Add(order);

            await _manageOrderRepository.UpsertAsync(manageOrder);

            var result = await _manageOrderRepository.GetOrdersByGasStationIdAsync(order.GasStationId);

            Assert.NotEmpty(result.Orders);
            Assert.Equal(order.GasStationId, result.Orders.First().GasStationId);
        }
コード例 #4
0
        public MockRepoHelper(IOrderDataFixture orderData)
        {
            MockGasStationScheduleRepo = new Mock <IReferenceRepository <GasStationSchedule> >();

            MockGasStationScheduleByDayRepo = new Mock <IReferenceRepository <GasStationScheduleByDay> >();

            MockGasStationTanksScheduleRepo = new Mock <IReferenceRepository <GasStationTankSchedule> >();

            MockDayComparable = new Mock <IDayComparable>();

            MockTimeIntervalComparable = new Mock <ITimeIntervalComparable>();

            MockGasStationScheduleByTimeRepo = new Mock <IReferenceRepository <GasStationScheduleByTime> >();

            MockGasStationsRepo = new Mock <IReferenceRepository <GasStation> >();

            MockManagerOrderRepository = new Mock <IManageOrderRepository>();

            MockGasStationCustomRepository = new Mock <IGasStationRepository>();

            MockGasStationScheduleRepo.Setup(x => x.FindByAsync(It.IsAny <Expression <Func <GasStationSchedule, bool> > >())).ReturnsAsync(
                (Expression <Func <GasStationSchedule, bool> > predicate) => orderData.GasStationSchedules.Where(predicate.Compile()));

            MockGasStationScheduleByDayRepo.Setup(x => x.FindByAsync(It.IsAny <Expression <Func <GasStationScheduleByDay, bool> > >()))
            .ReturnsAsync((Expression <Func <GasStationScheduleByDay, bool> > predicate) =>
                          orderData.GasStationSchedulesByDay.Where(predicate.Compile())
                          );

            MockGasStationTanksScheduleRepo.Setup(x => x.FindByAsync(It.IsAny <Expression <Func <GasStationTankSchedule, bool> > >()))
            .ReturnsAsync((Expression <Func <GasStationTankSchedule, bool> > predicate) =>
                          orderData.GasStationTankSchedules.Where(predicate.Compile())
                          );

            MockGasStationScheduleByTimeRepo.Setup(x => x.FindByAsync(It.IsAny <Expression <Func <GasStationScheduleByTime, bool> > >()))
            .ReturnsAsync((Expression <Func <GasStationScheduleByTime, bool> > predicate) =>
                          orderData.GasStationSchedulesByTime.Where(predicate.Compile())
                          );

            MockManagerOrderRepository.Setup(x => x.GetOrdersByGasStationIdAsync(
                                                 It.IsAny <Guid>())).ReturnsAsync((Guid gasStationId) =>
            {
                var manageOrder = new ManageOrder();
                foreach (var ord in orderData.Orders.Where(x => x.GasStationId == gasStationId))
                {
                    manageOrder.Add(ord);
                }
                return(manageOrder);
            });

            MockManagerOrderRepository.Setup(x => x.GetOrderByGasStationIdDeliveryDateAsync(
                                                 It.IsAny <Guid>(),
                                                 It.IsAny <DateTimeRange>())).ReturnsAsync((Guid gasStationId, DateTimeRange dispatchDate) =>
            {
                return(orderData.Orders.Where(x => x.GasStationId == gasStationId &&
                                              x.DispatchDate == dispatchDate).First());
            });

            MockManagerOrderRepository.Setup(x => x.UpsertAsync(
                                                 It.IsAny <ManageOrder>())).Returns((ManageOrder manageOrder) =>
            {
                void insertOrder(Order order)
                {
                    order.CreatedDate  = DateTime.UtcNow;
                    order.ModifiedDate = DateTime.UtcNow;

                    orderData.AddOrder(order);
                }

                void updateOrder(Order order)
                {
                    order.ModifiedDate = DateTime.UtcNow;
                }

                foreach (var order in manageOrder.Orders)
                {
                    if (order.State == TrackingState.Added)
                    {
                        insertOrder(order);
                    }
                    else if (order.State == TrackingState.Modified)
                    {
                        updateOrder(order);
                    }
                }

                return(Task.CompletedTask);
            });

            MockGasStationCustomRepository
            .Setup(x => x.GetGasStationIncludeTankOrderStrategyAsync(It.IsAny <Guid>()))
            .ReturnsAsync((Guid gasStationId) =>
                          (orderData.GasStations.First(), orderData.OrderStrategies.First().OrderType)
                          );

            MockGasStationsRepo.Setup(x => x.FindByAsync(It.IsAny <Expression <Func <GasStation, bool> > >()))
            .ReturnsAsync((Expression <Func <GasStation, bool> > predicate) =>
                          orderData.GasStations.Where(predicate.Compile())
                          );

            MockGasStationsRepo.Setup(x => x.FindByKeyAsync(It.IsAny <object>()))
            .ReturnsAsync((object id) =>
                          orderData.GasStations.Where(x => x.Id == (Guid)id).First()
                          );
        }