public static void CalculateTotalOwnershipCost_SingleOneOffOrRecurringOrderItem_ReturnsTotalOwnershipCost(
            CatalogueItemType catalogueItemType,
            ProvisioningType provisioningType,
            decimal price,
            int quantity,
            decimal totalOwnershipCost)
        {
            var orderItem = OrderItemBuilder
                            .Create()
                            .WithCatalogueItem(new CatalogueItem {
                CatalogueItemType = catalogueItemType
            })
                            .WithProvisioningType(provisioningType)
                            .WithPrice(price)
                            .WithRecipient(new OrderItemRecipient {
                Quantity = quantity
            })
                            .Build();

            var order = OrderBuilder
                        .Create()
                        .WithOrderItem(orderItem)
                        .Build();

            order.CalculateTotalOwnershipCost().Should().Be(totalOwnershipCost);
        }
        public static void Constructor_InitializesProvisioningType(
            [Frozen] ProvisioningType provisioningType,
            OrderItem orderItem)
        {
            var model = new GetOrderItemModel(orderItem);

            model.ProvisioningType.Should().Be(provisioningType.ToString());
        }
 public static TimeUnit?InferEstimationPeriod(this ProvisioningType provisioningType, TimeUnit?estimationPeriod)
 {
     return(provisioningType switch
     {
         ProvisioningType.Patient => TimeUnit.PerMonth,
         ProvisioningType.Declarative => TimeUnit.PerYear,
         ProvisioningType.OnDemand => estimationPeriod,
         _ => throw new InvalidOperationException(),
     });
Exemple #4
0
        public static void InferEstimationPeriod_ReturnsExpectedEstimationPeriod(
            CatalogueItemType catalogueItemType,
            ProvisioningType provisioningType,
            TimeUnit?estimationPeriod,
            TimeUnit?expectedEstimationPeriod)
        {
            var actual = catalogueItemType.InferEstimationPeriod(provisioningType, estimationPeriod);

            actual.Should().Be(expectedEstimationPeriod);
        }
        public void List_ReturnsExpectedList()
        {
            var actual = ProvisioningType.List();

            var expected = new List <ProvisioningType>
            {
                ProvisioningType.Patient,
                ProvisioningType.Declarative,
                ProvisioningType.OnDemand
            };

            actual.Should().BeEquivalentTo(expected);
        }
        private static async Task <PricingUnit> GetPricingUnitAsync(ProvisioningType provisioningType, string bapiConnectionString)
        {
            var query = @"SELECT pu.[Name],
                          pu.Description
                          FROM PricingUnit AS pu
                          INNER JOIN CataloguePrice AS cp ON cp.PricingUnitId = pu.PricingUnitId
                          WHERE cp.ProvisioningTypeId = @provisioningType
                          AND CataloguePriceTypeId = '1';";

            var result = (await SqlExecutor.ExecuteAsync <PricingUnit>(bapiConnectionString, query, new { provisioningType })).FirstOrDefault();

            return(result);
        }
Exemple #7
0
 private CreateCatalogueSolutionOrderItemRequestPayloadBuilder()
 {
     _odsCode                 = "ODS1";
     _catalogueSolutionId     = "100001-001";
     _catalogueSolutionName   = Guid.NewGuid().ToString();
     _deliveryDate            = DateTime.UtcNow.Date;
     _quantity                = 5;
     _estimationPeriod        = TimeUnit.Month;
     _provisioningType        = ProvisioningType.OnDemand;
     _cataloguePriceType      = CataloguePriceType.Flat;
     _currencyCode            = "GBP";
     _itemUnitName            = "consultation";
     _itemUnitNameDescription = "per consultation";
     _price = 1.5m;
 }
Exemple #8
0
 private OrderItemBuilder()
 {
     _odsCode            = "ODS1";
     _catalogueItemId    = "1000-001";
     _catalogueItemType  = CatalogueItemType.Solution;
     _catalogueItemName  = Guid.NewGuid().ToString();
     _provisioningType   = ProvisioningType.Patient;
     _cataloguePriceType = CataloguePriceType.Flat;
     _cataloguePriceUnit = CataloguePriceUnit.Create("patients", "per patient");
     _priceTimeUnit      = null;
     _currencyCode       = "GBP";
     _quantity           = 10;
     _estimationPeriod   = TimeUnit.PerYear;
     _deliveryDate       = DateTime.UtcNow;
     _price = 2.000m;
 }
Exemple #9
0
        public async Task <Result <int> > CreateAsync(CreateOrderItemRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var provisioningType   = ProvisioningType.FromName(request.ProvisioningTypeName);
            var cataloguePriceType = CataloguePriceType.FromName(request.CataloguePriceTypeName);
            var cataloguePriceUnit = CataloguePriceUnit.Create(request.CataloguePriceUnitTierName, request.CataloguePriceUnitDescription);

            var priceTimeUnit    = TimeUnit.FromName(request.PriceTimeUnitName);
            var estimationPeriod = TimeUnit.FromName(request.EstimationPeriodName);

            var orderItem = new OrderItem(
                request.OdsCode,
                request.CatalogueItemId,
                request.CatalogueItemType,
                request.CatalogueItemName,
                provisioningType,
                cataloguePriceType,
                cataloguePriceUnit,
                priceTimeUnit,
                request.CurrencyCode,
                request.Quantity,
                estimationPeriod,
                request.DeliveryDate,
                request.Price);

            Order order = request.Order;

            order.AddOrderItem(orderItem,
                               _identityService.GetUserIdentity(),
                               _identityService.GetUserName());

            await _orderRepository.UpdateOrderAsync(order);

            return(Result.Success(orderItem.OrderItemId));
        }
        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());
        }
 private OrderItemEntityBuilder(
     int orderId,
     string catalogueItemId,
     TimeUnit?estimationPeriod,
     ProvisioningType provisioningType,
     CataloguePriceType cataloguePriceType,
     string currencyCode,
     TimeUnit?timeUnit,
     string pricingUnitName,
     decimal?price,
     DateTime created)
 {
     this.orderId            = orderId;
     this.catalogueItemId    = catalogueItemId;
     this.estimationPeriod   = estimationPeriod;
     this.provisioningType   = provisioningType;
     this.cataloguePriceType = cataloguePriceType;
     this.currencyCode       = currencyCode;
     this.timeUnit           = timeUnit;
     this.pricingUnitName    = pricingUnitName;
     this.price   = price;
     this.created = created;
 }
Exemple #12
0
 private OrderItemEntityBuilder(
     string orderId,
     string odsCode,
     string catalogueItemId,
     CatalogueItemType catalogueItemType,
     string catalogueItemName,
     DateTime?deliveryDate,
     int quantity,
     TimeUnit?estimationPeriod,
     ProvisioningType provisioningType,
     CataloguePriceType cataloguePriceType,
     string currencyCode,
     TimeUnit?timeUnit,
     string pricingUnitTierName,
     string pricingUnitDescription,
     decimal?price,
     DateTime created,
     DateTime lastUpdated)
 {
     _orderId                = orderId;
     _odsCode                = odsCode;
     _catalogueItemId        = catalogueItemId;
     _catalogueItemType      = catalogueItemType;
     _catalogueItemName      = catalogueItemName;
     _deliveryDate           = deliveryDate;
     _quantity               = quantity;
     _estimationPeriod       = estimationPeriod;
     _provisioningType       = provisioningType;
     _cataloguePriceType     = cataloguePriceType;
     _currencyCode           = currencyCode;
     _timeUnit               = timeUnit;
     _pricingUnitTierName    = pricingUnitTierName;
     _pricingUnitDescription = pricingUnitDescription;
     _price       = price;
     _created     = created;
     _lastUpdated = lastUpdated;
 }
 public static async Task <IEnumerable <SupplierDetails> > SuppliersWithCatalogueSolution(string connectionString, ProvisioningType provisioningType)
 {
     return(await SupplierLookup(connectionString, CatalogueItemType.Solution, provisioningType));
 }
 public OrderItemBuilder WithProvisioningType(ProvisioningType provisioningType)
 {
     orderItem.ProvisioningType = provisioningType;
     return(this);
 }
Exemple #15
0
 public static TimeUnit?InferEstimationPeriod(this CatalogueItemType itemType, ProvisioningType provisioningType, TimeUnit?estimationPeriod)
 {
     return(itemType switch
     {
         CatalogueItemType.AssociatedService => provisioningType == ProvisioningType.OnDemand
             ? provisioningType.InferEstimationPeriod(estimationPeriod)
             : null,
         _ => provisioningType.InferEstimationPeriod(estimationPeriod),
     });
Exemple #16
0
 private static OrderItem CreateOrderItem(CatalogueItemType catalogueItemType, ProvisioningType provisioningType)
 {
     return(OrderItemBuilder
            .Create()
            .WithCatalogueItem(new CatalogueItem {
         CatalogueItemType = catalogueItemType
     })
            .WithProvisioningType(provisioningType)
            .Build());
 }
Exemple #17
0
        public static void CostType_DeterminesTheCostType_ReturnsCorrectCostType(CatalogueItemType catalogueItemType, ProvisioningType provisioningType, CostType costType)
        {
            var orderItem = CreateOrderItem(catalogueItemType, provisioningType);

            orderItem.CostType.Should().Be(costType);
        }
 static void Test()
 {
     ProvisioningType.FromName(null);
 }
        public void EnsureProvisioningTypeNamingMatchesOrderingApi(string name)
        {
            ProvisioningType provisioningType = Enumerator.FromName <ProvisioningType>(name);

            provisioningType.Name.Should().Be(name);
        }
Exemple #20
0
 public CreateCatalogueSolutionOrderItemRequestPayloadBuilder WithProvisioningType(ProvisioningType provisioningType)
 {
     _provisioningType = provisioningType;
     return(this);
 }
Exemple #21
0
 public OrderItemEntityBuilder WithProvisioningType(ProvisioningType provisioningType)
 {
     _provisioningType = provisioningType;
     return(this);
 }
Exemple #22
0
        public void Configure(EntityTypeBuilder <OrderItem> builder)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.HasKey(orderItem => orderItem.OrderItemId);

            builder.Property(orderItem => orderItem.OrderItemId)
            .HasColumnName(nameof(OrderItem.OrderItemId))
            .IsRequired();

            builder.Property("OrderId")
            .HasColumnName("OrderId")
            .IsRequired();

            builder.Property(orderItem => orderItem.CatalogueItemId)
            .HasColumnName(nameof(OrderItem.CatalogueItemId))
            .IsRequired();

            builder
            .Property(orderItem => orderItem.CatalogueItemType)
            .HasConversion(input => input.Id, output => CatalogueItemType.FromId(output))
            .HasColumnName("CatalogueItemTypeId");

            builder.Property(orderItem => orderItem.CatalogueItemName)
            .HasColumnName(nameof(OrderItem.CatalogueItemName))
            .IsRequired();

            builder.Property(orderItem => orderItem.OdsCode)
            .HasColumnName(nameof(OrderItem.OdsCode));

            builder
            .Property(orderItem => orderItem.ProvisioningType)
            .HasConversion(input => input.Id, output => ProvisioningType.FromId(output))
            .HasColumnName("ProvisioningTypeId");

            builder
            .Property(orderItem => orderItem.CataloguePriceType)
            .HasConversion(input => input.Id, output => CataloguePriceType.FromId(output))
            .HasColumnName("CataloguePriceTypeId");

            builder.OwnsOne(orderItem => orderItem.CataloguePriceUnit, navigationBuilder =>
            {
                navigationBuilder.Property(cataloguePriceUnit => cataloguePriceUnit.TierName)
                .HasColumnName("PricingUnitTierName");

                navigationBuilder.Property(cataloguePriceUnit => cataloguePriceUnit.Description)
                .HasColumnName("PricingUnitDescription");
            });

            builder
            .Property(orderItem => orderItem.PriceTimeUnit)
            .HasConversion(input => input.Id, output => TimeUnit.FromId(output))
            .HasColumnName("TimeUnitId");

            builder.Property(orderItem => orderItem.CurrencyCode)
            .HasColumnName(nameof(OrderItem.CurrencyCode))
            .IsRequired();

            builder.Property(orderItem => orderItem.Quantity)
            .HasColumnName(nameof(OrderItem.Quantity))
            .IsRequired();

            builder
            .Property(orderItem => orderItem.EstimationPeriod)
            .HasConversion(input => input.Id, output => TimeUnit.FromId(output))
            .HasColumnName("EstimationPeriodId");

            builder.Property(orderItem => orderItem.DeliveryDate)
            .HasColumnName(nameof(OrderItem.DeliveryDate));

            builder.Property(orderItem => orderItem.Price)
            .HasColumnName(nameof(OrderItem.Price))
            .HasColumnType("decimal(18, 3)");
        }
        public static async Task <IEnumerable <SupplierDetails> > SupplierLookup(string connectionString, CatalogueItemType catalogueItemType, ProvisioningType provisioningType)
        {
            var query = @"SELECT ci.SupplierId, su.[Name], su.Address    
                            FROM dbo.CatalogueItem AS ci
                            INNER JOIN CataloguePrice AS pr ON ci.CatalogueItemId=pr.CatalogueItemId
                            INNER JOIN Supplier AS su On ci.SupplierId=su.Id
                            WHERE ci.CatalogueItemTypeId=@catalogueItemType
                            AND pr.ProvisioningTypeId=@provisioningType";

            return(await SqlExecutor.ExecuteAsync <SupplierDetails>(connectionString, query, new
            {
                catalogueItemType = (int)catalogueItemType,
                provisioningType = (int)provisioningType,
            }));
        }
        public void FromName_ProvisioningTypeId_ReturnsExpectedType(string provisioningTypeName)
        {
            var actual = ProvisioningType.FromName(provisioningTypeName);

            actual.Should().Be(ProvisioningType.Declarative);
        }
        public void FromId_ProvisioningTypeId_ReturnsExpectedType()
        {
            var actual = ProvisioningType.FromId(1);

            actual.Should().Be(ProvisioningType.Patient);
        }
Exemple #26
0
        public static void Parse_ReturnsExpectedEnumValue(ProvisioningType provisioningType)
        {
            var enumValue = OrderingEnums.Parse <ProvisioningType>(provisioningType.GetName());

            enumValue.Should().Be(provisioningType);
        }
        public void FromName_UnknownProvisioningTypeId_ReturnsNull()
        {
            var actual = ProvisioningType.FromName("Unknown");

            actual.Should().BeNull();
        }