public void Configure(EntityTypeBuilder <OrderItemRecipient> builder)
        {
            const string catalogueItemId = "CatalogueItemId";
            const string odsCode         = "OdsCode";
            const string orderId         = "OrderId";

            builder.ToTable("OrderItemRecipients");
            builder.Property <int>(orderId).IsRequired();
            builder.Property <CatalogueItemId>(catalogueItemId)
            .HasMaxLength(14)
            .HasConversion(id => id.ToString(), id => CatalogueItemId.ParseExact(id));

            builder.Property <string>(odsCode).HasMaxLength(8);
            builder.HasKey(orderId, catalogueItemId, odsCode);

            builder.Property(r => r.DeliveryDate).HasColumnType("date");

            builder.HasOne(r => r.Recipient)
            .WithMany()
            .HasForeignKey(odsCode)
            .OnDelete(DeleteBehavior.ClientSetNull)
            .HasConstraintName("FK_OrderItemRecipients_OdsCode");

            builder.HasOne <OrderItem>()
            .WithMany(i => i.OrderItemRecipients)
            .HasForeignKey(orderId, catalogueItemId)
            .HasConstraintName("FK_OrderItemRecipients_OrderItem");
        }
        public async Task GivenACatalogueSolutionHasBeenAddedToTheOrder()
        {
            var order = (Order)Context[ContextKeys.CreatedOrder];

            var solutions = await SupplierInfo.GetPublishedCatalogueItemsNoTieredAsync(Test.BapiConnectionString, order.Supplier.Id, CatalogueItemType.Solution);

            var selectedItem = solutions.First();

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

            var pricingUnitName = "per banana";

            var pricingUnit = await DbContext.FindAsync <PricingUnit>(pricingUnitName) ?? new PricingUnit
            {
                Name = pricingUnitName,
            };

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

            order.AddOrUpdateOrderItem(orderItem);

            await DbContext.SaveChangesAsync();
        }
Esempio n. 3
0
        public void Configure(EntityTypeBuilder <CatalogueItem> builder)
        {
            builder.ToTable("CatalogueItem");
            builder.HasKey(i => i.Id);
            builder.Property(i => i.Id)
            .IsRequired()
            .HasMaxLength(14)
            .HasConversion(id => id.ToString(), id => CatalogueItemId.ParseExact(id));

            builder.Property(i => i.Name)
            .IsRequired()
            .HasMaxLength(256);

            const string catalogueItemTypeId = "CatalogueItemTypeId";

            builder
            .Property(i => i.CatalogueItemType)
            .HasConversion <int>()
            .HasColumnName(catalogueItemTypeId);

            builder.HasOne <CatalogueItem>()
            .WithMany()
            .HasForeignKey(i => i.ParentCatalogueItemId)
            .HasConstraintName("FK_CatalogueItem_ParentCatalogueItem");
        }
        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());
        }
Esempio n. 5
0
        public void Configure(EntityTypeBuilder <OrderItem> builder)
        {
            const string catalogueItemId = "CatalogueItemId";

            builder.ToTable("OrderItem");
            builder.Property <CatalogueItemId>(catalogueItemId)
            .HasMaxLength(14)
            .HasConversion(id => id.ToString(), id => CatalogueItemId.ParseExact(id));

            builder.Property(o => o.OrderId).IsRequired();
            builder.HasKey(nameof(OrderItem.OrderId), catalogueItemId);

            builder.Property(i => i.Created).HasDefaultValueSql("(GetUtcDate())");
            builder.Property(i => i.CurrencyCode)
            .IsRequired()
            .HasMaxLength(3);

            builder.Property(i => i.DefaultDeliveryDate).HasColumnType("date");
            builder.Property(i => i.LastUpdated).HasDefaultValueSql("(GetUtcDate())");
            builder.Property(i => i.Price).HasColumnType("decimal(18, 4)");

            builder.HasOne(i => i.CatalogueItem)
            .WithMany()
            .HasForeignKey(catalogueItemId)
            .OnDelete(DeleteBehavior.ClientSetNull)
            .HasConstraintName("FK_OrderItem_CatalogueItem");

            builder
            .Property(i => i.CataloguePriceType)
            .HasConversion <int>()
            .HasColumnName("CataloguePriceTypeId");

            builder
            .Property(i => i.EstimationPeriod)
            .HasConversion <int>()
            .HasColumnName("EstimationPeriodId");

            builder.HasOne <Order>()
            .WithMany(o => o.OrderItems)
            .HasForeignKey(o => o.OrderId)
            .HasConstraintName("FK_OrderItem_Order");

            builder.HasOne(i => i.PricingUnit)
            .WithMany()
            .HasForeignKey("PricingUnitName")
            .OnDelete(DeleteBehavior.ClientSetNull)
            .HasConstraintName("FK_OrderItem_PricingUnit");

            builder
            .Property(i => i.ProvisioningType)
            .HasConversion <int>()
            .HasColumnName("ProvisioningTypeId");

            builder
            .Property(i => i.PriceTimeUnit)
            .HasConversion <int>()
            .HasColumnName("TimeUnitId");
        }
Esempio n. 6
0
 public static CatalogueItem ToDomain(this CatalogueItemModel model)
 {
     return(model is null
         ? null
         : new CatalogueItem
     {
         Id = CatalogueItemId.ParseExact(model.CatalogueItemId),
         Name = model.Name,
         CatalogueItemType = model.CatalogueItemType,
         ParentCatalogueItemId = model.ParentCatalogueItemId,
     });
 }
Esempio n. 7
0
        public void Configure(EntityTypeBuilder <DefaultDeliveryDate> builder)
        {
            builder.ToTable("DefaultDeliveryDate");
            builder.HasKey(d => new { d.OrderId, d.CatalogueItemId });
            builder
            .Property(d => d.CatalogueItemId)
            .HasMaxLength(14)
            .HasConversion(id => id.ToString(), id => CatalogueItemId.ParseExact(id));

            builder.Property(d => d.DeliveryDate).HasColumnType("date");

            builder.HasOne <Order>()
            .WithMany(o => o.DefaultDeliveryDates)
            .HasForeignKey(d => d.OrderId)
            .HasConstraintName("FK_DefaultDeliveryDate_OrderId");
        }
        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());
        }
Esempio n. 9
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) =>
 CatalogueItemId.ParseExact((string)value);
        public static void ParseExact_ValidId_ReturnsExpectedResult()
        {
            var id = CatalogueItemId.ParseExact("999999-ItemId");

            id.Should().Be(new CatalogueItemId(999999, "ItemId"));
        }
 public static void ParseExact_InvalidId_ThrowsException(string id)
 {
     Assert.Throws <FormatException>(() => CatalogueItemId.ParseExact(id));
 }
        public async Task GivenTheOrderIsCompleteEnoughSoThatTheCompleteOrderButtonIsEnabled(string fsValue)
        {
            bool fs = fsValue.ToLower() == "yes";

            await new CommonSteps(Test, Context).GivenAnIncompleteOrderExists();

            var order = Context.Get <Order>(ContextKeys.CreatedOrder);

            var supplier = await DbContext.Supplier.SingleOrDefaultAsync(s => s.Id == "100000")
                           ?? (await SupplierInfo.GetSupplierWithId("100000", Test.BapiConnectionString)).ToDomain();

            var orderBuilder = new OrderBuilder(order)
                               .WithExistingSupplier(supplier)
                               .WithSupplierContact(ContactHelper.Generate())
                               .WithCommencementDate(DateTime.Today)
                               .WithOrderingPartyContact(ContactHelper.Generate())
                               .WithFundingSource(fs);

            var associatedServices = await SupplierInfo.GetPublishedCatalogueItemsNoTieredAsync(Test.BapiConnectionString, supplier.Id, CatalogueItemType.AssociatedService);

            var selectedItem = associatedServices.First();

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

            var pricingUnitName = "per banana";

            var pricingUnit = await DbContext.FindAsync <PricingUnit>(pricingUnitName) ?? new PricingUnit
            {
                Name = pricingUnitName,
            };

            pricingUnit.Description = pricingUnitName;

            var recipients = new List <OrderItemRecipient>();

            var recipient = await DbContext.ServiceRecipient.SingleOrDefaultAsync(s => s.OdsCode == order.OrderingParty.OdsCode)
                            ?? new ServiceRecipient(order.OrderingParty.OdsCode, order.OrderingParty.Name);

            var orderItemRecipient = new OrderItemRecipient()
            {
                Recipient    = recipient,
                DeliveryDate = DateTime.UtcNow,
                Quantity     = 1,
            };

            recipients.Add(orderItemRecipient);

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

            order.AddOrUpdateOrderItem(orderItem);

            await OrderProgressHelper.SetProgress(
                context : DbContext,
                order : order,
                catalogueSolutionsViewed : true,
                additionalServicesViewed : true,
                associatedServicesViewed : true);

            DbContext.Update(order);

            await DbContext.SaveChangesAsync();

            Context.Remove(ContextKeys.CreatedOrder);
            Context.Add(ContextKeys.CreatedOrder, order);

            Test.Driver.Navigate().Refresh();
        }