コード例 #1
0
        public async Task ShouldReturnScheduleInputOrderObjectWhenScheduleTypeIsDay()
        {
            _mockDayComparable.Setup(x => x.Compare(It.IsAny <DayOfWeek>())).Returns(true);
            var scheduleOrder = new ScheduleOrder(
                _mockGasStationScheduleRepo.Object
                , _mockGasStationScheduleByDayRepo.Object
                , _mockGasStationTanksScheduleRepo.Object
                , _mockGasStationScheduleByTimeRepo.Object
                , _mockDayComparable.Object
                , _mockTimeIntervalComparable.Object
                , _mockOrderRepository.Object
                );

            var gasStation = _orderData.GasStations.First();
            var result     = await scheduleOrder.CreateAsync((gasStation, _orderData.OrderStrategies.First().OrderType));

            Assert.True(result.IsSuccess);
            var lineItemsTankIds        = result.Entity !.OrderProducts.Select(x => x.TankId).ToList();
            var gasStationScheduleTanks = _orderData.GasStationTankSchedules.Where(x => x.TankId == 1 || x.TankId == 2).ToList();

            _mockDayComparable.Verify(x => x.Compare(It.IsAny <DayOfWeek>()), Times.Once);
            Assert.Equal(OrderType.Schedule, result.Entity !.OrderType);
            Assert.Equal(2, result.Entity !.OrderProducts.Count());
            Assert.True(lineItemsTankIds.Exists(x => x == gasStationScheduleTanks
                                                .FirstOrDefault().TankId));
            Assert.True(lineItemsTankIds.Exists(x => x == gasStationScheduleTanks
                                                .LastOrDefault().TankId));
            Assert.Equal(result.Entity !.OrderProducts.FirstOrDefault(
                             x => x.TankId == gasStationScheduleTanks.FirstOrDefault().TankId)
                         .Quantity, gasStationScheduleTanks.FirstOrDefault().Quantity);
            Assert.Equal(result.Entity !.OrderProducts.FirstOrDefault(
                             x => x.TankId == gasStationScheduleTanks.LastOrDefault().TankId)
                         .Quantity, gasStationScheduleTanks.LastOrDefault().Quantity);
        }
コード例 #2
0
        public Order Change(List <OrderProduct> productList)
        {
            foreach (var product in productList)
            {
                var selectedProduct = OrderProducts.FirstOrDefault(x => x.Sku == product.Sku);
                if (product.Quantity - selectedProduct.Quantity < 1)
                {
                    throw new ProductQuantityMustBeGreaterThanZeroBusinessException();
                }

                selectedProduct.Quantity = product.Quantity;
            }
            TotalPriceCalculator(productList);
            return(this);
        }
コード例 #3
0
        public Order CancelLineItem(string sku)
        {
            if (States.Count > 1)
            {
                throw new CannotCancelOrderProductItemException();
            }

            var product = OrderProducts.FirstOrDefault(x => x.Sku == sku);

            OrderProducts.Remove(product);
            CanceledOrderProducts.Add(product);

            TotalPrice        -= product.Price * product.Quantity;
            TotalPriceWithVat -= product.PriceWithVat * product.Quantity;
            TotalVat          -= product.Vat * product.Quantity;

            return(this);
        }
コード例 #4
0
ファイル: OrderTests.cs プロジェクト: rajakondla/SmartBuy
        public void ShouldReturnOrderProductFromOrder()
        {
            var order = Order.Create(_orderData.InputOrder, _orderData.GasStations.FirstOrDefault());

            Assert.NotNull(order.Entity);
            Assert.Equal(_orderData.InputOrder.GasStationId, order.Entity !.GasStationId);
            Assert.Equal(_orderData.InputOrder.Comments, order.Entity !.Comments);
            Assert.Single(order.Entity !.OrderProducts);
            Assert.Equal(_orderData.InputOrder.LineItems.FirstOrDefault().TankId, order.Entity !.OrderProducts.FirstOrDefault().TankId);
        }