Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                OpsServiceUri       = Settings.Default.OpsServiceUri;
                ShopsServiceUri     = Settings.Default.ShopsServiceUri;
                MinionsServiceUri   = Settings.Default.MinionsServiceUri;
                AuthoringServiceUri = Settings.Default.AuthoringServiceUri;
                SitecoreIdServerUri = Settings.Default.SitecoreIdServerUri;

                UserName = Settings.Default.UserName;
                Password = Settings.Default.Password;

                SitecoreTokenRaw = SitecoreIdServerAuth.GetToken();
                SitecoreToken    = $"Bearer {SitecoreTokenRaw}";

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                System.Console.ForegroundColor = ConsoleColor.Cyan;

                if (ShouldBootstrapOnLoad)
                {
                    Bootstrapping.RunScenarios();
                    Content.RunScenarios();
                }

                if (ShouldDevOpsScenarios)
                {
                    Environments.RunScenarios();

                    Plugins.RunScenarios();

                    Entities.RunScenarios();

                    Policies.RunScenarios();

                    Caching.RunScenarios();
                }

                if (ShouldRunCatalogScenarios)
                {
                    Catalogs.RunScenarios();
                    CatalogsUX.RunScenarios();

                    Categories.RunScenarios();
                    CategoriesUX.RunScenarios();

                    SellableItems.RunScenarios();
                    SellableItemsUX.RunScenarios();
                }

                if (ShouldRunPricingScenarios)
                {
                    Pricing.RunScenarios();
                    PricingUX.RunScenarios();
                }

                if (ShouldRunPromotionsScenarios)
                {
                    Promotions.RunScenarios();
                    PromotionsUX.RunScenarios();
                    PromotionsRuntime.RunScenarios();

                    Rules.RunScenarios();

                    Coupons.RunScenarios();
                    CouponsUX.RunScenarios();
                }

                if (ShouldRunInventoryScenarios)
                {
                    Inventory.RunScenarios();
                    InventoryUX.RunScenarios();
                }

                if (ShouldRunOrdersScenarios)
                {
                    Fulfillment.RunScenarios();

                    Payments.RunScenarios();

                    Carts.RunScenarios();

                    Returns.RunScenarios();

                    OrdersUX.RunScenarios();
                    Orders.RunScenarios();

                    Shipments.RunScenarios(); // ORDERS HAVE TO BE RELEASED FOR SHIPMENTS TO GET GENERATED
                }

                if (ShouldRunCustomersScenarios)
                {
                    CustomersUX.RunScenarios();
                }

                if (ShouldRunEntitlementsScenarios)
                {
                    Entitlements.RunScenarios();
                }

                if (ShouldRunSearchScenarios)
                {
                    Search.RunScenarios();
                }

                if (ShouldRunBusinessUsersScenarios)
                {
                    ComposerUX.RunScenarios();
                    Composer.RunScenarios();
                }

                if (ShouldRunVersionScenarios)
                {
                    Versions.RunScenarios();
                }

                stopwatch.Stop();

                System.Console.WriteLine($"Test Runs Complete - {stopwatch.ElapsedMilliseconds} ms -  (Hit any key to continue)");

                if (DemoStops)
                {
                    System.Console.ReadKey();
                }
            }
            catch (Exception ex)
            {
                ConsoleExtensions.WriteErrorLine("An unexpected exception occurred.");
                ConsoleExtensions.WriteErrorLine(ex.ToString());
                System.Console.ReadKey();
            }

            System.Console.WriteLine("done.");
        }
        private static void RequestDigitalRma()
        {
            using (new SampleMethodScope())
            {
                var order   = CreateDigitalCompletedOrder();
                var orderId = order.Id;
                var lineId  = order.Lines.FirstOrDefault()?.Id;

                var result =
                    Proxy.DoCommand(
                        _context.ShopsContainer()
                        .RequestRma(
                            orderId,
                            "ConsoleWrongItem",
                            new List <RmaLineComponent>
                {
                    new RmaLineComponent
                    {
                        LineId   = lineId,
                        Quantity = 1
                    }
                }));

                result.Should().NotBeNull();
                result.Messages.Should().NotContainErrors();
                var rmaId = result.Models.OfType <Sitecore.Commerce.Core.PersistedEntityModel>().FirstOrDefault(m => m.Name.Equals(typeof(ReturnMerchandiseAuthorization).FullName))?.EntityId;
                rmaId.Should().NotBeNullOrEmpty();
                var rmaFriendlyId = result.Models.OfType <Sitecore.Commerce.Core.PersistedEntityModel>().FirstOrDefault(m => m.Name.Equals(typeof(ReturnMerchandiseAuthorization).FullName))?.EntityFriendlyId;
                rmaFriendlyId.Should().NotBeNullOrEmpty();

                var rma = GetRma(_context.ShopsContainer(), rmaId);
                rma.Status.Should().Be("RefundPending");
                rma.Lines.Should().Contain(l => l.LineId.Equals(lineId));
                rma.Order.EntityTarget.Should().Be(orderId);
                rma.ItemsReturnedDate.Should().NotBe(DateTimeOffset.MinValue);

                order = Orders.GetOrder(_context.ShopsContainer(), orderId);
                order.Should().NotBeNull();
                order.Components.OfType <OrderRmasComponent>().FirstOrDefault().Should().NotBeNull();
                order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.Should().NotBeEmpty();
                order.Components.OfType <OrderRmasComponent>()
                .FirstOrDefault()
                ?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))
                .Should()
                .NotBeNull();
                order.Components.OfType <OrderRmasComponent>()
                .FirstOrDefault()
                ?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))
                ?.Lines.Should()
                .NotBeEmpty();
                order.Components.OfType <OrderRmasComponent>()
                .FirstOrDefault()
                ?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))
                ?.Lines.Count.Should()
                .Be(rma.Lines.Count);
                order.Components.OfType <OrderRmasComponent>()
                .FirstOrDefault()
                ?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))
                ?.Lines.Should()
                .Contain(rma.Lines.Select(l => l.LineId));
            }
        }
        private static void OnHoldScenarios()
        {
            using (new SampleMethodScope())
            {
                var jeff      = new AnonymousCustomerJeff();
                var container = jeff.Context.ShopsContainer();

                var orderId = Scenarios.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 <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);
                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 ReturnedItemReceived(
            Engine.Container container,
            string rmaFriendlyId,
            string orderId,
            string lineId)
        {
            var result = Proxy.DoCommand(container.ReturnedItemReceived(rmaFriendlyId));

            result.Should().NotBeNull();
            result.Messages.Should().NotContainErrors();
            var rmaId = result.Models.OfType <Sitecore.Commerce.Core.PersistedEntityModel>().FirstOrDefault(m => m.Name.Equals(typeof(ReturnMerchandiseAuthorization).FullName))?.EntityId;

            rmaId.Should().NotBeNullOrEmpty();

            var rma = GetRma(container, rmaId);

            rma.Status.Should().Be("RefundPending");
            rma.ItemsReturnedDate.Should().BeCloseTo(DateTimeOffset.UtcNow, 5000);

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

            order.Should().NotBeNull();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault().Should().NotBeNull();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.Should().NotBeEmpty();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId)).Should().NotBeNull();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .Any()
            .Should()
            .BeTrue();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.Should()
            .NotBeEmpty();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.Count.Should()
            .Be(order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.Count);
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.OrderByDescending(r => r.ReturnedDate)
            .FirstOrDefault()
            .Should()
            .NotBeNull();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.OrderByDescending(r => r.ReturnedDate)
            .FirstOrDefault()
            ?.Quantity.Should()
            .Be(rma.Lines.FirstOrDefault()?.Quantity);
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.OrderByDescending(r => r.ReturnedDate)
            .FirstOrDefault()
            ?.ReturnedDate.Should()
            .BeCloseTo(DateTimeOffset.UtcNow, 5000);
        }