/// <summary> /// Adds a line-item to the shopping cart. /// </summary> /// <param name="container">The service container.</param> /// <param name="cartId">The id of the shopping cart.</param> /// <param name="itemId">The id of the sellable item.</param> /// <param name="quantity">The quantity being added.</param> /// <param name="expands">The expands options.</param> /// <returns>The <see cref="DataServiceActionQuerySingle{AddCartLineCommand}"/> query.</returns> public static DataServiceActionQuerySingle <AddCartLineCommand> AddCartLine(this Engine.Container container, string cartId, string itemId, decimal quantity, string expands) { return(new DataServiceActionQuerySingle <AddCartLineCommand>(container, container.BaseUri.OriginalString.Trim('/') + $"/AddCartLine?$expand={expands}", new BodyOperationParameter("cartId", cartId), new BodyOperationParameter("itemId", itemId), new BodyOperationParameter("quantity", quantity))); }
private static void WriteListCounts(Engine.Container container) { var backupColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("---------------------------------------------------"); var rmasMetadata = container.GetListMetadata("Rmas").GetValue(); Console.WriteLine($"List:{rmasMetadata.ListName} Count:{rmasMetadata.Count}"); var pendingRmasMetadata = container.GetListMetadata("PendingRmas").GetValue(); Console.WriteLine($"List:{pendingRmasMetadata.ListName} Count:{pendingRmasMetadata.Count}"); var refundPendingRmasMetadata = container.GetListMetadata("RefundPendingRmas").GetValue(); Console.WriteLine($"List:{refundPendingRmasMetadata.ListName} Count:{refundPendingRmasMetadata.Count}"); var completedRmasMetadata = container.GetListMetadata("CompletedRmas").GetValue(); Console.WriteLine($"List:{completedRmasMetadata.ListName} Count:{completedRmasMetadata.Count}"); var problemRmasMetadata = container.GetListMetadata("ProblemRmas").GetValue(); Console.WriteLine($"List:{problemRmasMetadata.ListName} Count:{problemRmasMetadata.Count}"); Console.WriteLine("---------------------------------------------------"); Console.ForegroundColor = backupColor; }
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.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse(); var rma = GetRma(container, rmaFriendlyId); rma.Status.Should().Be("RefundPending"); rma.ItemsReturnedDate.Should().BeCloseTo(DateTimeOffset.UtcNow, 2000); 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, 2000); WriteListCounts(container); }
public static void RunRefundRmasMinion(Engine.Container container, string rmaId, string environmentName = "AdventureWorksMinions") { EngineExtensions.RunMinionWithRetry( "Sitecore.Commerce.Plugin.Returns.RefundRmasMinion, Sitecore.Commerce.Plugin.Returns", environmentName); var rma = GetRma(container, rmaId); rma.Status.Should().Be("Completed"); }
private static ReturnMerchandiseAuthorization GetRma(Engine.Container container, string rmaFriendlyId) { var result = Proxy.GetValue(container.ReturnMerchandiseAuthorizations.ByKey(rmaFriendlyId).Expand("Lines($expand=ChildComponents),Components")); result.Should().NotBeNull(); result.Status.Should().NotBeNullOrEmpty(); result.Lines.Should().NotBeEmpty(); result.Order.EntityTarget.Should().NotBeNullOrEmpty(); result.ReturnReason.Should().NotBeNullOrEmpty(); var result2 = Proxy.GetValue(container.ReturnMerchandiseAuthorizations.ByKey($"Entity-ReturnMerchandiseAuthorization-{rmaFriendlyId}").Expand("Lines($expand=ChildComponents),Components")); result2.Should().NotBeNull(); return(result); }
public static void RunRefundRmasMinion(Engine.Container container, string rmaFriendlyId, string environmentName = "AdventureWorksMinions") { Console.WriteLine("Begin RunRefundRmasMinion"); var policies = new Collection <CommerceOps.Sitecore.Commerce.Core.Policy> { new CommerceOps.Sitecore.Commerce.Core.RunMinionPolicy { RunChildren = false } }; var result = Proxy.GetValue( new MinionRunner().Context.MinionsContainer() .RunMinion("Sitecore.Commerce.Plugin.Returns.RefundRmasMinion, Sitecore.Commerce.Plugin.Returns", environmentName, policies)); result.Should().NotBeNull(); result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse(); WriteListCounts(container); var rma = GetRma(container, rmaFriendlyId); rma.Status.Should().Be("Completed"); }
/// <summary> /// Removes a line-item from the shopping cart. /// </summary> /// <param name="container">The service container</param> /// <param name="cartId">The cart Id</param> /// <param name="cartLineId">The cart line-item Id</param> /// <param name="expands">The expands options</param> /// <returns>The <see cref="DataServiceActionQuerySingle{RemoveCartLineCommand}" /> query</returns> public static DataServiceActionQuerySingle <RemoveCartLineCommand> RemoveCartLine(this Engine.Container container, string cartId, string cartLineId, string expands) { return(new DataServiceActionQuerySingle <RemoveCartLineCommand>(container, container.BaseUri.OriginalString.Trim('/') + $"/RemoveCartLine?$expand={expands}", new BodyOperationParameter("cartId", cartId), new BodyOperationParameter("cartLineId", cartLineId))); }
/// <summary> /// Gets the customer by its user name. /// </summary> /// <param name="container">The service container.</param> /// <param name="userName">The user name.</param> /// <param name="expands">The expands options.</param> /// <returns></returns> public static DataServiceActionQuerySingle <Customer> GetCustomer(this Engine.Container container, string userName, string expands) { return(new DataServiceActionQuerySingle <Customer>(container, container.BaseUri.OriginalString.Trim('/') + $"/GetCustomer?$expand={expands}", new BodyOperationParameter("userName", userName))); }
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); }