コード例 #1
0
        public static void RunScenarios()
        {
            var watch = new Stopwatch();

            watch.Start();

            Console.WriteLine("Begin Entitlements");

            try
            {
                // Adventure Works
                var jeff = new AnonymousCustomerJeff();

                // Habitat
                var steve = new AnonymousCustomerSteve();

                BuyPhysicalAndGiftCard(jeff.Context);
                BuyGiftCard(jeff.Context);
                BuyGiftCards(jeff.Context);
                BuyWarranty(steve.Context);
                BuyInstallation(steve.Context);
                BuySubscription(steve.Context);
                BuyOneOfEach(steve.Context);

                BuyGiftCardAuthenticated(jeff.Context);
            }
            catch (Exception ex)
            {
                ConsoleExtensions.WriteColoredLine(ConsoleColor.Red, $"Exception in Scenario 'Entitlements' ({ex.Message}) : Stack={ex.StackTrace}");
            }

            watch.Stop();

            Console.WriteLine($"End Entitlements :{watch.ElapsedMilliseconds} ms");
        }
コード例 #2
0
        private static void GetSellableItemsAllLanguages()
        {
            using (new SampleMethodScope())
            {
                var jeff = new AnonymousCustomerJeff
                {
                    Context =
                    {
                        Language = "en"
                    }
                };
                var container = jeff.Context.ShopsContainer();
                container.MergeOption = MergeOption.NoTracking;

                var result = Proxy.Execute(container.GetCatalogItemsAllLanguages($"{typeof(SellableItem).FullName}, Sitecore.Commerce.Plugin.Catalog", "SellableItems", 0, 5).Expand("Components($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents)))")).ToList();
                result.Should().NotBeNullOrEmpty();

                result.Count.Should().Be(20);

                foreach (var item in result)
                {
                    item.Key.Should().NotBeNullOrEmpty();
                    item.Key.Split('_')[0].Should().BeOneOf("en", "fr-FR", "de-DE", "ja-JP");
                    item.Value.Should().NotBeNull();
                    item.Value.Should().BeOfType(typeof(SellableItem));
                    item.Key.Should().EndWith(item.Value.FriendlyId);
                }
            }
        }
コード例 #3
0
        public static string HoldOrder(string orderId)
        {
            using (new SampleMethodScope())
            {
                var jeff = new AnonymousCustomerJeff();

                var view = Proxy.GetEntityView(
                    jeff.Context.ShopsContainer(),
                    orderId,
                    "Details",
                    "HoldOrder",
                    string.Empty);
                view.Should().NotBeNull();
                view.Properties.Should().NotBeEmpty();

                var result = jeff.Context.ShopsContainer().DoAction(view).GetValue();
                result.Messages.Should().NotContainErrors();

                var temporaryCartId = result.Models.OfType <TemporaryCartCreated>().FirstOrDefault()?.TemporaryCartId;
                temporaryCartId.Should().NotBeNullOrEmpty();

                var temporaryCart = Carts.GetCart(temporaryCartId, jeff.Context);
                temporaryCart.Should().NotBeNull();

                return(temporaryCartId);
            }
        }
コード例 #4
0
        public static string HoldOrder(string orderId)
        {
            Console.WriteLine($"Hold order: '{orderId}'");

            var jeff = new AnonymousCustomerJeff();

            var view = Proxy.GetEntityView(jeff.Context.ShopsContainer(), orderId, "Details", "HoldOrder", string.Empty);

            view.Should().NotBeNull();
            view.Properties.Should().NotBeEmpty();

            var result = jeff.Context.ShopsContainer().DoAction(view).GetValue();

            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();

            var temporaryCartId = result.Models.OfType <TemporaryCartCreated>().FirstOrDefault()?.TemporaryCartId;

            temporaryCartId.Should().NotBeNullOrEmpty();

            var temporaryCart = Carts.GetCart(temporaryCartId);

            temporaryCart.Should().NotBeNull();

            return(temporaryCartId);
        }
コード例 #5
0
        private static void DynamicBundle_GetSelectedAutomaticPrice()
        {
            var container = new AnonymousCustomerJeff(EnvironmentConstants.HabitatShops).Context.ShopsContainer();
            var items     = new List <BundleItem>
            {
                new BundleItem()
                {
                    SellableItemId = "Habitat_Master|7042078|57042078", Quantity = 2
                },
                new BundleItem()
                {
                    SellableItemId = "Habitat_Master|6042063|", Quantity = 3
                },
            };
            var result = Proxy.GetValue(container.GetBundleSelectionPrice("Habitat_Master|6002002|", items));

            var itemPricing = result as SellableItemPricing;

            itemPricing.Should().NotBeNull();

            itemPricing.ListPrice.Should().NotBeNull();
            itemPricing.SellPrice.Should().NotBeNull();
            itemPricing.ItemId.Should().NotBeNullOrEmpty();
            itemPricing.ItemId.Should().Be("6002002");

            itemPricing.Variations.Should().BeEmpty();
        }
コード例 #6
0
        private static void GetSellableItem_DynamicBundle()
        {
            using (new SampleMethodScope())
            {
                var container = new AnonymousCustomerJeff(EnvironmentConstants.HabitatShops).Context.ShopsContainer();
                var result    = Proxy.GetValue(
                    container.SellableItems.ByKey("Habitat_Master|6002002|")
                    .Expand(
                        "Components($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents)))"));
                result.Should().NotBeNull();

                result.Policies.OfType <PurchaseOptionMoneyPolicy>().First().SellPrice.Amount.Should().Be(207.82M);

                result.Components.OfType <CatalogsComponent>()
                .First()
                .ChildComponents.OfType <CatalogComponent>()
                .First()
                .Name.Should()
                .Be("Habitat_Master");
                result.Components.OfType <ImagesComponent>()
                .First()
                .Images.First()
                .Should()
                .Be("C8D50E8E-D22A-4780-8A4F-7126167DEEC1");
                result.Components.OfType <BundleComponent>().First().BundleType.Should().Be("Dynamic");
                result.Components.OfType <BundleComponent>().First().BundleItems.Count.Should().Be(2);
                result.Components.OfType <BundleComponent>().First().ChildComponents.OfType <BundleItemUpgradeOptionsComponent>().Count().Should().Be(1);
                result.Components.OfType <BundleComponent>().First().ChildComponents.OfType <BundleItemUpgradeOptionsComponent>().First().UpgradeItems.Count.Should().Be(2);
                result.Components.OfType <ItemAvailabilityComponent>().First().IsAvailable.Should().Be(true);
                result.Components.OfType <ItemAvailabilityComponent>()
                .First()
                .ItemId.Should()
                .Be("Habitat_Master|6002002|");
            }
        }
コード例 #7
0
        private static void GetSellableItemsSummary()
        {
            using (new SampleMethodScope())
            {
                var container = new AnonymousCustomerJeff(EnvironmentConstants.HabitatShops).Context.ShopsContainer();

                var result = Proxy.Execute(container.GetSellableItemsSummary(new List <string>
                {
                    "Habitat_Master|6001001|",
                    "Habitat_Master|6042134|",
                    "Habitat_Master|6042134|56042137"
                }, true));

                var sellableItemSummaries = result as SellableItemSummary[] ?? result.ToArray();
                sellableItemSummaries.Should().NotBeNull();
                sellableItemSummaries.Should().NotBeEmpty();
                foreach (var summary in sellableItemSummaries)
                {
                    summary.ItemId.Should().NotBeNullOrEmpty();
                    summary.Summaries.Should().NotBeEmpty();
                    summary.Summaries.OfType <SellableItemPricing>().Any().Should().BeTrue();
                    summary.Summaries.OfType <ConnectItemAvailability>().Any().Should().BeTrue();
                }
            }
        }
コード例 #8
0
        public static void RunScenarios()
        {
            using (new SampleScenarioScope("Orders UX"))
            {
                try
                {
                    var jeff = new AnonymousCustomerJeff();
                    _orderId = Simple2PhysicalDigitalItems.Run(jeff.Context);
                    _orderId.Should().NotBeNull();
                    HoldOrder(_orderId);

                    OrderFulfillments();

                    SetFulfillment_Digital();
                    SetFulfillment_ShipToMe();
                    SetFulfillment_Split();

                    OrderPayments();
                    VoidPayment_Federated();
                    AddPayment_Federated(64.23M);

                    UndoOnHoldOrder();

                    OrderEntitlements(jeff.Context);

                    OnHoldScenarios();

                    // Run Federated Scenarios
                    var bob = new AnonymousCustomerBob();
                    _orderId = SimplePhysicalDigitalItemsFederatedPayment.Run(bob.Context);
                    _orderId.Should().NotBeNull();
                    HoldOrder(_orderId);

                    OrderFulfillments();

                    SetFulfillment_Digital();
                    SetFulfillment_ShipToMe();
                    SetFulfillment_Split();

                    OrderPayments();
                    VoidPayment_Federated();
                    AddPayment_Federated(64.23M);
                    RefundPayment_Federated();

                    _orderId = SimplePhysical2Items.Run(jeff.Context);
                    _orderId.Should().NotBeNull();
                    HoldOrder(_orderId);

                    AddPayment_GiftCard();

                    UndoOnHoldOrder();
                }
                catch (Exception ex)
                {
                    ConsoleExtensions.WriteErrorLine($"Exception in Scenario 'OrdersUX' (${ex.Message}) : Stack={ex.StackTrace}");
                }
            }
        }
        private static void TryEditCategoryUsingShopsEnvironment()
        {
            var shopsContainer = new AnonymousCustomerJeff().Context.ShopsContainer();
            var view           = Proxy.GetValue(shopsContainer.GetEntityView(ParentCategoryId, "Details", "EditCategory", string.Empty));

            view.Should().NotBeNull();
            view.Policies.Should().BeEmpty();
            view.Properties.Should().BeEmpty();
            view.ChildViews.Should().BeEmpty();
        }
コード例 #10
0
        private static void GetSellableItemsByParent_Page()
        {
            using (new SampleMethodScope())
            {
                var container = new AnonymousCustomerJeff(EnvironmentConstants.HabitatShops).Context.ShopsContainer();

                var result = Proxy.Execute(container.GetSellableItemsByParent("Entity-Category-Habitat_Master-FeaturedProducts", 0, 5));

                result.Should().NotBeNull();
                result.Should().HaveCount(5);
            }
        }
コード例 #11
0
        public static void CommitOnHoldOrder(string orderId)
        {
            Console.WriteLine($"Commit On-Hold Order: '{orderId}'");

            var jeff = new AnonymousCustomerJeff();

            var view = Proxy.GetEntityView(jeff.Context.ShopsContainer(), orderId, "Details", "CommitOnHoldOrder", string.Empty);

            view.Should().NotBeNull();
            view.Properties.Should().NotBeEmpty();

            var result = jeff.Context.ShopsContainer().DoAction(view).GetValue();

            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
        }
コード例 #12
0
        private static void SetOrderStatus()
        {
            using (new SampleMethodScope())
            {
                var container = new AnonymousCustomerJeff();

                var orderId = Buy3Items.Run(container.Context);
                var result  = Proxy.DoCommand(
                    new AnonymousCustomerJeff().Context.ShopsContainer().SetOrderStatus(orderId, "CustomStatus"));
                result.Messages.Should().NotContainErrors();

                var order = GetOrder(container.Context.ShopsContainer(), orderId);
                order.Should().NotBeNull();
                order.Status.Should().Be("CustomStatus");
            }
        }
コード例 #13
0
        private static void SetOrderStatus()
        {
            Console.WriteLine("Set order status");

            var container = new AnonymousCustomerJeff();

            var orderId = Buy3Items.Run(container.Context).Result;
            var result  = Proxy.DoCommand(new AnonymousCustomerJeff().Context.ShopsContainer().SetOrderStatus(orderId, "CustomStatus"));

            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();

            var order = GetOrder(container.Context.ShopsContainer(), orderId);

            order.Should().NotBeNull();
            order.Status.Should().Be("CustomStatus");
        }
コード例 #14
0
        private static void GetSellableItemsByParent_InvalidParent()
        {
            using (new SampleMethodScope())
            {
                var container = new AnonymousCustomerJeff(EnvironmentConstants.HabitatShops).Context.ShopsContainer();

                try
                {
                    var result = Proxy.Execute(container.GetSellableItemsByParent("InvalidParent", 0, 100));
                    ConsoleExtensions.WriteExpectedError();
                }
                catch (DataServiceQueryException ex)
                {
                    ex.Response.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
                }
            }
        }
コード例 #15
0
        public static void RunScenarios()
        {
            var shopsContainer     = new AnonymousCustomerJeff().Context.ShopsContainer();
            var authoringContainer = new AnonymousCustomerJeff(EnvironmentConstants.AdventureWorksAuthoring)
                                     .Context.AuthoringContainer();

            using (new SampleScenarioScope(MethodBase.GetCurrentMethod().DeclaringType.Name))
            {
                AddCatalog();
                EditCatalogUsingAuthoringEnvironment(authoringContainer);
                TryEditCatalogUsingShopsEnvironment(shopsContainer);
                ExportCatalogsFull().Wait();
                DeleteCatalog();
                ImportCatalogsReplace().Wait();
                CloneCatalog();
            }
        }
コード例 #16
0
        public static void CommitOnHoldOrder(string orderId)
        {
            using (new SampleMethodScope())
            {
                var jeff = new AnonymousCustomerJeff();

                var view = Proxy.GetEntityView(
                    jeff.Context.ShopsContainer(),
                    orderId,
                    "Details",
                    "CommitOnHoldOrder",
                    string.Empty);
                view.Should().NotBeNull();
                view.Properties.Should().NotBeEmpty();

                var result = jeff.Context.ShopsContainer().DoAction(view).GetValue();
                result.Messages.Should().NotContainErrors();
            }
        }
        public static void RunScenarios()
        {
            using (new SampleScenarioScope("Entitlements"))
            {
                // Adventure Works
                var jeff = new AnonymousCustomerJeff();

                // Habitat
                var steve = new AnonymousCustomerSteve();

                BuyPhysicalAndGiftCard(jeff.Context);
                BuyGiftCard(jeff.Context);
                BuyGiftCards(jeff.Context);
                BuyWarranty(steve.Context);
                BuyInstallation(steve.Context);
                BuySubscription(steve.Context);
                BuyOneOfEach(steve.Context);
                BuyGiftCardAuthenticated(jeff.Context);
            }
        }
コード例 #18
0
        public static void RunScenarios()
        {
            var shopsContainer     = new AnonymousCustomerJeff().Context.ShopsContainer();
            var authoringContainer = new AnonymousCustomerJeff(EnvironmentConstants.AdventureWorksAuthoring)
                                     .Context.AuthoringContainer();

            using (new SampleScenarioScope(MethodBase.GetCurrentMethod().DeclaringType.Name))
            {
                var partial = $"{Guid.NewGuid():N}".Substring(0, 5);
                CatalogName      = $"Console{partial}";
                CatalogCloneName = $"ConsoleClone{partial}";
                CatalogId        = $"Entity-Catalog-{CatalogName}";

                AddCatalog();
                EditCatalogUsingAuthoringEnvironment(authoringContainer);
                TryEditCatalogUsingShopsEnvironment(shopsContainer);
                ExportCatalogsFull().Wait();
                DeleteCatalog();
                ImportCatalogsReplace().Wait();
                CloneCatalog();
            }
        }
コード例 #19
0
        public static void RunScenarios()
        {
            var value = Settings.Default.RequestedTestRuns;

            _requestedTestRuns = value;

            var opsUser = new DevOpAndre();

            Randomizer.Seed = new Random(3897234); // Set the randomizer seed if you wish to generate repeatable data sets.
            var testParties = new Faker <Party>()
                              .RuleFor(u => u.FirstName, f => f.Name.FirstName())
                              .RuleFor(u => u.LastName, f => f.Name.LastName())
                              .RuleFor(u => u.Email, (f, u) => f.Internet.Email(u.FirstName, u.LastName))
                              .RuleFor(u => u.AddressName, f => "FulfillmentPartyName")
                              .RuleFor(u => u.Address1, f => f.Address.StreetAddress(true))
                              .RuleFor(u => u.City, f => f.Address.City())
                              .RuleFor(u => u.StateCode, f => "WA")
                              .RuleFor(u => u.State, f => "Washington")
                              .RuleFor(u => u.ZipPostalCode, f => "93612")
                              .RuleFor(u => u.CountryCode, f => "US")
                              .RuleFor(u => u.Country, f => "United States")
                              .FinishWith((f, u) => { System.Console.WriteLine($"BogusUser Address1={u.Address1}|City={u.City}"); });

            using (new SampleScenarioScope("Orders"))
            {
                System.Console.ForegroundColor = ConsoleColor.Green;
                System.Console.WriteLine("---------------------------------------------------");
                System.Console.WriteLine($"Requested Runs: {_requestedTestRuns}");
                System.Console.WriteLine("---------------------------------------------------");
                System.Console.ForegroundColor = ConsoleColor.Cyan;

                for (var i = 1; i <= _requestedTestRuns; i++)
                {
                    try
                    {
                        //Anonymous Customer Jeff Order Samples
                        var bogusParty = testParties.Generate();
                        var jeff       = new AnonymousCustomerJeff();
                        jeff.Context.Components.OfType <ElectronicFulfillmentComponent>().First().EmailAddress =
                            bogusParty.Email;
                        var physicalFulfillmentComponent = jeff.Context.Components
                                                           .OfType <PhysicalFulfillmentComponent>()
                                                           .FirstOrDefault();
                        if (physicalFulfillmentComponent != null)
                        {
                            physicalFulfillmentComponent.ShippingParty = bogusParty;
                        }

                        var danaHab = new RegisteredHabitatCustomerDana();
                        bogusParty = testParties.Generate();
                        danaHab.Context.Components.OfType <ElectronicFulfillmentComponent>().First().EmailAddress =
                            bogusParty.Email;
                        physicalFulfillmentComponent = danaHab.Context.Components.OfType <PhysicalFulfillmentComponent>()
                                                       .FirstOrDefault();
                        if (physicalFulfillmentComponent != null)
                        {
                            physicalFulfillmentComponent.ShippingParty = bogusParty;
                        }

                        danaHab.Context.CustomerId = AddCustomer(
                            danaHab.Context.Components.OfType <ElectronicFulfillmentComponent>().First().EmailAddress,
                            danaHab.Context,
                            bogusParty.FirstName,
                            bogusParty.LastName);

                        // RegisteredCustomer Dana Order Samples
                        var danaAdv = new RegisteredCustomerDana();
                        bogusParty = testParties.Generate();
                        danaAdv.Context.Components.OfType <ElectronicFulfillmentComponent>().First().EmailAddress =
                            bogusParty.Email;
                        danaAdv.Context.CustomerId = AddCustomer(
                            danaAdv.Context.Components.OfType <ElectronicFulfillmentComponent>().First().EmailAddress,
                            danaAdv.Context,
                            bogusParty.FirstName,
                            bogusParty.LastName);

                        var lastSimplePhysical = SimplePhysical2Items.Run(jeff.Context);
                        var lastGiftCardOrder  = BuyGiftCards.Run(jeff.Context);
                        _createdGiftCard = jeff.Context.GiftCards.First();

                        var lastBuyWithGiftCard = BuyWithGiftCard.Run(jeff.Context);

                        SimplePhysicalRtrn15Coupon.Run(jeff.Context);
                        AddRemovePayment.Run(jeff.Context);
                        AddRemoveCoupon.Run(jeff.Context);

                        UseLimitedCouponMoreThanOnce.Run(jeff.Context);

                        OnSaleItem.Run(jeff.Context);
                        BuyBackOrderedItem.Run(jeff.Context);
                        BuyPreOrderableItem.Run(jeff.Context);
                        BuyAvailabilitySplitItem.Run(jeff.Context);
                        AddRemoveCartLine.Run(jeff.Context);
                        var lastSplitShipment = BuySplitShipment.Run(jeff.Context);

                        ////International
                        var katrina = new InternationalShopperKatrina();

                        var result = Proxy.GetValue(
                            katrina.Context.ShopsContainer()
                            .SellableItems.ByKey("Adventure Works Catalog,AW055 01,33")
                            .Expand(
                                "Components($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents)))"));
                        result.Should().NotBeNull();
                        result.ListPrice.CurrencyCode.Should().Be("EUR");
                        result.ListPrice.Amount.Should().Be(1.0M);

                        ////These samples leverage EntityViews and EntityActions
                        ////For post order management
                        ////Place a Split shipment order and then put it on hold
                        SplitShipmentOnHold.Run(jeff.Context);
                        ////Place a Split shipment order, place it on hold and delete one of the lines
                        SplitShipmentThenDeleteLine.Run(jeff.Context);

                        ////Retrieve the Business User "View" for the SplitShipment end order.  The Order should still be in a Pending State
                        Proxy.GetValue(
                            jeff.Context.ShopsContainer()
                            .GetEntityView(lastSplitShipment, "Master", string.Empty, string.Empty));

                        var cancelOrderId = Buy3Items.Run(jeff.Context);
                        if (!string.IsNullOrEmpty(cancelOrderId))
                        {
                            CancelOrder(cancelOrderId);
                        }

                        ////RegisteredCustomer Dana Order Samples
                        SimplePhysical2Items.Run(danaAdv.Context);
                        BuyGiftCards.Run(danaAdv.Context);
                        BuyWarranty.Run(danaHab.Context, 1);

                        danaHab.GoShopping();

                        //Force the pending orders Minion to run
                        RunPendingOrdersMinion(opsUser.Context);

                        //Force the Released Orders Minion to run
                        RunReleasedOrdersMinion(opsUser.Context);

                        //The Following represent examples of using the Business User (BizOps) Api to handle Orders.
                        //At this stage, the orders have been released and only actions allowed on Released or Problem orders can occur

                        //Get the last SimplePhysical order to show how it is changed by the Minions
                        var orderMaster = Proxy.GetEntityView(
                            jeff.Context.ShopsContainer(),
                            lastSimplePhysical,
                            "Master",
                            string.Empty,
                            string.Empty);
                        if (!orderMaster.ChildViews.Any(p => p.Name.EqualsIgnoreCase("Shipments")))
                        {
                            ConsoleExtensions.WriteErrorLine($"LastSimplePhysical.MissingShipments: OrderId={lastSimplePhysical}");
                        }

                        ////Get the last SimplePhysical order to show how it is changed by the Minions
                        var lastGiftCardMaster = Proxy.GetEntityView(
                            jeff.Context.ShopsContainer(),
                            lastGiftCardOrder,
                            "Master",
                            string.Empty,
                            string.Empty);

                        ////There should not be a Shipments child EntityView because this was a Digital order
                        lastGiftCardMaster.ChildViews.Count(p => p.Name == "Shipments").Should().Be(0);

                        var giftCardNew = jeff.Context.ShopsContainer()
                                          .GiftCards.ByKey("Entity-GiftCard-" + _createdGiftCard)
                                          .Expand("Components($expand=ChildComponents)")
                                          .GetValue() as GiftCard;
                        giftCardNew.Should().NotBeNull();

                        var lastBuyWithGiftCardView = Proxy.GetEntityView(
                            jeff.Context.ShopsContainer(),
                            lastBuyWithGiftCard,
                            "Master",
                            string.Empty,
                            string.Empty);
                        var salesActivities =
                            lastBuyWithGiftCardView.ChildViews.First(p => p.Name == "SalesActivities") as EntityView;
                        salesActivities.ChildViews.Count.Should().Be(2);

                        // Example of updating the Order Status from via a service.  This is for external systems to push status updates
                        SetOrderStatus();
                    }
                    catch (Exception ex)
                    {
                        ConsoleExtensions.WriteColoredLine(ConsoleColor.Red, $"Test Exception - {ex.Message}");
                        ConsoleExtensions.WriteColoredLine(ConsoleColor.Red, $"Test Exception - {ex.StackTrace}");
                    }

                    System.Console.ForegroundColor = ConsoleColor.Cyan;
                    System.Console.WriteLine("---------------------------------------------------");
                    System.Console.WriteLine($"Test pass {i} of {_requestedTestRuns}");
                    System.Console.WriteLine($"Orders:{_totalOrders} Dollars:{_totalOrderDollars}");
                    System.Console.ForegroundColor = ConsoleColor.Cyan;
                }
            }
        }
コード例 #20
0
        private static void OnHoldScenarios()
        {
            var jeff      = new AnonymousCustomerJeff();
            var container = jeff.Context.ShopsContainer();

            var orderId = Scenarios.SimplePhysical2Items.Run(jeff.Context).Result;

            orderId.Should().NotBeNull();

            // hold order
            HoldOrder(orderId);

            // Get an Order Master view
            var orderMaster = Proxy.GetEntityView(container, orderId, "Master", string.Empty, string.Empty);

            // Adjustments
            var adjustments = orderMaster.ChildViews.FirstOrDefault(p => p.Name == "Adjustments") as EntityView;

            adjustments.Should().NotBeNull();
            adjustments.ChildViews.Count.Should().NotBe(0);
            var adjustment = adjustments.ChildViews[0] as EntityView;

            adjustment.DisplayName.Should().Be("Adjustment");
            adjustment.Properties.FirstOrDefault(p => p.Name == "Adjustment")?.Value.Should().NotBeEmpty();
            adjustment.Properties.FirstOrDefault(p => p.Name == "Type")?.Value.Should().NotBeEmpty();

            // Messages
            var messages = orderMaster.ChildViews.FirstOrDefault(p => p.Name == "Messages") as EntityView;

            messages.Should().NotBeNull();
            messages.ChildViews.Count.Should().NotBe(0);
            var message = messages.ChildViews[0] as EntityView;

            message.DisplayName.Should().Be("Message");
            message.Properties.FirstOrDefault(p => p.Name == "Code")?.Value.Should().NotBeEmpty();
            message.Properties.FirstOrDefault(p => p.Name == "Text")?.Value.Should().NotBeEmpty();

            // Edit line
            var lines = orderMaster.ChildViews.FirstOrDefault(p => p.Name == "Lines") as EntityView;

            lines?.Policies.OfType <ActionsPolicy>().First().Actions.First(p => p.Name == "AddLineItem").IsEnabled.Should().Be(true);
            var line   = lines?.ChildViews.First() as EntityView;
            var itemId = line?.Properties.FirstOrDefault(p => p.Name == "ItemId")?.Value;
            var editLineItemRequest = Proxy.GetEntityView(container, orderId, "EditLineItem", "EditLineItem", itemId);

            editLineItemRequest.Properties.First(p => p.Name == "Quantity").Value = "2";
            var actionResult = Proxy.GetValue(container.DoAction(editLineItemRequest));

            actionResult.ResponseCode.Should().Be("Ok");
            var totals = actionResult.Models.OfType <Sitecore.Commerce.Plugin.Carts.Totals>().FirstOrDefault();

            totals.Should().NotBeNull();

            // add payment
            AddPayment_Federated(totals.GrandTotal.Amount, orderId);

            // Commit the OnHold Order
            CommitOnHoldOrder(orderId);

            var order = Orders.GetOrder(container, orderId);

            order.Status.Should().Be("Pending");

            orderId = Scenarios.SimplePhysical2Items.Run(jeff.Context).Result;
            orderId.Should().NotBeNull();

            // hold order
            HoldOrder(orderId);

            order  = Proxy.GetValue(container.Orders.ByKey(orderId).Expand("Components"));
            totals = order.Totals;

            // Void payment
            VoidPayment_Federated(orderId);

            // add payment
            AddPayment_Federated(totals.GrandTotal.Amount, orderId);

            // Commit the OnHold Order
            CommitOnHoldOrder(orderId);

            order = Orders.GetOrder(container, orderId);
            order.Status.Should().Be("Pending");
        }
コード例 #21
0
        public static void RunScenarios()
        {
            var watch = new Stopwatch();

            watch.Start();

            Console.WriteLine("Begin OrdersUX");

            try
            {
                // Run CredtCard scenarios
                var jeff = new AnonymousCustomerJeff();
                _orderId = Scenarios.Simple2PhysicalDigitalItems.Run(jeff.Context).Result;
                _orderId.Should().NotBeNull();
                HoldOrder(_orderId);

                OrderFulfillments();

                SetFulfillment_Digital();
                SetFulfillment_ShipToMe();
                SetFulfillment_Split();

                OrderPayments();
                VoidPayment_Federated();
                AddPayment_Federated(64.23M);

                UndoOnHoldOrder();

                OrderEntitlements(jeff.Context);

                OnHoldScenarios();
                // Run Federated Scenarios
                var bob = new AnonymousCustomerBob();
                _orderId = Scenarios.SimplePhysicalDigitalItemsFederatedPayment.Run(bob.Context).Result;
                _orderId.Should().NotBeNull();
                HoldOrder(_orderId);

                OrderFulfillments();

                SetFulfillment_Digital();
                SetFulfillment_ShipToMe();
                SetFulfillment_Split();

                OrderPayments();
                VoidPayment_Federated();
                AddPayment_Federated(64.23M);

                RefundPayment_Federated();

                _orderId = Scenarios.SimplePhysical2Items.Run(jeff.Context).Result;
                _orderId.Should().NotBeNull();
                HoldOrder(_orderId);

                AddPayment_GiftCard();

                UndoOnHoldOrder();
            }
            catch (Exception ex)
            {
                ConsoleExtensions.WriteColoredLine(ConsoleColor.Red, $"Exception in Scenario 'OrdersUX' (${ex.Message}) : Stack={ex.StackTrace}");
            }

            watch.Stop();

            Console.WriteLine($"End PromotionsUX :{watch.ElapsedMilliseconds} ms");
        }
コード例 #22
0
        private static void SellableItemPricing_ForwardInTime()
        {
            using (new SampleMethodScope())
            {
                // NOW REQUEST
                var result = Proxy.GetValue(
                    Container.SellableItems.ByKey("Adventure Works Catalog,AW055 01,")
                    .Expand(
                        "Components($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents)))"));
                result.Should().NotBeNull();

                result.Policies.OfType <PriceCardPolicy>().Should().NotBeNull();
                result.Policies.OfType <PriceCardPolicy>().First().PriceCardName.Should().Be("AdventureWorksPriceCard");

                result.Policies.OfType <ListPricingPolicy>().Should().NotBeNull();
                result.Policies.OfType <ListPricingPolicy>().First().Prices.First().Amount.Should().Be(58);
                result.Policies.OfType <ListPricingPolicy>().First().Prices.First().CurrencyCode.Should().Be("USD");
                result.ListPrice.Amount.Should().Be(58);

                result.Policies.OfType <PurchaseOptionMoneyPolicy>().Should().NotBeNull();
                result.Policies.OfType <PurchaseOptionMoneyPolicy>().First().SellPrice.Amount.Should().Be(10.0M);
                result.Policies.OfType <PurchaseOptionMoneyPolicy>().First().SellPrice.CurrencyCode.Should().Be("USD");

                result.Components.OfType <PriceSnapshotComponent>().Should().NotBeNull();
                result.Components.OfType <PriceSnapshotComponent>()
                .First()
                .Tiers.FirstOrDefault(t => t.Quantity == 1)
                ?.Price.Should()
                .Be(10.0M);

                result.Components.OfType <ItemVariationsComponent>().Should().NotBeNull();
                result.Components.OfType <ItemVariationsComponent>().First().ChildComponents.Should().NotBeNull();
                result.Components.OfType <ItemVariationsComponent>()
                .First()
                .ChildComponents.Cast <ItemVariationComponent>()
                .ToList()
                .ForEach(
                    v =>
                {
                    v.Policies.OfType <ListPricingPolicy>().Should().NotBeNull();
                    v.Policies.OfType <ListPricingPolicy>()
                    .First()
                    .Prices.First(p => p.CurrencyCode.Equals("USD"))
                    .Amount.Should()
                    .Be(58M);
                    v.ListPrice.Amount.Should().Be(58M);

                    v.Policies.OfType <PurchaseOptionMoneyPolicy>().Should().NotBeNull();
                    v.Policies.OfType <PurchaseOptionMoneyPolicy>()
                    .First()
                    .SellPrice.Amount.Should()
                    .BeInRange(9M, 10M);
                    v.Policies.OfType <PurchaseOptionMoneyPolicy>()
                    .First()
                    .SellPrice.CurrencyCode.Should()
                    .Be("USD");

                    v.ChildComponents.OfType <PriceSnapshotComponent>().Should().NotBeNull();
                    result.Components.OfType <PriceSnapshotComponent>()
                    .First()
                    .Tiers.FirstOrDefault(t => t.Quantity == 1)
                    ?.Price.Should()
                    .BeInRange(9M, 10.0M);
                });

                // BACK IN TIME REQUEST
                var jeff = new AnonymousCustomerJeff
                {
                    Context =
                    {
                        EffectiveDate = DateTimeOffset.Now.AddDays(30)
                    }
                };
                var container = jeff.Context.ShopsContainer();
                result = Proxy.GetValue(
                    container.SellableItems.ByKey("Adventure Works Catalog,AW055 01,")
                    .Expand(
                        "Components($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents)))"));
                result.Should().NotBeNull();

                result.Policies.OfType <PriceCardPolicy>().Should().NotBeNull();
                result.Policies.OfType <PriceCardPolicy>().First().PriceCardName.Should().Be("AdventureWorksPriceCard");

                result.Policies.OfType <ListPricingPolicy>().Should().NotBeNull();
                result.Policies.OfType <ListPricingPolicy>().First().Prices.First().Amount.Should().Be(58M);
                result.Policies.OfType <ListPricingPolicy>().First().Prices.First().CurrencyCode.Should().Be("USD");
                result.ListPrice.Amount.Should().Be(58);

                result.Policies.OfType <PurchaseOptionMoneyPolicy>().Should().NotBeNull();
                result.Policies.OfType <PurchaseOptionMoneyPolicy>().First().SellPrice.Amount.Should().Be(7M);
                result.Policies.OfType <PurchaseOptionMoneyPolicy>().First().SellPrice.CurrencyCode.Should().Be("USD");

                result.Components.OfType <PriceSnapshotComponent>().Should().NotBeNull();
                result.Components.OfType <PriceSnapshotComponent>()
                .First()
                .Tiers.FirstOrDefault(t => t.Quantity == 1)
                ?.Price.Should()
                .Be(7M);

                result.Components.OfType <ItemVariationsComponent>().Should().NotBeNull();
                result.Components.OfType <ItemVariationsComponent>().First().ChildComponents.Should().NotBeNull();
                result.Components.OfType <ItemVariationsComponent>()
                .First()
                .ChildComponents.Cast <ItemVariationComponent>()
                .ToList()
                .ForEach(
                    v =>
                {
                    v.Policies.OfType <ListPricingPolicy>().Should().NotBeNull();
                    v.Policies.OfType <ListPricingPolicy>()
                    .First()
                    .Prices.First(p => p.CurrencyCode.Equals("USD"))
                    .Amount.Should()
                    .Be(58M);
                    v.ListPrice.Amount.Should().Be(58M);

                    v.Policies.OfType <PurchaseOptionMoneyPolicy>().Should().NotBeNull();
                    v.Policies.OfType <PurchaseOptionMoneyPolicy>()
                    .First()
                    .SellPrice.Amount.Should()
                    .BeInRange(7M, 10M);
                    v.Policies.OfType <PurchaseOptionMoneyPolicy>()
                    .First()
                    .SellPrice.CurrencyCode.Should()
                    .Be("USD");

                    v.ChildComponents.OfType <PriceSnapshotComponent>().Should().NotBeNull();
                    result.Components.OfType <PriceSnapshotComponent>()
                    .First()
                    .Tiers.FirstOrDefault(t => t.Quantity == 1)
                    ?.Price.Should()
                    .Be(7M);
                });
            }
        }