/// <summary> /// Gets the product pre-orderable information. /// </summary> /// <param name="shopName">The shop name.</param> /// <param name="productIds">The product ids.</param> /// <param name="visitorId">The visitor id.</param> /// <param name="location">The warehouse location.</param> /// <returns>The products pre-orderable information.</returns> public List <OrderableInformation> GetPreOrderableInformation(string shopName, IEnumerable <string> productIds, string visitorId, string location) { var request = new GetPreOrderableInformationRequest(shopName, productIds.Select(pid => new InventoryProduct { ProductId = pid }).ToList()) { VisitorId = visitorId, Location = location }; GetPreOrderableInformationResult result = this._serviceProvider.GetPreOrderableInformation(request); var orderableInfos = new List <OrderableInformation>(); if (result == null) { return(orderableInfos); } foreach (var orderableInfo in productIds.Select(id => (result.OrderableInformation.FirstOrDefault(i => i.Product.ProductId.Equals(id, System.StringComparison.OrdinalIgnoreCase)) ?? new OrderableInformation { Product = new InventoryProduct { ProductId = id } })).Where(orderableInfo => !orderableInfos.Contains(orderableInfo))) { orderableInfos.Add(orderableInfo); } return(orderableInfos); }
public void ShouldNotAddNewRecordsIfProductPreOrderableInformationIsNotFound() { // Arrange var request = new GetPreOrderableInformationRequest("shopname", new List <InventoryProduct> { new InventoryProduct { ProductId = "noExist" } }); var result = new GetPreOrderableInformationResult(); var args = new ServicePipelineArgs(request, result); var results = new OrderableInformationModel[1]; results[0] = null; this._client.GetPreOrderableInformationList("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); }
public void ShouldGetPreOrderableInformationForTheSpecifiedProducts() { // Arrange var request = new GetPreOrderableInformationRequest("shopname", new List <InventoryProduct> { new InventoryProduct { ProductId = "pid1" } }); var result = new GetPreOrderableInformationResult(); var args = new ServicePipelineArgs(request, result); this._client.GetPreOrderableInformationList("shopname", Arg.Is <string[]>(ids => (ids.Length == 1) && (ids[0] == "pid1")), new System.Guid()) .Returns(new[] { new OrderableInformationModel { ProductId = "pid1", Status = NopCommerce.NopInventoryService.StockStatus.InStock } }); // Act this._processor.Process(args); // Assert result.OrderableInformation.Should().HaveCount(1); result.OrderableInformation.ElementAt(0).Product.ProductId.Should().Be("pid1"); result.OrderableInformation.ElementAt(0).Status.Should().Be(1); }