public void ImportProductService_ImportProducts_ShouldCallImportUrlHistoryOfImportProductUrlHistoryService() { var productDTO = new ProductImportDataTransferObject { UrlSegment = "test-url", UrlHistory = new List <string> { "test-url-old" } }; var product = new Product { Name = "Test Product" }; A.CallTo(() => _documentService.GetDocumentByUrl <Product>(productDTO.UrlSegment)).Returns(product); _importProductsService.ImportProduct(productDTO); A.CallTo(() => _importProductUrlHistoryService.ImportUrlHistory(productDTO, product)).MustHaveHappened(); }
/// <summary> /// Import from DTOs /// </summary> /// <param name="dataTransferObject"></param> public Product ImportProduct(ProductImportDataTransferObject dataTransferObject) { var uniquePage = _uniquePageService.GetUniquePage <ProductContainer>(); var productGalleriesCategory = _documentService.GetDocumentByUrl <MediaCategory>("product-galleries"); if (productGalleriesCategory == null) { productGalleriesCategory = new MediaCategory { Name = "Product Galleries", UrlSegment = "product-galleries", IsGallery = true, HideInAdminNav = true }; _documentService.AddDocument(productGalleriesCategory); } Product product = _session.Query <Product>() .SingleOrDefault(x => x.UrlSegment == dataTransferObject.UrlSegment) ?? new Product(); product.Parent = uniquePage; product.UrlSegment = dataTransferObject.UrlSegment; product.Name = dataTransferObject.Name; product.BodyContent = dataTransferObject.Description; product.MetaTitle = dataTransferObject.SEOTitle; product.MetaDescription = dataTransferObject.SEODescription; product.MetaKeywords = dataTransferObject.SEOKeywords; product.ProductAbstract = dataTransferObject.Abstract; product.PublishOn = dataTransferObject.PublishDate; bool isNew = false; MediaCategory productGallery = product.Gallery ?? new MediaCategory(); if (product.Id == 0) { isNew = true; product.DisplayOrder = GetParentQuery(uniquePage).Any() ? GetParentQuery(uniquePage) .Select(Projections.Max <Webpage>(webpage => webpage.DisplayOrder)) .SingleOrDefault <int>() : 0; productGallery.Name = product.Name; productGallery.UrlSegment = "product-galleries/" + product.UrlSegment; productGallery.IsGallery = true; productGallery.Parent = productGalleriesCategory; productGallery.HideInAdminNav = true; product.Gallery = productGallery; } SetBrand(dataTransferObject, product); SetCategories(dataTransferObject, product); SetOptions(dataTransferObject, product); ////Url History _importUrlHistoryService.ImportUrlHistory(dataTransferObject, product); ////Specifications _importSpecificationsService.ImportSpecifications(dataTransferObject, product); ////Variants _importProductVariantsService.ImportVariants(dataTransferObject, product); if (isNew) { _session.Transact(session => session.Save(product)); _session.Transact(session => session.Save(productGallery)); } else { _session.Transact(session => session.Update(product)); _session.Transact(session => session.Update(productGallery)); } _importProductImagesService.ImportProductImages(dataTransferObject.Images, product.Gallery); return(product); }