Example #1
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}");
                }
            }
        }
Example #2
0
        private static void RefundPayment_Federated()
        {
            using (new SampleMethodScope())
            {
                var context   = new AnonymousCustomerBob().Context;
                var container = context.ShopsContainer();
                var orderid   = SimplePhysical2Items.Run(new AnonymousCustomerBob().Context);
                var order     = Orders.GetOrder(container, orderid);
                var paymentId = order.Components.OfType <FederatedPaymentComponent>()
                                .FirstOrDefault()
                                ?.Id;

                Orders.RunPendingOrdersMinion(context);
                Orders.RunReleasedOrdersMinion(context);
                var view = Proxy.GetValue(
                    ShopsContainer.GetEntityView(orderid, "RefundPayment", "RefundPayment", paymentId));

                var result = Proxy.DoCommand(ShopsContainer.DoAction(view));

                result.Should().NotBeNull();
                result.Messages.Should().NotContainErrors();

                var updatedOrderView = Proxy.GetValue(
                    ShopsContainer.GetEntityView(orderid, "Master", string.Empty, string.Empty));

                var salesActivities =
                    updatedOrderView.ChildViews.FirstOrDefault(p => p.Name.Equals("SalesActivities")) as EntityView;
                salesActivities.Should().NotBeNull();

                //There should be 2 Sales Activities now. The original one and the one for the refund.
                salesActivities?.ChildViews.Count.Should().Be(2);

                // Get the OrderPayments View and validate that the payment is now gone
                var paymentsView = Proxy.GetValue(
                    ShopsContainer.GetEntityView(orderid, "OrderPayments", string.Empty, string.Empty));
                paymentsView.ChildViews.Count().Should().Be(0);
            }
        }
Example #3
0
        private static void OnHoldScenarios()
        {
            using (new SampleMethodScope())
            {
                var jeff      = new AnonymousCustomerJeff();
                var container = jeff.Context.ShopsContainer();

                var orderId = SimplePhysical2Items.Run(jeff.Context);
                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 <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 = SimplePhysical2Items.Run(jeff.Context);
                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");
            }
        }
        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;
                }
            }
        }