public static async Task <OrderItem> GetOrderItemWithId(Order order, string solutionId, string connectionString, OrderingDbContext context)
        {
            var newPricingUnit = await GetPricingUnitAsync(ProvisioningType.Declarative, connectionString);

            var pricingUnit = await context.FindAsync <PricingUnit>(newPricingUnit.Name) ?? newPricingUnit;

            var selectedItem = (await SupplierInfo.GetPublishedCatalogueItemsNoTieredAsync(connectionString, order.Supplier.Id, CatalogueItemType.Solution))
                               .Single(s => s.CatalogueItemId.ToString().Equals(solutionId));

            var catalogueItem = await context.FindAsync <CatalogueItem>(CatalogueItemId.ParseExact(solutionId))
                                ?? selectedItem.ToDomain();

            var orderItem = new OrderItemBuilder(order.Id)
                            .WithCatalogueItem(catalogueItem)
                            .WithCataloguePriceType(CataloguePriceType.Flat)
                            .WithCurrencyCode()
                            .WithDefaultDeliveryDate(DateTime.Today)
                            .WithPrice(0.01M)
                            .WithPricingTimeUnit(TimeUnit.PerYear)
                            .WithProvisioningType(ProvisioningType.Declarative)
                            .WithPricingUnit(pricingUnit)
                            .WithEstimationPeriod(TimeUnit.PerMonth);

            return(orderItem.Build());
        }
コード例 #2
0
 protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
     FoodBuilder.Build(modelBuilder);
     OrderBuilder.Build(modelBuilder);
     OrderItemBuilder.Build(modelBuilder);
     PaymentMethodBuilder.Build(modelBuilder);
     RestaurantBuilder.Build(modelBuilder);
     TableBuilder.Build(modelBuilder);
 }
        public void Calculate_UnderMinimum_ShouldAddCharge()
        {
            // Arrange
            var chargeName = "VAT";
            var orderItem  = _orderItemBuilder.Build();
            var order      = _orderBuilder.WithOrderItems(new List <OrderItem> {
                orderItem
            }).Build();
            var calculator = Mock.Of <IChargeCalculator>();

            orderItem.AddCharge(new OrderCharge(chargeName, "EUR9.99", ChargeNames.Item));

            var sut = new MinimumPayableConstraint(calculator, chargeName, "EUR10");

            // Act
            sut.Calculate(order);

            // Assert
            order.GetChargeAmount(chargeName, order.Currency).Value.Should().Be(10);
        }
        public void Calculate_SingleOrderItem_ShouldAddCorrectCharge()
        {
            // Arrange
            var orderItem = _orderItemBuilder.Build();
            var order     = _orderBuilder.WithOrderItems(new List <OrderItem> {
                orderItem
            }).Build();
            var expectedChargeName = ChargeName.FromBaseChargeName(_chargeName, ChargeNames.Item);

            var sut = new FixedChargeCalculator(_chargeName, new Price(CurrencyFakes.EUR, 10));

            // Act
            sut.Calculate(order);

            // Assert
            orderItem.Charges.Should()
            .HaveCount(3).And
            .ContainSingle(c => c.ChargeName.Value == expectedChargeName && c.ChargeAmount.Value == 10);
        }
        public static async Task <OrderItem> CreateOrderItem(
            Order order,
            CatalogueItemType catalogueItemType,
            CataloguePriceType cataloguePriceType,
            ProvisioningType provisioningType,
            OrderingDbContext context,
            string connectionString,
            TimeUnit timeUnit = TimeUnit.PerYear)
        {
            var solution = await SupplierInfo.GetPublishedCatalogueItemsNoTieredAsync(connectionString, order.Supplier.Id, catalogueItemType);

            var selectedItem = RandomInformation.GetRandomItem(solution);

            var catalogueItem = await context.FindAsync <CatalogueItem>(CatalogueItemId.ParseExact(selectedItem.CatalogueItemId))
                                ?? selectedItem.ToDomain();

            var catalogueItemPricingUnit = await GetPricingUnitAsync(provisioningType, connectionString);

            var pricingUnit = await context.FindAsync <PricingUnit>(catalogueItemPricingUnit.Name) ?? catalogueItemPricingUnit;

            var orderItem = new OrderItemBuilder(order.Id)
                            .WithCatalogueItem(catalogueItem)
                            .WithCataloguePriceType(cataloguePriceType)
                            .WithCurrencyCode()
                            .WithDefaultDeliveryDate(DateTime.Today)
                            .WithPrice(0.01M)
                            .WithPricingTimeUnit(timeUnit)
                            .WithProvisioningType(provisioningType)
                            .WithPricingUnit(pricingUnit)
                            .WithEstimationPeriod(timeUnit);

            if (provisioningType == ProvisioningType.OnDemand)
            {
                orderItem.WithEstimationPeriod(timeUnit);
            }

            return(orderItem.Build());
        }