public virtual ProductResourceModel GetProductDownloads(string externalProductId) { int productId; if (!int.TryParse(externalProductId, out productId)) { return(new ProductResourceModel()); } var productVariant = this.productService.GetProductById(productId); if (productVariant == null || !productVariant.IsDownload) { return(new ProductResourceModel()); } var download = this.downloadService.GetDownloadById(productVariant.DownloadId); var productResourceModel = new ProductResourceModel { ProductId = externalProductId, ProductResourceType = "Download", Resources = new List <ResourceModel>() }; var resourceModel = new ResourceModel { Url = download.DownloadUrl, ResourceType = "Download", Id = download.Id.ToString(CultureInfo.InvariantCulture), Name = download.UseDownloadUrl ? download.DownloadGuid.ToString() : download.Filename }; productResourceModel.Resources.Add(resourceModel); return(productResourceModel); }
public void ShouldAppendNewProductRelationsToExisting() { // arrange this.args.Request.Properties["ProductResources"] = new List <ProductResource> { new ProductResource { Name = "Resource_1" } }; var productResourceModel = new ProductResourceModel { Resources = new[] { new ResourceModel { Name = "Resource_2" } } }; this.client.GetProductAlternateImages("100500").Returns(productResourceModel); // act this.processor.Process(this.args); // assert var resources = (IEnumerable <ProductResource>) this.args.Request.Properties["ProductResources"]; resources.Count().Should().Be(2); resources.ElementAt(0).Name.Should().Be("Resource_1"); resources.ElementAt(1).Name.Should().Be("Resource_2"); }
public void ShouldFillResultWithProductResourcesDataIfItIsNotNull() { // arrange var firstDate = DateTime.Now; var secondDate = DateTime.Now; var resourceModels = new[] { new ResourceModel { Id = "157", CreatedOnUtc = firstDate, UpdatedOnUtc = firstDate, ResourceType = "main image 1", Url = "http://main_image_1", Name = "first" }, new ResourceModel { Id = "33", CreatedOnUtc = secondDate, UpdatedOnUtc = secondDate, ResourceType = "main image 2", Url = "http://main_image_2", Name = "second" }, }; var productResourceModel = new ProductResourceModel { Resources = resourceModels }; this.client.GetProductMainImage("100500").Returns(productResourceModel); // act this.processor.Process(this.args); // assert var result = (IEnumerable <ProductResource>) this.args.Request.Properties["ProductResources"]; result.Count().Should().Be(2); var firstResource = result.ElementAt(0); firstResource.Created.Should().Be(firstDate); firstResource.Updated.Should().Be(firstDate); firstResource.ExternalId.Should().Be("157"); firstResource.Type.Should().Be("main image 1"); firstResource.Uri.Should().Be("http://main_image_1"); firstResource.Name.Should().Be("first"); var secondResource = result.ElementAt(1); secondResource.Created.Should().Be(secondDate); secondResource.Updated.Should().Be(secondDate); secondResource.ExternalId.Should().Be("33"); secondResource.Type.Should().Be("main image 2"); secondResource.Uri.Should().Be("http://main_image_2"); secondResource.Name.Should().Be("second"); }
public void ShouldNotFillResultWithProductResourcesDataIfItIsNull() { // arrange ProductResourceModel productResourceModel = null; this.client.GetProductMainImage("100500").Returns(productResourceModel); // act this.processor.Process(this.args); // assert this.args.Request.Properties["ProductResources"].Should().BeNull(); }
public virtual ProductResourceModel GetProductAlternateImages(string externalProductId) { int productId; if (!int.TryParse(externalProductId, out productId)) { return(new ProductResourceModel()); } var product = this.productService.GetProductById(productId); if (product == null) { return(new ProductResourceModel()); } var productResourceModel = new ProductResourceModel { ProductId = externalProductId, ProductResourceType = "Alt image", Resources = new List <ResourceModel>() }; var mainProductPictureId = GetMainImageIdByProduct(product); if (mainProductPictureId == 0 || mainProductPictureId >= int.MaxValue || mainProductPictureId <= int.MinValue) { return(productResourceModel); } var pictureIds = GetAlternateImagesByProductVariantAndMainImageId(product, mainProductPictureId); foreach (var picture in pictureIds.Select(pictureId => this.pictureService.GetPictureById(pictureId))) { productResourceModel.Resources.Add(new ResourceModel { Url = this.pictureService.GetPictureUrl(picture.Id), Name = picture.SeoFilename, ResourceType = "Alt image", Id = picture.Id.ToString(CultureInfo.InvariantCulture) }); } return(productResourceModel); }