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; } } }
private static void CloneEnvironment() { using (new SampleMethodScope()) { var originalEnvironment = ExportEnvironment( EnvironmentConstants.AdventureWorksShops); // Export an Environment to use as a template var serializer = new JsonSerializer { TypeNameHandling = TypeNameHandling.All, NullValueHandling = NullValueHandling.Ignore }; var reader = new StringReader(originalEnvironment); CommerceEnvironment newEnvironment = null; using (var jsonReader = new JsonTextReader(reader) { DateParseHandling = DateParseHandling.DateTimeOffset }) { newEnvironment = serializer.Deserialize <CommerceEnvironment>(jsonReader); } // Change the Id of the environment in order to import as a new Environment var newEnvironmentId = Guid.NewGuid(); newEnvironment.ArtifactStoreId = newEnvironmentId; newEnvironment.Name = "ConsoleSample." + newEnvironmentId.ToString("N"); var sw = new StringWriter(new StringBuilder()); string newSerializedEnvironment = null; using (var writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, newSerializedEnvironment); } newSerializedEnvironment = sw.ToString(); // imports the environment into Sitecore Commerce var importedEnvironment = ImportEnvironment(newSerializedEnvironment); importedEnvironment.EntityId.Should() .Be($"Entity-CommerceEnvironment-ConsoleSample.{newEnvironmentId}"); importedEnvironment.Name.Should().Be($"ConsoleSample.{newEnvironmentId}"); // Adds a policy var policyResult = Proxy.DoOpsCommand( OpsContainer.AddPolicy( importedEnvironment.EntityId, "Sitecore.Commerce.Plugin.Availability.GlobalAvailabilityPolicy, Sitecore.Commerce.Plugin.Availability", new GlobalAvailabilityPolicy { AvailabilityExpires = 0 }, "GlobalEnvironment")); policyResult.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)) .Should() .BeFalse(); policyResult.Models.OfType <PolicyAddedModel>().Any().Should().BeTrue(); // Initialize the Environment with default artifacts Bootstrapping.InitializeEnvironment(OpsContainer, $"ConsoleSample.{newEnvironmentId}"); // Get a SellableItem from the environment to assure that we have set it up correctly var shopperInNewEnvironmentContainer = new RegisteredCustomerDana { Context = { Environment = $"ConsoleSample.{newEnvironmentId}" } }.Context.ShopsContainer(); var result = Proxy.GetValue( shopperInNewEnvironmentContainer.SellableItems.ByKey("Adventure Works Catalog,AW055 01,") .Expand( "Components($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents)))")); result.Should().NotBeNull(); result.Name.Should().Be("Unisex hiking pants"); // Get the environment to validate change was made var updatedEnvironment = Proxy.GetValue(OpsContainer.Environments.ByKey(importedEnvironment.EntityUniqueId.ToString())); var globalAvailabilityPolicy = updatedEnvironment.Policies.OfType <GlobalAvailabilityPolicy>().FirstOrDefault(); globalAvailabilityPolicy.Should().NotBeNull(); globalAvailabilityPolicy.AvailabilityExpires.Should().Be(0); } }
public static void RunScenarios() { var watch = new Stopwatch(); watch.Start(); NewEnvironment(); var habitat = Proxy.GetValue(OpsContainer.Environments.ByKey("Entity-CommerceEnvironment-HabitatAuthoring").Expand("Components")); habitat.Should().NotBeNull(); Console.WriteLine("Begin Clone Environment"); // Export an Environment to use as a template var originalEnvironment = ExportEnvironment("AdventureWorksShops"); var environmentObject = JsonConvert.DeserializeObject(originalEnvironment); // Get a dynamic view of the JSON object var dynamicEnvironment = (dynamic)environmentObject; // Change the Id of the environment in order to import as a new Environment var newEnvironmentId = Guid.NewGuid().ToString("N"); dynamicEnvironment.ArtifactStoreId = newEnvironmentId; dynamicEnvironment.Name = "ConsoleSample." + newEnvironmentId; var newSerializedEnvironment = JsonConvert.SerializeObject(environmentObject); // imports the environment into Sitecore Commerce var importedEnvironment = ImportEnvironment(newSerializedEnvironment); importedEnvironment.EnvironmentId.Should().Be($"Entity-CommerceEnvironment-ConsoleSample.{newEnvironmentId}"); importedEnvironment.Name.Should().Be($"ConsoleSample.{newEnvironmentId}"); // Adds a policy var policyResult = Proxy.DoOpsCommand( OpsContainer.AddPolicy( importedEnvironment.EnvironmentId, "Sitecore.Commerce.Plugin.Availability.GlobalAvailabilityPolicy, Sitecore.Commerce.Plugin.Availability", new GlobalAvailabilityPolicy { AvailabilityExpires = 0 }, "GlobalEnvironment")); policyResult.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse(); policyResult.Models.OfType <PolicyAddedModel>().Any().Should().BeTrue(); // Initialize the Environment with default artifacts Bootstrapping.InitializeEnvironment(OpsContainer, $"ConsoleSample.{newEnvironmentId}"); var shopperInNewEnvironmentContainer = new RegisteredCustomerDana { Context = { Environment = $"ConsoleSample.{newEnvironmentId}" } }.Context.ShopsContainer(); // Get a SellableItem from the environment to assure that we have set it up correctly var result = Proxy.GetValue(shopperInNewEnvironmentContainer.SellableItems.ByKey("Adventure Works Catalog,AW055 01,") .Expand("Components($expand=ChildComponents($expand=ChildComponents($expand=ChildComponents)))")); result.Should().NotBeNull(); result.Name.Should().Be("Unisex hiking pants"); // Get the environment to validate change was made var updatedEnvironment = Proxy.GetValue(OpsContainer.Environments.ByKey(importedEnvironment.EnvironmentId)); var globalAvailabilityPolicy = updatedEnvironment.Policies.OfType <GlobalAvailabilityPolicy>().FirstOrDefault(); globalAvailabilityPolicy.Should().NotBeNull(); globalAvailabilityPolicy.AvailabilityExpires.Should().Be(0); var orderListsPolicy = updatedEnvironment.Policies.OfType <KnownOrderListsPolicy>().FirstOrDefault(); orderListsPolicy.Should().NotBeNull(); orderListsPolicy.OrderDashboardLists = new ObservableCollection <KeyValueString> { new KeyValueString { Key = "listName", Value = "icon" } }; policyResult = Proxy.DoOpsCommand( OpsContainer.AddPolicy( importedEnvironment.EnvironmentId, "Sitecore.Commerce.Plugin.Orders.KnownOrderListsPolicy, Sitecore.Commerce.Plugin.Orders", orderListsPolicy, "GlobalEnvironment")); policyResult.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse(); policyResult.Models.OfType <PolicyAddedModel>().Any().Should().BeTrue(); updatedEnvironment = Proxy.GetValue(OpsContainer.Environments.ByKey(importedEnvironment.EnvironmentId)); orderListsPolicy = updatedEnvironment.Policies.OfType <KnownOrderListsPolicy>().FirstOrDefault(); orderListsPolicy.Should().NotBeNull(); orderListsPolicy.OrderDashboardLists.Should().OnlyContain(l => l.Key.Equals("listName")); watch.Stop(); Console.WriteLine($"End Clone Environments: {watch.ElapsedMilliseconds} ms"); }