コード例 #1
0
        public void WHEN_empty_value_SHOULD_return_no_specification_attribute()
        {
            // Arrange
            var product = new Overture.ServiceModel.Products.Product
            {
                PropertyBag = new PropertyBag {
                    { "attr1", "" }
                },
                Variants = new List <Variant>
                {
                    new Variant
                    {
                        Id          = VariantId,
                        PropertyBag = new PropertyBag()
                    }
                }
            };

            var productDefinition = BuildProductDefinitionWithOneAttribute("attr 1", "attr1", PropertyDataType.Text);

            var productSpecificationsViewService = _container.CreateInstance <ProductSpecificationsViewService>();

            // Act
            var specificationViewModel = productSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
            {
                Product           = product,
                ProductDefinition = productDefinition,
            });

            // Assert
            specificationViewModel.Groups.Should().BeEmpty();
        }
コード例 #2
0
        public void WHEN_excluded_property_SHOULD_return_no_property()
        {
            // Arrange
            var product = new Overture.ServiceModel.Products.Product
            {
                PropertyBag = new PropertyBag
                {
                    { "ProductDefinition", "test1" }, //Excluded Property
                },
                Variants = new List <Variant>
                {
                    new Variant
                    {
                        Id          = VariantId,
                        PropertyBag = new PropertyBag()
                    }
                }
            };

            var productDefinition = BuildProductDefinitionWithOneAttribute("attr 1", "ProductDefinition", PropertyDataType.Text);

            productDefinition.PropertyGroups.First().Name = "GroupTest";

            var productSpecificationsViewService = _container.CreateInstance <ProductSpecificationsViewService>();

            // Act
            var specificationViewModel = productSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
            {
                Product           = product,
                ProductDefinition = productDefinition,
            });

            // Assert
            specificationViewModel.Groups.Should().BeEmpty();
        }
コード例 #3
0
        public void WHEN_empty_propertybag_SHOULD_return_null()
        {
            // Arrange
            var product = new Overture.ServiceModel.Products.Product
            {
                PropertyBag = new PropertyBag(),
                Variants    = new List <Variant>
                {
                    new Variant
                    {
                        Id          = VariantId,
                        PropertyBag = new PropertyBag()
                    }
                }
            };

            var productDefinition = BuildProductDefinitionWithEachAttributeTypes();

            var productSpecificationsViewService = _container.CreateInstance <ProductSpecificationsViewService>();

            // Act
            var specificationViewModel = productSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
            {
                Product           = product,
                ProductDefinition = productDefinition,
                VariantId         = VariantId
            });

            // Assert
            specificationViewModel.Should().BeNull();
        }
コード例 #4
0
        public void WHEN_variant_id_is_null_SHOULD_not_throw_ArgumentException()
        {
            // Arrange
            var product = new Overture.ServiceModel.Products.Product
            {
                PropertyBag = new PropertyBag(),
                Variants    = new List <Variant>()
            };

            var productDefinition = BuildProductDefinitionWithEachAttributeTypes();

            SetupProductRepository(product, productDefinition);

            var productSpecificationsViewService = _container.CreateInstance <ProductSpecificationsViewService>();

            // Assert
            Assert.DoesNotThrow(() => productSpecificationsViewService.GetProductSpecificationsViewModel(
                                    new GetProductSpecificationsParam
            {
                Product           = product,
                ProductDefinition = productDefinition,
                VariantId         = null
            }
                                    ));
        }
        private static Mock <IProductRepository> CreateProductRepositoryWithNulls()
        {
            Mock <IProductRepository> productRepositoryMock = new Mock <IProductRepository>(MockBehavior.Strict);

            Overture.ServiceModel.Products.Product product = new Overture.ServiceModel.Products.Product();
            product.Variants    = null; //A product without variants will eventually contain a null list
            product.Description = null; //A product without description will eventuall contain a null description

            product.Active                  = null;
            product.CatalogId               = null;
            product.DefinitionName          = null;
            product.Description             = null;
            product.DisplayName             = null;
            product.LastPublishedDate       = null;
            product.ListPrice               = null;
            product.NewProductDate          = null;
            product.Prices                  = null;
            product.PrimaryParentCategoryId = null;
            product.Relationships           = null;
            product.SequenceNumber          = null;
            product.Sku         = null;
            product.TaxCategory = null;
            product.Variants    = null;


            productRepositoryMock.Setup(
                repo => repo.GetProductAsync(It.IsAny <GetProductParam>()))
            .ReturnsAsync(product)
            .Verifiable();

            return(productRepositoryMock);
        }
コード例 #6
0
        private void SetupProductRepository(Overture.ServiceModel.Products.Product product, ProductDefinition definition)
        {
            var productRepository = new Mock <IProductRepository>();

            productRepository.Setup(r => r.GetProductAsync(It.Is <GetProductParam>(param => param.ProductId == ProductId))).ReturnsAsync(product);
            productRepository.Setup(r => r.GetProductDefinitionAsync(It.Is <GetProductDefinitionParam>(param => param.Name == product.DefinitionName))).ReturnsAsync(definition);

            _container.Use(productRepository);
        }
コード例 #7
0
 /// <summary>
 /// Initializes specifications for a given variant.
 /// </summary>
 /// <param name="productId">ID of the product.</param>
 /// <param name="productImages">Available product images.</param>
 /// <param name="cultureInfo">Culture info.</param>
 /// <param name="variantViewModel">ViewModel to be impacted.</param>
 protected virtual void InitializeVariantSpecificaton(
     Overture.ServiceModel.Products.Product product,
     ProductDefinition productDefinition,
     VariantViewModel variantViewModel)
 {
     variantViewModel.Specifications = ProductSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
     {
         VariantId         = variantViewModel.Id,
         Product           = product,
         ProductDefinition = productDefinition
     });
 }
        private static Mock <IProductRepository> CreateProductRepositoryWithLookups()
        {
            Mock <IProductRepository> productRepositoryMock = new Mock <IProductRepository>(MockBehavior.Strict);
            var product = new Overture.ServiceModel.Products.Product
            {
                PropertyBag = new PropertyBag {
                    { "Lookup1", "LookupValue1" }, { "Size", "Small|Medium" }
                }
            };

            productRepositoryMock.Setup(repo => repo.GetProductAsync(It.IsAny <GetProductParam>()))
            .ReturnsAsync(product)
            .Verifiable();

            productRepositoryMock.Setup(repo => repo.GetProductDefinitionAsync(It.IsAny <GetProductDefinitionParam>()))
            .ReturnsAsync(new ProductDefinition
            {
                PropertyGroups = new List <ProductPropertyDefinitionGroup>
                {
                    new ProductPropertyDefinitionGroup {
                        Properties = new List <ProductPropertyDefinition>
                        {
                            new ProductPropertyDefinition
                            {
                                PropertyName     = "Lookup1",
                                DataType         = PropertyDataType.Lookup,
                                LookupDefinition = new ProductLookupDefinition
                                {
                                    LookupName = "Lookup1Lookup"
                                }
                            },
                            new ProductPropertyDefinition
                            {
                                PropertyName     = "Size",
                                DataType         = PropertyDataType.Lookup,
                                LookupDefinition = new ProductLookupDefinition
                                {
                                    LookupName = "SizeLookup"
                                }
                            }
                        }
                    }
                }
            })
            .Verifiable();

            return(productRepositoryMock);
        }
コード例 #9
0
        public void WHEN_variant_not_found_SHOULD_return_product_specifications()
        {
            // Arrange
            var product = new Overture.ServiceModel.Products.Product
            {
                PropertyBag = new PropertyBag
                {
                    { "attrText", "test1" }
                },
                Variants = new List <Variant>
                {
                    new Variant
                    {
                        Id          = VariantId,
                        PropertyBag = new PropertyBag
                        {
                            { "attrText", "test2" }
                        }
                    }
                }
            };
            var productDefinition = BuildProductDefinitionWithEachAttributeTypes();

            var productSpecificationsViewService = _container.CreateInstance <ProductSpecificationsViewService>();

            // Act
            var specificationViewModel = productSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
            {
                Product           = product,
                ProductDefinition = productDefinition,
                VariantId         = "invalid"
            });

            // Assert
            specificationViewModel.Should().NotBeNull();
            specificationViewModel.Groups.Should().NotBeEmpty();

            var group = specificationViewModel.Groups.First();

            group.Title.ShouldBeEquivalentTo("group 1");

            var textAttribute = group.Attributes.Find(x => x.Title == "attr Text");

            textAttribute.Should().NotBeNull();
            textAttribute.Value.ShouldBeEquivalentTo("test1");
        }
コード例 #10
0
        protected virtual decimal?GetCurrentPrice(IEnumerable <ProductPrice> prices, Overture.ServiceModel.Products.Product product, Variant variant)
        {
            // there may be multiple copies of the product if this is a variant, just take the first
            var price = prices.FirstOrDefault(p => p.ProductId == product.Id);

            if (price == null)
            {
                return(null);
            }

            if (variant == null)
            {
                return(price.Pricing.Price);
            }

            var variantPrice = price.VariantPrices.SingleOrDefault(vp => vp.VariantId == variant.Id);

            return(variantPrice == null ? null : (decimal?)variantPrice.Pricing.Price);
        }
コード例 #11
0
        /// <summary>
        /// Get the product images associate with a productId and a variantId
        /// </summary>
        /// <param name="product"></param>
        /// <param name="variants"></param>
        /// <returns></returns>
        protected virtual async Task <List <AllProductImages> > GetProductImages(
            Overture.ServiceModel.Products.Product product,
            IList <Variant> variants)
        {
            var param = new GetAllProductImagesParam
            {
                ImageSize             = ProductConfiguration.ImageSize,
                ThumbnailImageSize    = ProductConfiguration.ThumbnailImageSize,
                ProductZoomImageSize  = ProductConfiguration.ProductZoomImageSize,
                ProductId             = product.Id,
                PropertyBag           = product.PropertyBag,
                ProductDefinitionName = product.DefinitionName,
                Variants        = variants == null ? new List <Variant>() : variants.ToList(),
                MediaSet        = product.MediaSet,
                VariantMediaSet = product.VariantMediaSet
            };

            return(await DamProvider.GetAllProductImagesAsync(param).ConfigureAwait(false));
        }
コード例 #12
0
        public void WHEN_propertybag_with_multiple_value_lookup_attribute_SHOULD_return_correct_specification()
        {
            // Arrange
            var propertyName = GetRandom.String(32);
            var lookupName   = GetRandom.String(32);

            var product = new Overture.ServiceModel.Products.Product
            {
                PropertyBag = new PropertyBag {
                    { propertyName, "test1|test2" }
                },
                Variants = new List <Variant>
                {
                    new Variant
                    {
                        Id          = VariantId,
                        PropertyBag = new PropertyBag()
                    }
                }
            };

            var productDefinition = BuildProductDefinitionForLookupWithOneAttribute("attr Lookup", propertyName, lookupName);

            var productSpecificationsViewService = _container.CreateInstance <ProductSpecificationsViewService>();

            // Act
            var specificationViewModel = productSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
            {
                Product           = product,
                ProductDefinition = productDefinition,
            });

            // Assert
            var group     = specificationViewModel.Groups.First();
            var attribute = group.Attributes.First();

            attribute.Title.ShouldBeEquivalentTo("attr Lookup");
            attribute.Value.ShouldBeEquivalentTo("test 1, test 2");
            attribute.PropertyName.ShouldBeEquivalentTo(propertyName);
        }
コード例 #13
0
        public void SHOULD_return_specification_with_custom_formatting()
        {
            // Arrange
            var product = new Overture.ServiceModel.Products.Product
            {
                PropertyBag = new PropertyBag {
                    { "attrWithCustomResource", "test1" }
                },
                Variants = new List <Variant>
                {
                    new Variant
                    {
                        Id          = VariantId,
                        PropertyBag = new PropertyBag()
                    }
                }
            };

            var productDefinition = BuildProductDefinitionWithOneAttribute("attr WithCustomResource", "attrWithCustomResource", PropertyDataType.Text);

            var productSpecificationsViewService = _container.CreateInstance <ProductSpecificationsViewService>();

            // Act
            var specificationViewModel = productSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
            {
                Product           = product,
                ProductDefinition = productDefinition,
            });

            // Assert
            var group     = specificationViewModel.Groups.First();
            var attribute = group.Attributes.First();

            attribute.Title.ShouldBeEquivalentTo("attr WithCustomResource");
            attribute.Value.ShouldBeEquivalentTo("test1 customText");
            attribute.PropertyName.ShouldBeEquivalentTo("attrWithCustomResource");
        }
コード例 #14
0
        public void WHEN_propertybag_with_all_basic_attribute_types_SHOULD_return_correct_specification()
        {
            // Arrange
            var datetimeNow = DateTime.Now;
            var product     = new Overture.ServiceModel.Products.Product
            {
                PropertyBag = new PropertyBag
                {
                    { "attrText", "test1" },
                    { "attrBoolean", true },
                    { "attrCurrency", 10.5 },
                    { "attrDatetime", datetimeNow },
                    { "attrDecimal", 10.5 },
                    { "attrNumber", 10 },
                },
                Variants = new List <Variant>
                {
                    new Variant
                    {
                        Id          = VariantId,
                        PropertyBag = new PropertyBag()
                    }
                }
            };
            var productDefinition = BuildProductDefinitionWithEachAttributeTypes();

            var productSpecificationsViewService = _container.CreateInstance <ProductSpecificationsViewService>();

            // Act
            var specificationViewModel = productSpecificationsViewService.GetProductSpecificationsViewModel(new GetProductSpecificationsParam
            {
                Product           = product,
                ProductDefinition = productDefinition,
            });

            // Assert
            specificationViewModel.Should().NotBeNull();
            specificationViewModel.Groups.Should().NotBeEmpty();
            var group = specificationViewModel.Groups.First();

            group.Title.ShouldBeEquivalentTo("group 1");

            var textAttribute = group.Attributes.Find(x => x.Title == "attr Text");

            textAttribute.Should().NotBeNull();
            textAttribute.Value.ShouldBeEquivalentTo("test1");

            var booleanAttribute = group.Attributes.Find(x => x.Title == "attr Boolean");

            booleanAttribute.Should().NotBeNull();
            booleanAttribute.Value.ShouldBeEquivalentTo("True");

            var currencyAttribute = group.Attributes.Find(x => x.Title == "attr Currency");

            currencyAttribute.Should().NotBeNull();
            currencyAttribute.Value.ShouldBeEquivalentTo(string.Format("{0}", 10.5));

            var datetimeAttribute = group.Attributes.Find(x => x.Title == "attr Datetime");

            datetimeAttribute.Should().NotBeNull();
            datetimeAttribute.Value.ShouldBeEquivalentTo(datetimeNow.ToShortDateString());

            var decimalAttribute = group.Attributes.Find(x => x.Title == "attr Decimal");

            decimalAttribute.Should().NotBeNull();
            decimalAttribute.Value.ShouldBeEquivalentTo(string.Format("{0}", 10.5));

            var numberAttribute = group.Attributes.Find(x => x.Title == "attr Number");

            numberAttribute.Should().NotBeNull();
            numberAttribute.Value.ShouldBeEquivalentTo("10");
        }
コード例 #15
0
        protected virtual async Task <ProductViewModel> SetViewModelRecurringOrdersRelatedProperties(GetProductParam param, ProductViewModel vm, Overture.ServiceModel.Products.Product product)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (vm == null)
            {
                throw new ArgumentNullException(nameof(vm));
            }

            var recurringOrdersEnabled = RecurringOrdersSettings.Enabled;

            var recurringOrderProgramName = product.PropertyBag.GetValueOrDefault <string>(Constants.ProductAttributes.RecurringOrderProgramName);

            if (string.IsNullOrWhiteSpace(recurringOrderProgramName))
            {
                return(vm);
            }

            vm.RecurringOrderProgramName            = recurringOrderProgramName;
            vm.Context["RecurringOrderProgramName"] = recurringOrderProgramName;

            var program = await RecurringOrdersRepository.GetRecurringOrderProgram(param.Scope, recurringOrderProgramName).ConfigureAwait(false);

            if (program == null)
            {
                return(vm);
            }

            vm.IsRecurringOrderEligible            = recurringOrdersEnabled;
            vm.Context["IsRecurringOrderEligible"] = recurringOrdersEnabled;

            if (recurringOrdersEnabled)
            {
                var recurringOrderProgramViewModel = RecurringOrderProgramViewModelFactory.CreateRecurringOrderProgramViewModel(program, param.CultureInfo);

                vm.RecurringOrderFrequencies            = recurringOrderProgramViewModel.Frequencies;
                vm.Context["RecurringOrderFrequencies"] = recurringOrderProgramViewModel.Frequencies;
            }

            return(vm);
        }
コード例 #16
0
        protected virtual IEnumerable <ProductIdentifier> ExtractRelatedProductIdentifiers(Overture.ServiceModel.Products.Product product, string[] merchandiseTypes, int maxItems)
        {
            if (product == null || product.Relationships == null)
            {
                return(Enumerable.Empty <ProductIdentifier>());
            }

            var relatedProducts = product.Relationships
                                  .Where(r => r.RelationshipType == RelationshipType.Product ||
                                         r.RelationshipType == RelationshipType.Variant);

            var relatedProductIdentifiers = relatedProducts
                                            .Where(r => merchandiseTypes.Contains(r.MerchandiseType))
                                            .OrderBy(r => r.SequenceNumber)
                                            .Take(maxItems)
                                            .Select(r => new ProductIdentifier
            {
                // if the product is a variant, it's VariantProductId will be set to the product ID,
                // otherwise it's EntityId is the correct product id
                ProductId = r.VariantProductId ?? r.EntityId,
                VariantId = r.RelationshipType == RelationshipType.Variant ? r.EntityId : null
            });

            return(relatedProductIdentifiers);
        }
コード例 #17
0
        private static Overture.ServiceModel.Products.Product GenerateProductWithKva()
        {
            /*
             *
             * Product Variant Values.
             * _____________________________________
             |    Color       Size    Type       |
             |___________________________________|
             |    Red         Small       A      |
             |    Blue        Small       B      |
             |    White       Medium      C      |
             |___________________________________|
             |
             |
             | Assuming that thoses are KVA, they should be transformed into 3 lists:
             |
             | 1: Red, Blue, White.
             | 2: Smal, Medium.
             | 3: A, B, C.
             |
             */

            var variantOne = new Variant();

            variantOne.Id          = "VariantOne";
            variantOne.Active      = true;
            variantOne.PropertyBag = new PropertyBag();
            variantOne.PropertyBag.Add("Size", "Small");
            variantOne.PropertyBag.Add("Colour", "Red");
            variantOne.PropertyBag.Add("Type", "A");
            variantOne.PropertyBag.Add("Lookup1", "LookupValue3");

            var variantTwo = new Variant();

            variantTwo.Id          = "VariantTwo";
            variantTwo.Active      = true;
            variantTwo.PropertyBag = new PropertyBag();
            variantTwo.PropertyBag.Add("Size", "Small");
            variantTwo.PropertyBag.Add("Colour", "Blue");
            variantTwo.PropertyBag.Add("Type", "B");
            variantTwo.PropertyBag.Add("Lookup1", "LookupValue2");

            var variantThree = new Variant();

            variantThree.Id          = "variantThree";
            variantThree.Active      = false;
            variantThree.PropertyBag = new PropertyBag();
            variantThree.PropertyBag.Add("Size", "Medium");
            variantThree.PropertyBag.Add("Colour", "White");
            variantThree.PropertyBag.Add("Type", "C");
            variantThree.PropertyBag.Add("Lookup1", "LookupValue1");

            var product = new Overture.ServiceModel.Products.Product();

            product.Variants = new List <Variant>();
            product.Variants.Add(variantOne);
            product.Variants.Add(variantTwo);
            product.Variants.Add(variantThree);

            return(product);
        }
コード例 #18
0
        private static Mock <IProductRepository> CreateProductRepository(CultureInfo culture, Overture.ServiceModel.Products.Product product)
        {
            Mock <IProductRepository> productRepositoryMock = new Mock <IProductRepository>();

            productRepositoryMock.Setup(
                repo => repo.GetProductAsync(It.Is <GetProductParam>(param => param.CultureInfo.Name == culture.Name)))
            .ReturnsAsync(product)
            .Verifiable();

            productRepositoryMock.Setup(
                repo => repo.GetProductDefinitionAsync(It.Is <GetProductDefinitionParam>(param => param.Name == null && param.CultureInfo.Name == culture.Name)))
            .ReturnsAsync(GenerateProductDefinitionWithKva())
            .Verifiable();

            return(productRepositoryMock);
        }