public override void Process(ServicePipelineArgs args) { UpdateCartLinesRequest request; CartResult result; CheckParametersAndSetupRequestAndResult(args, out request, out result); using (new DisposableThreadLifestyleScope()) { if (IsFromUcommerce(request)) { return; } if (!result.Success) { return; } var basket = _basketService.GetBasketByCartExternalId(request.Cart.ExternalId); var existingOrderLines = basket.PurchaseOrder.OrderLines; var query = from updatedOrderLine in request.Lines join originalOrderLine in existingOrderLines on updatedOrderLine.ExternalCartLineId equals originalOrderLine.OrderLineId.ToString() select new { updatedOrderLine, originalOrderLine }; foreach (var line in query.ToList()) { var updatedOrderLine = MappingLibrary.MapCartLineToOrderLine(line.updatedOrderLine); UpdateOrderLine(updatedOrderLine, line.originalOrderLine); } } }
/// <summary> /// Initializes a new instance of the <see cref="SaveCartTest"/> class. /// </summary> public SaveCartTest() { this.cart = new Cart { Lines = new ReadOnlyCollection <CartLine>(new List <CartLine> { new CartLine { Product = new CartProduct { ProductId = "Audi S4" }, Quantity = 5 }, }) }; this.request = new SaveCartRequest(this.cart); this.result = new CartResult(); this.args = new ServicePipelineArgs(this.request, this.result); this.client = Substitute.For <ICartsServiceChannel>(); var clientFactory = Substitute.For <ServiceClientFactory>(); clientFactory.CreateClient <ICartsServiceChannel>(Arg.Any <string>(), Arg.Any <string>()).Returns(this.client); this.processor = new SaveCart { ClientFactory = clientFactory }; }
public void ShouldNotAddNewRecordsIfProductBackOrderableInformationIsNotFound() { // Arrange var request = new GetBackOrderableInformationRequest("shopname", new List <InventoryProduct> { new InventoryProduct { ProductId = "noExist" } }); var result = new GetBackOrderableInformationResult(); var args = new ServicePipelineArgs(request, result); var results = new OrderableInformationModel[1]; results[0] = null; this._client.GetBackOrderableInformationList("shopname", Arg.Is <string[]>(ids => (ids.Length == 1) && (ids[1] == "noExist")), new System.Guid()).Returns(results); // Act this._processor.Process(args); // Assert result.OrderableInformation.Should().HaveCount(1); result.OrderableInformation.ElementAt(0).Product.ProductId.Should().Be("noExist"); result.OrderableInformation.ElementAt(0).Status.Should().Be(null); result.OrderableInformation.ElementAt(0).InStockDate.Should().Be(null); result.OrderableInformation.ElementAt(0).OrderableEndDate.Should().Be(null); result.OrderableInformation.ElementAt(0).OrderableStartDate.Should().Be(null); result.OrderableInformation.ElementAt(0).RemainingQuantity.Should().Be(0); result.OrderableInformation.ElementAt(0).ShippingDate.Should().Be(null); result.OrderableInformation.ElementAt(0).CartQuantityLimit.Should().Be(0); }
/// <summary> /// Processes the specified args. /// </summary> /// <param name="args">The args.</param> public override void Process(ServicePipelineArgs args) { var request = (GetBackInStockInformationRequest)args.Request; var result = (GetBackInStockInformationResult)args.Result; StockInformationUpdateModel[] stockInformationUpdateModels; using (IInventoryServiceChannel client = this.GetClient()) { stockInformationUpdateModels = client.GetBackInStocksInformation( request.Shop.Name, request.Products.Select(p => p.ProductId).ToArray()); } var stockInformationUpdateList = new List <StockInformationUpdate>(); foreach (var model in stockInformationUpdateModels) { var entity = this.EntityFactory.Create <StockInformationUpdate>("StockInformationUpdate"); this.PopulateStockInformationUpdate(entity, model); stockInformationUpdateList.Add(entity); } result.StockInformationUpdates = stockInformationUpdateList; }
/// <summary> /// Sets the data from saved product. /// </summary> /// <param name="args">The arguments.</param> /// <param name="product">The product.</param> protected override void SetDataFromSavedProduct(ServicePipelineArgs args, Product product) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(product, "product"); args.Request.Properties["ClassificationGroups"] = product.ClassificationGroups; }
/// <summary> /// Processes the arguments. /// </summary> /// <param name="args">The pipeline arguments.</param> public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var request = (UpdateWishListLinesRequest)args.Request; var result = (UpdateWishListLinesResult)args.Result; var updatedLines = new List <WishListLine>(); using (var client = this.GetClient()) { var wishlistId = new Guid(request.WishList.ExternalId); foreach (WishListLine line in request.Lines) { if (client.UpdateQuantity(wishlistId, line.Product.ProductId, int.Parse(line.Quantity.ToString())) != null) { updatedLines.Add(line); } } ShoppingCartModel wishlistModel = client.GetWishlist(wishlistId); var wishlist = new WishList { ExternalId = request.WishList.ExternalId }; wishlist.MapWishlistFromModel(wishlistModel); result.WishList = wishlist; result.UpdatedLines = new ReadOnlyCollection <WishListLine>(updatedLines); } }
/// <summary> /// Processes the specified args. /// </summary> /// <param name="args">The args.</param> public override void Process(ServicePipelineArgs args) { var request = (GetProductPricesRequest)args.Request; var result = (GetProductPricesResult)args.Result; var currencyCode = request.CurrencyCode; if (string.IsNullOrEmpty(currencyCode)) { currencyCode = "USD"; } using (var client = this.GetClient()) { if (request.PriceTypeIds.Any()) { foreach (var priceType in request.PriceTypeIds) { result.Prices.Add(priceType, this.GetProductPrice(client, request.ProductId, priceType, currencyCode)); } } else { result.Prices.Add(ListPriceType, this.GetProductPrice(client, request.ProductId, ListPriceType, currencyCode)); } } }
/// <summary> /// Processes the arguments. /// </summary> /// <param name="args">The pipeline arguments.</param> public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var request = (RemoveWishListLinesRequest)args.Request; var result = (RemoveWishListLinesResult)args.Result; var removedLines = new List <WishListLine>(); using (var client = this.GetClient()) { var wishlistId = new Guid(request.WishList.ExternalId); foreach (string lineId in request.LineIds) { WishListLine line = request.WishList.Lines.FirstOrDefault(p => p.ExternalId == lineId); if (line != null) { client.RemoveProduct(wishlistId, line.Product.ProductId); removedLines.Add(line); } } ShoppingCartModel wishlistModel = client.GetWishlist(wishlistId); var wishlist = new WishList { ExternalId = request.WishList.ExternalId }; wishlist.MapWishlistFromModel(wishlistModel); result.WishList = wishlist; result.RemovedLines = new ReadOnlyCollection <WishListLine>(removedLines); } }
public void ShouldGetStockInformationOnlyStatusForTheSpecifiedProducts() { // Arrange var request = new GetStockInformationRequest("shopname", new List <InventoryProduct> { new InventoryProduct { ProductId = "pid1" } }); var result = new GetStockInformationResult(); var args = new ServicePipelineArgs(request, result); this._client.GetStocksInformation("shopname", Arg.Is <string[]>(ids => (ids.Length == 1) && (ids[0] == "pid1")), new System.Guid()) .Returns(new[] { new StockInformationModel { ProductId = "pid1", Status = NopCommerce.NopInventoryService.StockStatus.InStock } }); // Act this._processor.Process(args); // Assert result.StockInformation.Should().HaveCount(1); result.StockInformation.ElementAt(0).Product.ProductId.Should().Be("pid1"); result.StockInformation.ElementAt(0).Status.Should().Be(1); result.StockInformation.ElementAt(0).Count.Should().Be(0); result.StockInformation.ElementAt(0).AvailabilityDate.Should().Be(null); }
/// <summary> /// Processes the specified args. /// </summary> /// <param name="args">The args.</param> public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var result = (GetShippingOptionsResult)args.Result; result.ShippingOptions = new ReadOnlyCollection <ShippingOption>(this.ShippingOptionList.Values.ToList()); }
/// <summary> /// Gets the product data from service. /// </summary> /// <param name="args">The arguments</param> protected override void GetProductDataFromService(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var request = (ProductSynchronizationRequest)args.Request; using (var nopServiceClient = this.GetClient()) { var productGlobalSpecificationModels = nopServiceClient.GetProductGlobalSpecifications(request.ProductId); if (productGlobalSpecificationModels == null) { return; } args.Request.Properties["ProductSpecifications"] = productGlobalSpecificationModels .Select(sm => { var specification = this.InstantiateEntity <Specification>(); specification.ExternalId = sm.SpecificationLookupId; specification.Key = sm.SpecificationLookupName; specification.Value = sm.LookupValueName; return(specification); }).ToList(); nopServiceClient.Close(); } }
public void ShouldRemovePaymentInfoFromCart() { var guid = Guid.NewGuid(); var request = new RemovePaymentInfoRequest( new Cart() { ExternalId = guid.ToString(), ShopName = "my store" }, new List<PaymentInfo>() { new PaymentInfo() { PaymentProviderID = "Payments.PurchaseOrder", PaymentMethodID = "Purchase Order" } }); var result = new RemovePaymentInfoResult(); var args = new ServicePipelineArgs(request, result); _client.RemovePaymentInfo(guid, Arg.Any<PaymentInfoModel>(), request.Cart.ShopName) .Returns(new PaymentInfoModelResponse { Success = true }); _processor.Process(args); result.Success.Should().BeTrue(); result.Payments.Should().HaveCount(0); result.Cart.Payment.Should().HaveCount(0); }
public override void Process(ServicePipelineArgs args) { if (this.visitorContext.CurrentUser?.Email != null) { return; } var cart = this.GetCartFromArgs(args); if (cart?.Total == null) { return; } this.contactManager.SetEmail(EmailKey, cart.Email); var personalInfo = this.GetPersonalInfo(cart); if (personalInfo == null) { return; } this.contactManager.SetPersonalInfo(personalInfo); }
public void ShouldAddPartiesToCartById() { var cartId = Guid.NewGuid(); var request = new AddPartiesRequest( new Cart { ExternalId = cartId.ToString(), Name = "Vasya" }, new List <Party> { new Party { Address1 = "my address 1", Address2 = "my address 2", FirstName = "Koly", LastName = "Ivanov" }, new Party() }); var result = new AddPartiesResult(); var args = new ServicePipelineArgs(request, result); _client.AddAddresses(Arg.Any <CustomerAddressModel[]>(), Arg.Any <Guid>()) .Returns(new Response() { Success = true, Message = "Success" }); _processor.Process(args); result.Success.Should().BeTrue(); }
public void ShouldCallServiceWithCorrectArgs() { var cartId = Guid.NewGuid(); var request = new AddPartiesRequest( new Cart { ExternalId = cartId.ToString(), BuyerCustomerParty = new CartParty() { ExternalId = "1" } }, // only one party to add new List <Party> { new Party(), new Party() } ); var result = new AddPartiesResult(); var args = new ServicePipelineArgs(request, result); _client.AddAddresses(Arg.Any <CustomerAddressModel[]>(), Arg.Any <Guid>()).Returns(new Response() { Success = true, Message = "Success" }); _processor.Process(args); // asserts // result.Success.Should().Be(true); // _client.Received().AddAddressesByExternalCustomerId(Arg.Is<CustomerAddressModel[]>(x => x.Length > 0), Arg.Is(cartId)); _client.Received().AddAddresses(Arg.Any <CustomerAddressModel[]>(), Arg.Any <Guid>()); }
/// <summary> /// Processes the arguments. /// </summary> /// <param name="args">The pipeline arguments.</param> public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var addresses = new List <AddressModel>(); Guid customerId; var request = (UpdateCustomerPartiesRequest)args.Request; var result = (CustomerPartiesResult)args.Result; using (ICustomersServiceChannel channel = this.GetClient()) { try { customerId = new Guid(request.CommerceCustomer.ExternalId); } catch { result.Success = false; result.SystemMessages.Add(new SystemMessage { Message = "Cannot parse customer Guid " + request.CommerceCustomer.ExternalId }); return; } } }
public override void Process(ServicePipelineArgs args) { ServiceProviderRequest request; PaymentClientTokenResult result; PipelineUtility.ValidateArguments <ServiceProviderRequest, PaymentClientTokenResult>(args, out request, out result); try { string commerceCustomerId = string.Empty; _accountManager = DependencyResolver.Current.GetService <IAccountManager>(); var user = this._accountManager.GetUser(Sitecore.Context.GetUserName()); commerceCustomerId = user?.Result?.ExternalId; string str = (string)Proxy.GetValue <string>(this.GetContainer(request.Shop.Name, string.Empty, commerceCustomerId, string.Empty, args.Request.CurrencyCode, new DateTime?(), "").GetClientToken()); if (str != null) { result.ClientToken = str; } else { result.Success = false; } } catch (ArgumentException ex) { result.Success = false; result.SystemMessages.Add(PipelineUtility.CreateSystemMessage((Exception)ex)); } base.Process(args); }
public void ShouldCalculateCartTotals() { // arrange var cart = new Cart { Lines = new ReadOnlyCollection <CartLine>(new List <CartLine> { new CartLine { Product = new CartProduct { Price = new Price(1050, "USD") }, Quantity = 2 }, new CartLine { Product = new CartProduct { Price = new Price(2000, "USD") }, Quantity = 1 } }) }; var processor = new GetPricesForCart(); var request = new GetCartTotalRequest { Cart = cart }; var args = new ServicePipelineArgs(request, new GetCartTotalResult()); // act processor.Process(args); // assert var resultCart = ((GetCartTotalResult)args.Result).Cart; resultCart.Total.Amount.Should().Be(4100); resultCart.Total.CurrencyCode.Should().Be("USD"); }
public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, nameof(args)); Assert.ArgumentNotNull(args.Request, nameof(args.Request)); Assert.ArgumentCondition(args.Request is GetSupportedCurrenciesRequest, nameof(args.Request), "args.Request is RefSFArgs.GetSupportedCurrenciesRequest"); Assert.ArgumentCondition(args.Result is GetSupportedCurrenciesResult, nameof(args.Result), "args.Result is GetSupportedCurrenciesResult"); var request = (GetSupportedCurrenciesRequest)args.Request; var result = (GetSupportedCurrenciesResult)args.Result; Assert.ArgumentNotNullOrEmpty(request.CatalogName, nameof(request.CatalogName)); var catalogRepository = DependencyResolver.Current.GetService <ICatalogRepository>(); var catalog = catalogRepository.GetCatalogReadOnly(request.CatalogName); var currencyList = new List <string> { catalog[CommerceConstants.KnownCatalogFieldNames.Currency].ToString() }; if (_currenciesToInject.Count > 0) { currencyList.AddRange(_currenciesToInject); } result.Currencies = new ReadOnlyCollection <string>(currencyList); }
public override void Process(ServicePipelineArgs args) { AddPartiesRequest request; AddPartiesResult result; using (new DisposableThreadLifestyleScope()) { CheckParametersAndSetupRequestAndResult(args, out request, out result); Assert.ArgumentNotNull(request.Parties, "request.Parties"); Assert.ArgumentNotNull(request.Cart, "request.Cart"); IList <Party> parties = new List <Party>(); foreach (var party in request.Parties) { var addedParty = AddPartyToCart(party, request); parties.Add(addedParty); } result.Parties = new ReadOnlyCollection <Party>(parties); var cart = UpdatedCart(request.Cart); SetAccountingCustomerPartyAndBuyerCustomerParty(cart); result.Cart = cart; } }
public override void Process(ServicePipelineArgs args) { RemovePaymentInfoRequest request; RemovePaymentInfoResult result; using (new DisposableThreadLifestyleScope()) { CheckParametersAndSetupRequestAndResult(args, out request, out result); Assert.ArgumentNotNull(request.Payments, "request.Payments"); Assert.ArgumentNotNull(request.Cart, "request.Cart"); var purchaseOrder = _basketService.GetBasketByCartExternalId(request.Cart.ExternalId).PurchaseOrder; foreach (var paymentInfo in request.Payments) { RemovePayment(purchaseOrder, paymentInfo); } PipelineFactory.Create <PurchaseOrder>("Basket").Execute(purchaseOrder); var paymentInfos = _paymentMapper.Map(purchaseOrder.Payments); result.Payments = new ReadOnlyCollection <PaymentInfo>(paymentInfos); result.Cart = _purchaseOrderMapper.Map(purchaseOrder); } }
public void ShouldGetProductPricesInCuurencyForTheSpecifiedProducts() { // Arrange GetProductBulkPricesRequest request = new GetProductBulkPricesRequest(new[] { "ProductId1", "ProductId2" }, "PriceType"); request.CurrencyCode = "CAD"; GetProductBulkPricesResult result = new GetProductBulkPricesResult(); ServicePipelineArgs args = new ServicePipelineArgs(request, result); result.Prices.Add("ProductId1", null); this.client.GetProductPrices(Arg.Is <string[]>(argument => (argument.Length == 2) && (argument[0] == "ProductId1") && (argument[1] == "ProductId2")), "PriceType").Returns(new[] { new ProductPriceModel { ProductId = "ProductId1", Price = 2 }, new ProductPriceModel { ProductId = "ProductId2", Price = 1 } }); // Act this.processor.Process(args); // Assert result.Prices.Should().HaveCount(2); result.Prices["ProductId1"].Amount.Should().Be(2); result.Prices["ProductId1"].CurrencyCode.Should().Be("CAD"); result.Prices["ProductId2"].Amount.Should().Be(1); result.Prices["ProductId2"].CurrencyCode.Should().Be("CAD"); }
public override void Process(ServicePipelineArgs args) { GetShippingMethodsRequest request; GetShippingMethodsResult result; using (new DisposableThreadLifestyleScope()) { CheckParametersAndSetupRequestAndResult(args, out request, out result); if (request.Party == null || string.IsNullOrEmpty(request.Party.Country)) { result.ShippingMethods = GetCommerceConnectShippingMethods(null); return; } var countryRepository = ObjectFactory.Instance.Resolve <IRepository <Country> >(); var country = countryRepository.Select(x => x.Name == request.Party.Country).FirstOrDefault(); if (country == null) { throw new ArgumentException(string.Format("Could not find a country with name: \"{0}\", from Party.Country", request.Party.Country)); } result.ShippingMethods = GetCommerceConnectShippingMethods(country); } }
public override void Process(ServicePipelineArgs args) { CartLinesRequest request; CartResult result; CheckParametersAndSetupRequestAndResult(args, out request, out result); using (new DisposableThreadLifestyleScope()) { Basket basket = _basketService.GetBasketByCartExternalId(request.Cart.ExternalId); if (IsFromUcommerce(request)) { result.Cart = MappingLibrary.MapPurchaseOrderToCart(basket.PurchaseOrder); return; } if (!result.Success) { return; } var basketPipeline = ObjectFactory.Instance.Resolve <IPipeline <PurchaseOrder> >("Basket"); basketPipeline.Execute(basket.PurchaseOrder); result.Cart = MappingLibrary.MapPurchaseOrderToCart(basket.PurchaseOrder); if (string.IsNullOrEmpty(result.Cart.ShopName)) { result.Cart.ShopName = Context.GetSiteName(); } } }
/// <summary> /// Performs get wishlist operation. /// </summary> /// <param name="args">The args.</param> public override void Process([NotNull] ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); // Gets id of castomer to load from NopCommerce instance. var request = (GetWishListRequest)args.Request; var result = (GetWishListResult)args.Result; // Creates instance of WCF service client. using (var client = this.GetClient()) { Guid userGuid; string userId = request.UserId; if (!Guid.TryParse(userId, out userGuid)) { var idGenerator = new Md5IdGenerator(); userGuid = Guid.Parse(idGenerator.StringToID(userId, string.Empty).ToString()); } ShoppingCartModel wishlistModel = client.GetWishlist(userGuid); if (wishlistModel == null) { return; } var wishlist = new WishList { ExternalId = request.WishListId }; wishlist.MapWishlistFromModel(wishlistModel); result.WishList = wishlist; } }
/// <summary> /// Gets the product data from service. /// </summary> /// <param name="args">The arguments.</param> protected override void GetProductDataFromService(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var request = (ProductSynchronizationRequest)args.Request; using (var nopServiceClient = this.GetClient()) { var categoryModels = nopServiceClient.GetCategories(request.ProductId); var classificationGroup = this.InstantiateEntity <ClassificationGroup>(); classificationGroup.Name = this.productClassificationGroupName; classificationGroup.ExternalId = this.productClassificationGroupExternalId; classificationGroup.Classifications = categoryModels.Select(category => { var classification = this.InstantiateEntity <Classification>(); classification.ExternalId = category.Id; return(classification); }).ToList().AsReadOnly(); args.Request.Properties["ClassificationGroups"] = new List <ClassificationGroup> { classificationGroup }; nopServiceClient.Close(); } }
/// <summary> /// Initializes a new instance of the <see cref="UpdateLinesOnWishlistTest"/> class. /// </summary> public UpdateLinesOnWishlistTest() { this.visitorId = Guid.NewGuid(); this.oldLine = new WishListLine() { ExternalId = "10", Product = new CartProduct { ProductId = "100500", Price = new Price { Amount = 100 } }, Quantity = 12 }; this.lineToUpdate = new WishListLine() { ExternalId = "10", Product = new CartProduct { ProductId = "100500", Price = new Price { Amount = 100 } }, Quantity = 2 }; this.wishlist = new WishList { ExternalId = this.visitorId.ToString(), Lines = new ReadOnlyCollection <WishListLine>(new List <WishListLine> { this.oldLine }) }; this.updatedWishlist = new WishList { ExternalId = this.visitorId.ToString(), Lines = new ReadOnlyCollection <WishListLine>(new List <WishListLine> { this.lineToUpdate }) }; this.request = new UpdateWishListLinesRequest(this.wishlist, new[] { this.lineToUpdate }); this.result = new UpdateWishListLinesResult(); this.args = new ServicePipelineArgs(this.request, this.result); this.client = Substitute.For <IWishlistsServiceChannel>(); var clientFactory = Substitute.For <ServiceClientFactory>(); clientFactory.CreateClient <IWishlistsServiceChannel>(Arg.Any <string>(), Arg.Any <string>()).Returns(this.client); this.processor = new UpdateLinesOnWishlist { ClientFactory = clientFactory }; }
/// <summary> /// Runs the processor. /// </summary> /// <param name="args">The arguments.</param> public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); using (var nopServiceClient = this.GetClient()) { var nopTypes = nopServiceClient.GetAllProductTypes(); var types = nopTypes.Select(x => { var type = this.InstantiateEntity <ProductType>(); type.ExternalId = x.Id; type.Description = x.Description; type.Name = x.Name; type.ProductTypeId = x.Id; type.ParentProductTypeId = x.ParentProductTypeId; type.Created = x.CreatedOnUtc; type.Updated = x.UpdatedOnUtc; return(type); }).ToList(); args.Request.Properties["ProductTypes"] = types; nopServiceClient.Close(); } }
/// <summary> /// Initializes a new instance of the <see cref="RemoveLinesFromCartTest"/> class. /// </summary> public RemoveLinesFromCartTest() { this.visitorId = Guid.NewGuid(); this.cart = new Cart { ExternalId = this.visitorId.ToString(), Lines = new ReadOnlyCollectionAdapter <CartLine> { new CartLine() } }; this.lineToRemove = new CartLine { Product = new CartProduct { ProductId = "100500", Price = new Price { Amount = 100 } }, Quantity = 12 }; this.request = new RemoveCartLinesRequest(this.cart, new[] { this.lineToRemove }); this.result = new CartResult(); this.args = new ServicePipelineArgs(this.request, this.result); this.client = Substitute.For <ICartsServiceChannel>(); var clientFactory = Substitute.For <ServiceClientFactory>(); clientFactory.CreateClient <ICartsServiceChannel>(Arg.Any <string>(), Arg.Any <string>()).Returns(this.client); this.processor = new RemoveLinesFromCart { ClientFactory = clientFactory }; }
public void ShouldNotAddNewRecordsIfProductStockInformationIsNotFound() { // Arrange var request = new GetStockInformationRequest("shopname", new List <InventoryProduct> { new InventoryProduct { ProductId = "noExist" } }); var result = new GetStockInformationResult(); var args = new ServicePipelineArgs(request, result); var results = new StockInformationModel[1]; results[0] = null; this._client.GetStocksInformation("shopname", Arg.Is <string[]>(ids => (ids.Length == 1) && (ids[1] == "noExist")), new System.Guid()).Returns(results); // Act this._processor.Process(args); // Assert result.StockInformation.Should().HaveCount(1); result.StockInformation.ElementAt(0).Product.ProductId.Should().Be("noExist"); result.StockInformation.ElementAt(0).Status.Should().Be(null); result.StockInformation.ElementAt(0).Count.Should().Be(0); result.StockInformation.ElementAt(0).AvailabilityDate.Should().Be(null); }
/// <summary> /// Executes the business logic of the TriggerPageEevent processor. /// </summary> /// <param name="args">The arguments.</param> public override void Process(ServicePipelineArgs args) { if (Sitecore.Context.Site.DisplayMode != DisplayMode.Normal) { return; } base.Process(args); }
public override void Process(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.Request, "args.Request"); Assert.ArgumentNotNull(args.Result, "args.Result"); Assert.IsTrue((bool)(args.Request is SubmitVisitorOrderRequest), "args.Request is SubmitVisitorOrderRequest"); Assert.IsTrue((bool)(args.Result is SubmitVisitorOrderResult), "args.Result is SubmitVisitorOrderResult"); SubmitVisitorOrderRequest request = (SubmitVisitorOrderRequest)args.Request; SubmitVisitorOrderResult result = (SubmitVisitorOrderResult)args.Result; CartPipelineContext context = CartPipelineContext.Get(request.RequestContext); Assert.IsNotNull(context, "cartContext"); if (((context.Basket != null) && !context.HasBasketErrors) && result.Success) { foreach (OrderForm orderForm in context.Basket.OrderForms) { foreach (LineItem lineItem in orderForm.LineItems) { var cartLine = request.Cart.Lines.FirstOrDefault(l => l.ExternalCartLineId.Equals(lineItem.LineItemId.ToString("B"), StringComparison.OrdinalIgnoreCase)); if (cartLine == null) { continue; } // Store the image as a string since a dictionary is not serializable and causes problems in C&OM. StringBuilder imageList = new StringBuilder(); foreach (MediaItem image in ((CustomCommerceCartLine)cartLine).Images) { if (image != null) { if (imageList.Length > 0) { imageList.Append("|"); } imageList.Append(image.ID.ToString()); imageList.Append(","); imageList.Append(image.MediaPath); } } lineItem["Images"] = imageList.ToString(); } } PurchaseOrder orderGroup = context.Basket.SaveAsOrder(); TranslateOrderGroupToEntityRequest request2 = new TranslateOrderGroupToEntityRequest(context.UserId, context.ShopName, orderGroup); TranslateOrderGroupToEntityResult result2 = PipelineUtility.RunCommerceConnectPipeline<TranslateOrderGroupToEntityRequest, TranslateOrderGroupToEntityResult>("translate.orderGroupToEntity", request2); result.Order = result2.Cart as Order; } }
/// <summary> /// Gets the page event data. /// </summary> /// <param name="args">The arguments.</param> /// <returns>The page event data.</returns> protected override Dictionary<string, object> GetPageEventData(ServicePipelineArgs args) { Assert.ArgumentNotNull(args, "args"); var data = base.GetPageEventData(args) ?? new Dictionary<string, object>(); var request = args.Request as VisitedProductDetailsPageRequest; if (request != null) { data.Add(StorefrontConstants.PageEventDataNames.ShopName, request.ShopName); data.Add(StorefrontConstants.PageEventDataNames.ProductId, request.ProductId); data.Add(StorefrontConstants.PageEventDataNames.ParentCategoryName, request.ParentCategoryName ?? string.Empty); data.Add(StorefrontConstants.PageEventDataNames.CatalogName, request.CatalogName ?? string.Empty); } return data; }