public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); // Add Cart Line with Variant var commandResult = Proxy.DoCommand( container.AddCartLine(cartId, "Adventure Works Catalog|AW098 04|5", 1)); var cartLineId = commandResult.Models.OfType <LineAdded>().FirstOrDefault()?.LineId; // Add Cart Line without Variant Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW475 14|", 1)); // Add a valid coupon Proxy.DoCommand(container.AddCouponToCart(cartId, "SingleUseCouponCode")); Proxy.DoCommand(container.UpdateCartLine(cartId, cartLineId, 10)); commandResult = Proxy.DoCommand( container.SetCartFulfillment( cartId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var totals = commandResult.Models.OfType <Totals>().First(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount); Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Totals.GrandTotal.Amount.Should().Be(1219.90M); cartId = Guid.NewGuid().ToString("B"); // Add Cart Line with Variant Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW098 04|5", 1)); // Add Cart Line without Variant Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW475 14|", 1)); // Add a valid coupon commandResult = Proxy.DoCommand(container.AddCouponToCart(cartId, "SingleUseCouponCode")); commandResult.ResponseCode.Should() .NotBe( "Ok", "Expecting failure as this coupon code is single use only and has been used prior"); ConsoleExtensions.WriteExpectedError(); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine(ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW188 06|20", 1)); Proxy.DoCommand( container.SetCartFulfillment( cartId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var giftCardToUse = context.GiftCards.First(); var commandResult = Proxy.DoCommand( container.AddGiftCardPayment( cartId, new GiftCardPaymentComponent { Id = Guid.NewGuid().ToString(), PaymentMethod = new EntityReference { EntityTarget = "B5E5464E-C851-4C3C-8086-A4A874DD2DB0", Name = "GiftCard" }, GiftCardCode = giftCardToUse, Amount = Money.CreateMoney(50), })); var totals = commandResult.Models.OfType <Totals>().First(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount - totals.PaymentsTotal.Amount); commandResult = Proxy.DoCommand( container.AddFederatedPayment( cartId, paymentComponent)); totals = commandResult.Models.OfType <Totals>().First(); totals.PaymentsTotal.Amount.Should().Be(totals.GrandTotal.Amount); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Totals.GrandTotal.Amount.Should().Be(119.50M); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); // Add Cart Line with Variant Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW098 04|5", 1)); // Add Cart Line without Variant Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW475 14|", 1)); Proxy.DoCommand(container.AddCouponToCart(cartId, "RTRNC15P")); var commandResult = Proxy.DoCommand( container.SetCartFulfillment( cartId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var totals = commandResult.Models.OfType <Totals>().First(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount); commandResult = Proxy.DoCommand( container.AddFederatedPayment( cartId, paymentComponent)); totals = commandResult.Models.OfType <Totals>().First(); totals.Should().NotBeNull(); var order = Orders.CreateAndValidateOrder(container, cartId, context); var orderSummary = Proxy.GetValue( container.GetEntityView(order.Id, "Master", string.Empty, string.Empty)); // Show that the coupon used is part of the view when a business user looks at an order orderSummary.ChildViews.OfType <EntityView>() .First(p => p.Name == "Summary") .Properties.FirstOrDefault(p => p.Name == "CouponUsed") .Should() .NotBeNull(); order.Totals.GrandTotal.Amount.Should().Be(155.80M); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW098 04|5", 1)); Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW475 14|", 1)); Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW475 14|", 1)); var updatedCart = Proxy.GetValue(container.Carts.ByKey(cartId).Expand("Lines")); var cartLineComponent = updatedCart.Lines.FirstOrDefault(l => l.ItemId.Equals("Adventure Works Catalog|AW475 14|")); if (cartLineComponent != null) { Proxy.DoCommand(container.RemoveCartLine(cartId, cartLineComponent.Id)); } var commandResponse = Proxy.DoCommand( container.SetCartFulfillment( cartId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var totals = commandResponse.Models.OfType <Totals>().First(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount); commandResponse = Proxy.DoCommand( container.AddFederatedPayment( cartId, paymentComponent)); totals = commandResponse.Models.OfType <Totals>().First(); totals.PaymentsTotal.Amount.Should().Be(totals.GrandTotal.Amount); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Totals.GrandTotal.Amount.Should().Be(115.50M); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context, decimal quantity) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); //// subscription Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042453|56042453", quantity)); //// gift card Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042986|56042988", quantity)); //// warranty Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|7042259|57042259", quantity)); //// installation Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042558|56042558", quantity)); Proxy.DoCommand( container.SetCartFulfillment( cartId, new ElectronicFulfillmentComponent { Id = Guid.NewGuid().ToString(), FulfillmentMethod = new EntityReference { EntityTarget = "8A23234F-8163-4609-BD32-32D9DD6E32F5", Name = "Email" }, EmailAddress = "*****@*****.**", EmailContent = "this is the content of the email" })); var cart = Carts.GetCart(cartId, context); cart.Should().NotBeNull(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(cart.Totals.GrandTotal.Amount); Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Status.Should().NotBe("Problem"); order.Totals.GrandTotal.Amount.Should().Be(cart.Totals.GrandTotal.Amount); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); var commandResponse = Proxy.DoCommand( container.AddCartLine(cartId, "Adventure Works Catalog|22565422120|100", 1)); var firstLineId = commandResponse.Models.OfType <LineAdded>().FirstOrDefault()?.LineId; commandResponse = Proxy.DoCommand( container.AddCartLine(cartId, "Adventure Works Catalog|AW188 06|19", 1)); var secondLineId = commandResponse.Models.OfType <LineAdded>().FirstOrDefault()?.LineId; Proxy.DoCommand( container.SetCartLineFulfillment( cartId, firstLineId, context.Components.OfType <ElectronicFulfillmentComponent>().First())); commandResponse = Proxy.DoCommand( container.SetCartLineFulfillment( cartId, secondLineId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var totals = commandResponse.Models.OfType <Totals>().First(); totals.AdjustmentsTotal.Amount.Should().Be(0M); totals.GrandTotal.Amount.Should().Be(229M); // Add a Payment var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount - totals.PaymentsTotal.Amount); commandResponse = Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); totals = commandResponse.Models.OfType <Totals>().First(); totals.PaymentsTotal.Amount.Should().Be(229M); // Get the cart one last time before creating the order var cart = Carts.GetCart(cartId, context); cart.Version.Should().Be(5); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Status.Should().NotBe("Problem"); order.Totals.GrandTotal.Amount.Should().Be(229M); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); // Add Cart Line with Variant var commandResult = Proxy.DoCommand( container.AddCartLine(cartId, "Adventure Works Catalog|AW098 04|5", 1)); var cartLineId1 = commandResult.Models.OfType <LineAdded>().FirstOrDefault()?.LineId; // Add Cart Line without Variant commandResult = Proxy.DoCommand( container.AddCartLine(cartId, "Adventure Works Catalog|AW475 14|", 1)); var cartLineId2 = commandResult.Models.OfType <LineAdded>().FirstOrDefault()?.LineId; commandResult = Proxy.DoCommand( container.SetCartLineFulfillment( cartId, cartLineId1, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var totals = commandResult.Models.OfType <Totals>().First(); commandResult = Proxy.DoCommand( container.SetCartLineFulfillment( cartId, cartLineId2, context.Components.OfType <PhysicalFulfillmentComponent>().First())); totals = commandResult.Models.OfType <Totals>().First(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount - totals.PaymentsTotal.Amount); Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Totals.GrandTotal.Amount.Should().Be(180.40M); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context, decimal quantity) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|7042259|57042259", quantity)); var result = Proxy.DoCommand( container.SetCartFulfillment( cartId, new ElectronicFulfillmentComponent { FulfillmentMethod = new EntityReference { EntityTarget = "8A23234F-8163-4609-BD32-32D9DD6E32F5", Name = "Email" }, EmailAddress = "*****@*****.**", EmailContent = "this is the content of the email" })); var totals = result.Models.OfType <Sitecore.Commerce.Plugin.Carts.Totals>().FirstOrDefault(); totals.Should().NotBeNull(); totals?.GrandTotal.Should().NotBeNull(); totals?.GrandTotal.Amount.Should().NotBe(0); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount); result = Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); totals = result.Models.OfType <Sitecore.Commerce.Plugin.Carts.Totals>().FirstOrDefault(); totals.Should().NotBeNull(); totals?.GrandTotal.Should().NotBeNull(); totals?.GrandTotal.Amount.Should().NotBe(0); totals?.PaymentsTotal.Should().NotBeNull(); totals?.PaymentsTotal.Amount.Should().NotBe(0); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Status.Should().NotBe("Problem"); order.Totals.GrandTotal.Amount.Should().Be(totals.GrandTotal.Amount); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); //Habitat NextCube-V Game Cube 1TB var gameSystemLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042432|56042432", 1)); //Habitat NextCube Now 6 month On-Demand multi game Subscription var subscriptionLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042456|56042456", 1)); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, gameSystemLine.Models.OfType <LineAdded>().FirstOrDefault().LineId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, subscriptionLine.Models.OfType <LineAdded>().FirstOrDefault().LineId, context.Components.OfType <ElectronicFulfillmentComponent>().First())); var cart = Carts.GetCart(cartId, context); cart.Should().NotBeNull(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = cart.Totals.GrandTotal; Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Status.Should().NotBe("Problem"); order.Totals.GrandTotal.Amount.Should().Be(cart.Totals.GrandTotal.Amount); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); // Habitat Republic 32GB 4G LTE var phoneLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042323|56042324", 1)); // Habitat Shark Waterproof smart-phone Case var caseLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042360|56042360", 1)); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, phoneLine.Models.OfType <LineAdded>().FirstOrDefault().LineId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, caseLine.Models.OfType <LineAdded>().FirstOrDefault().LineId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var cart = Carts.GetCart(cartId, context); cart.Should().NotBeNull(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = cart.Totals.GrandTotal; Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Status.Should().NotBe("Problem"); order.Totals.GrandTotal.Amount.Should().Be(cart.Totals.GrandTotal.Amount); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); //Optix 18.0MP DSLR Camera with 18-55mm Lens var phoneLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|7042074|57042074", 1)); //Habitat Gift Wrapping (Style1) var gwLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042989|56042989", 1)); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, phoneLine.Models.OfType <LineAdded>().FirstOrDefault().LineId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, gwLine.Models.OfType <LineAdded>().FirstOrDefault().LineId, context.Components.OfType <ElectronicFulfillmentComponent>().First())); var cart = Carts.GetCart(cartId, context); cart.Should().NotBeNull(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = cart.Totals.GrandTotal; Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Status.Should().NotBe("Problem"); order.Totals.GrandTotal.Amount.Should().Be(cart.Totals.GrandTotal.Amount); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|22565422120|100", 1)); Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|22565422120|050", 1)); Proxy.DoCommand( container.SetCartFulfillment( cartId, new ElectronicFulfillmentComponent { Id = Guid.NewGuid().ToString(), FulfillmentMethod = new EntityReference { EntityTarget = "8A23234F-8163-4609-BD32-32D9DD6E32F5", Name = "Email" }, EmailAddress = "*****@*****.**", EmailContent = "this is the content of the email" })); // Add a Payment var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(150); Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Status.Should().NotBe("Problem"); order.Totals.GrandTotal.Amount.Should().Be(150.00000M); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW029 03|54", 1)); Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW029 03|64", 2)); Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW032 01|37", 3)); // Add Cart Level Physical Fulfillment var commandResponse = Proxy.DoCommand( container.SetCartFulfillment( cartId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var totals = commandResponse.Models.OfType <Totals>().First(); totals.AdjustmentsTotal.Amount.Should().Be(13.50M); totals.GrandTotal.Amount.Should().Be(148.50M); // Add a Payment var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount - totals.PaymentsTotal.Amount); commandResponse = Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); totals = commandResponse.Models.OfType <Totals>().First(); totals.PaymentsTotal.Amount.Should().Be(148.5M); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Status.Should().NotBe("Problem"); order.Totals.GrandTotal.Amount.Should().Be(148.50M); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); // making sure the pre-orderable item have a pre-order date in the future EngineExtensions.EditInventoryInformation( "Adventure Works Inventory", "AW074 04|9".ToEntityId <SellableItem>(), new List <ViewProperty> { new ViewProperty { Name = "Quantity", Value = "0", OriginalType = typeof(int).FullName }, new ViewProperty { Name = "Preorderable", Value = "true", OriginalType = typeof(bool).FullName }, new ViewProperty { Name = "PreorderAvailabilityDate", Value = DateTimeOffset.UtcNow.AddMonths(1).ToString(), OriginalType = typeof(DateTimeOffset).FullName }, new ViewProperty { Name = "PreorderLimit", Value = 10.ToString(), OriginalType = typeof(int).FullName } }); //Add Cart Line without Variant Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW475 14|", 1)); //Add a back-ordered item Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW210 12|4", 1)); //Add a pre-ordered item Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW074 04|9", 1)); var commandResult = Proxy.DoCommand( container.SetCartFulfillment( cartId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var totals = commandResult.Models.OfType <Totals>().First(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount); commandResult = Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); totals = commandResult.Models.OfType <Totals>().First(); totals.PaymentsTotal.Amount.Should().Be(totals.GrandTotal.Amount); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Totals.GrandTotal.Amount.Should().Be(433.40M); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); //Add Cart Line with Variant var commandResult = Proxy.DoCommand( container.AddCartLine(cartId, "Adventure Works Catalog|AW098 04|5", 1)); var cartLineId = commandResult.Models.OfType <LineAdded>().FirstOrDefault()?.LineId; //Add Cart Line without Variant Proxy.DoCommand(container.AddCartLine(cartId, "Adventure Works Catalog|AW475 14|", 1)); //Show adding an invalid coupon Proxy.DoCommand(container.AddCouponToCart(cartId, "InvalidCouponCode")); ConsoleExtensions.WriteExpectedError(); // Add a valid coupon, remove it and add again Proxy.DoCommand(container.AddCouponToCart(cartId, "RTRNC10P")); var cart = Carts.GetCart(cartId, context); cart.Components.OfType <CartCouponsComponent>().FirstOrDefault().Should().NotBeNull(); Proxy.DoCommand(container.RemoveCouponFromCart(cartId, "RTRNC10P")); cart = Carts.GetCart(cartId, context); cart.Components.OfType <CartCouponsComponent>().FirstOrDefault().Should().BeNull(); Proxy.DoCommand(container.AddCouponToCart(cartId, "RTRNC10P")); Proxy.DoCommand(container.RemoveCartLine(cartId, "BadLineId")); ConsoleExtensions.WriteExpectedError(); Proxy.DoCommand(container.UpdateCartLine(cartId, cartLineId, 10)); commandResult = Proxy.DoCommand( container.SetCartFulfillment( cartId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var totals = commandResult.Models.OfType <Totals>().First(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = Money.CreateMoney(totals.GrandTotal.Amount); Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Totals.GrandTotal.Amount.Should().Be(1109.00M); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }
public static string Run(ShopperContext context) { using (new SampleBuyScenarioScope()) { try { var container = context.ShopsContainer(); var cartId = Carts.GenerateCartId(); //Fridge - var fridgeLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042567|56042568", 1)); //Microwave var microwaveLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042757|56042758", 1)); //3-year warranty var warrantyLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|7042259|57042259", 1)); //HealthTracker var healthTrackerLine = Proxy.DoCommand(container.AddCartLine(cartId, "Habitat_Master|6042886|56042887", 1)); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, fridgeLine.Models.OfType <LineAdded>().FirstOrDefault().LineId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var microwaveLineAdded = microwaveLine.Models.OfType <LineAdded>().FirstOrDefault(); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, microwaveLineAdded.LineId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, warrantyLine.Models.OfType <LineAdded>().FirstOrDefault().LineId, context.Components.OfType <ElectronicFulfillmentComponent>().First())); Proxy.DoCommand( container.SetCartLineFulfillment( cartId, healthTrackerLine.Models.OfType <LineAdded>().FirstOrDefault().LineId, context.Components.OfType <PhysicalFulfillmentComponent>().First())); var cart = Carts.GetCart(cartId, context); cart.Should().NotBeNull(); var paymentComponent = context.Components.OfType <FederatedPaymentComponent>().First(); paymentComponent.Amount = cart.Totals.GrandTotal; Proxy.DoCommand(container.AddFederatedPayment(cartId, paymentComponent)); var order = Orders.CreateAndValidateOrder(container, cartId, context); order.Status.Should().NotBe("Problem"); order.Totals.GrandTotal.Amount.Should().Be(cart.Totals.GrandTotal.Amount); return(order.Id); } catch (Exception ex) { ConsoleExtensions.WriteColoredLine( ConsoleColor.Red, $"Exception in Scenario {ScenarioName} (${ex.Message}) : Stack={ex.StackTrace}"); return(null); } } }