예제 #1
0
        public void TestGetProductAttributeType()
        {
            var expected = new ProductAttributeType {
                Id = 1
            };

            this._fakePersistenceManager.Setup(
                pm => pm.Find(It.IsAny <PersistenceSearcher <ProductAttributeType> >()))
            .Returns(expected);

            var actual = this._target.GetProductAttributeType("something");

            Assert.AreEqual(expected, actual);
        }
예제 #2
0
        public void TestGetGetUniqueProductAttributes()
        {
            var fakeCategory = new ProductCategory();

            var fakeAttributeType = new ProductAttributeType();

            var fakeAttribute1 = new ProductAttribute
            {
                AttributeType = fakeAttributeType,
                Value         = "Hello"
            };

            var fakeAttribute2 = new ProductAttribute
            {
                AttributeType = fakeAttributeType,
                Value         = "hello"
            };

            var fakeAttribute3 = new ProductAttribute
            {
                AttributeType = fakeAttributeType,
                Value         = "0"
            };

            var fakeAttribute4 = new ProductAttribute
            {
                AttributeType = fakeAttributeType,
                Value         = "0"
            };

            this._fakePersistenceManager.Setup(
                pm => pm.Find(It.IsAny <PersistenceCollectionSearcher <ProductAttribute> >()))
            .Returns(new List <ProductAttribute>
            {
                fakeAttribute1,
                fakeAttribute2,
                fakeAttribute3,
                fakeAttribute4
            });

            var actual = this._target.GetUniqueProductAttributes(fakeCategory, fakeAttributeType);

            Assert.IsTrue(actual.Count() == 2);
        }
예제 #3
0
        /// <summary>
        /// Helper to convert enum to a valid string sent/received in from the API
        /// <returns>String</returns>
        /// </summary>
        public static String ProductAttributeTypeToString(ProductAttributeType value)
        {
            switch (value)
            {
            case ProductAttributeType.Checkbox: return("checkbox");

            case ProductAttributeType.Radio: return("radio");

            case ProductAttributeType.Text: return("text");

            case ProductAttributeType.Select: return("select");

            case ProductAttributeType.Memo: return("memo");

            case ProductAttributeType.Template: return("template");

            case ProductAttributeType.SwatchSelect: return("swatch-select");
            }
            return("");
        }
예제 #4
0
        /// <summary>
        /// Build a new <see cref="ProductAttributeType"/> and save it.
        /// </summary>
        /// <param name="name">The name of the new <see cref="ProductAttributeType"/>.</param>
        /// <param name="displayName">A human readable value of the <paramref name="name"/>.</param>
        /// <param name="validationRegularExpression">A regular expression to validate the value of a <see cref="ProductAttribute"/>.</param>
        /// <returns>The new <see cref="ProductAttributeType"/>.</returns>
        public ProductAttributeType CreateAttributeType(string name, string displayName, string validationRegularExpression)
        {
            if (
                this._persistence.Find(
                    new PersistenceSearcher<ProductAttributeType>(
                        pat => pat.Name.ToLower() == name.ToLower()))
                != null)
            {
                throw new InvalidOperationException(
                    string.Format("A Product Attribute type with the name [{0}] already exists.", name));
            }

            try
            {
                var match = Regex.Match(string.Empty, validationRegularExpression);
            }
            catch (ArgumentException invalidRegexException)
            {
                throw new ArgumentException(
                    string.Format(
                    CultureInfo.CurrentCulture,
                    "The regular expression [{0}] to validate the product attribute type [{1}] is not a valid regular expression.",
                    validationRegularExpression,
                    name),
                    invalidRegexException);
            }

            var productAttributeType = new ProductAttributeType
                                       {
                                           DisplayName = displayName,
                                           Name = name,
                                           ValidationRegularExpression = validationRegularExpression
                                       };

            this._persistence.Add(productAttributeType);

            this._persistence.Commit();

            return productAttributeType;
        }
예제 #5
0
        /// <summary>
        /// Build a new <see cref="ProductAttributeType"/> and save it.
        /// </summary>
        /// <param name="name">The name of the new <see cref="ProductAttributeType"/>.</param>
        /// <param name="displayName">A human readable value of the <paramref name="name"/>.</param>
        /// <param name="validationRegularExpression">A regular expression to validate the value of a <see cref="ProductAttribute"/>.</param>
        /// <returns>The new <see cref="ProductAttributeType"/>.</returns>
        public ProductAttributeType CreateAttributeType(string name, string displayName, string validationRegularExpression)
        {
            if (
                this._persistence.Find(
                    new PersistenceSearcher <ProductAttributeType>(
                        pat => pat.Name.ToLower() == name.ToLower()))
                != null)
            {
                throw new InvalidOperationException(
                          string.Format("A Product Attribute type with the name [{0}] already exists.", name));
            }

            try
            {
                var match = Regex.Match(string.Empty, validationRegularExpression);
            }
            catch (ArgumentException invalidRegexException)
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              "The regular expression [{0}] to validate the product attribute type [{1}] is not a valid regular expression.",
                              validationRegularExpression,
                              name),
                          invalidRegexException);
            }

            var productAttributeType = new ProductAttributeType
            {
                DisplayName = displayName,
                Name        = name,
                ValidationRegularExpression = validationRegularExpression
            };

            this._persistence.Add(productAttributeType);

            this._persistence.Commit();

            return(productAttributeType);
        }
예제 #6
0
        public void TestGetAllProductAttributeTypes()
        {
            var attributeType1 = new ProductAttributeType {
                Id = 1
            };
            var attributeType2 = new ProductAttributeType {
                Id = 2
            };
            var attributeType3 = new ProductAttributeType {
                Id = 3
            };

            var expected = new List <ProductAttributeType> {
                attributeType1, attributeType2, attributeType3
            };

            this._fakePersistenceManager.Setup(
                pm => pm.Find(It.Is <PersistenceCollectionSearcher <ProductAttributeType> >(pcs => pcs.Predicate == null)))
            .Returns(expected);

            var actual = this._target.GetProductAttributeTypes();

            Assert.AreEqual(expected, actual);
        }
예제 #7
0
        public void TestGetRelatedProductsWithCategory()
        {
            var attributeType1 = new ProductAttributeType {
                Id = 1
            };
            var attributeType2 = new ProductAttributeType {
                Id = 2
            };
            var attributeType3 = new ProductAttributeType {
                Id = 3
            };

            var category1 = new ProductCategory {
                Id = 1
            };
            var category2 = new ProductCategory {
                Id = 2
            };

            const string attributeValue1 = "TestValue1";
            const string attributeValue2 = "TestValue2";

            var product1 = new Product
            {
                Category = category1,
                ProductSpecifications =
                    new Collection <ProductSpecification>
                {
                    new ProductSpecification
                    {
                        ActiveFrom        = DateTime.Now.AddDays(-3),
                        ActiveUntil       = DateTime.Now.AddDays(+3),
                        ProductAttributes = new Collection <ProductAttribute>
                        {
                            new ProductAttribute
                            {
                                AttributeType = attributeType1,
                                Value         = attributeValue1
                            },
                            new ProductAttribute
                            {
                                AttributeType = attributeType3,
                                Value         = "No one cares"
                            }
                        }
                    }
                }
            };

            var product2 = new Product
            {
                Category = category2,
                ProductSpecifications =
                    new Collection <ProductSpecification>
                {
                    new ProductSpecification
                    {
                        ActiveFrom        = DateTime.Now.AddDays(-3),
                        ActiveUntil       = DateTime.Now.AddDays(+3),
                        ProductAttributes = new Collection <ProductAttribute>
                        {
                            new ProductAttribute
                            {
                                AttributeType = attributeType1,
                                Value         = attributeValue1
                            },
                            new ProductAttribute
                            {
                                AttributeType = attributeType2,
                                Value         = attributeValue2
                            },
                            new ProductAttribute
                            {
                                AttributeType = attributeType3,
                                Value         = "No one cares"
                            }
                        }
                    }
                }
            };

            var product3 = new Product
            {
                Category = category1,
                ProductSpecifications =
                    new Collection <ProductSpecification>
                {
                    new ProductSpecification
                    {
                        ActiveFrom        = DateTime.Now.AddDays(-3),
                        ActiveUntil       = DateTime.Now.AddDays(+3),
                        ProductAttributes = new Collection <ProductAttribute>
                        {
                            new ProductAttribute
                            {
                                AttributeType = attributeType1,
                                Value         = attributeValue1
                            },
                            new ProductAttribute
                            {
                                AttributeType = attributeType2,
                                Value         = attributeValue2
                            },
                            new ProductAttribute
                            {
                                AttributeType = attributeType3,
                                Value         = "No one cares"
                            }
                        }
                    }
                }
            };

            this._fakePersistenceManager
            .Setup(p => p.Find(It.IsAny <IPersistenceCollectionSearcher <Product> >()))
            .Returns(new List <Product> {
                product1, product2, product3
            });

            var actual =
                this._target.GetRelatedProducts(
                    category2,
                    new ProductAttribute {
                AttributeType = attributeType1, Value = attributeValue1
            },
                    new ProductAttribute {
                AttributeType = attributeType2, Value = attributeValue2
            });

            Assert.IsTrue(actual.Count() == 1);
            Assert.AreEqual(product2, actual.FirstOrDefault());
        }
예제 #8
0
        /// <summary>
        /// Retrieve all the distinct <see cref="ProductAttribute"/>s for a <see cref="ProductCategory"/> and
        /// <see cref="ProductAttributeType"/> based on their value.
        /// </summary>
        /// <param name="category">The <see cref="ProductCategory"/> to find the unique attributes for.</param>
        /// <param name="attributeType">The <see cref="ProductAttributeType"/> to find the unique attributes for.</param>
        /// <returns>A collection of distinct <see cref="ProductAttribute"/>s.</returns>
        public IEnumerable <ProductAttribute> GetUniqueProductAttributes(ProductCategory category, ProductAttributeType attributeType)
        {
            var attibutes = this._persistence.Find(
                new PersistenceCollectionSearcher <ProductAttribute>(
                    pa => pa.AttributeType.Id == attributeType.Id &&
                    pa.ProductSpecification.Category.Id == category.Id))
                            .DistinctBy(pa => pa.Value.ToLower());

            return(attibutes);
        }
예제 #9
0
        /// <summary>
        /// Retrieve all the distinct <see cref="ProductAttribute"/>s for a <see cref="ProductCategory"/> and
        /// <see cref="ProductAttributeType"/> based on their value.
        /// </summary>
        /// <param name="category">The <see cref="ProductCategory"/> to find the unique attributes for.</param>
        /// <param name="attributeType">The <see cref="ProductAttributeType"/> to find the unique attributes for.</param>
        /// <returns>A collection of distinct <see cref="ProductAttribute"/>s.</returns>
        public IEnumerable<ProductAttribute> GetUniqueProductAttributes(ProductCategory category, ProductAttributeType attributeType)
        {
            var attibutes = this._persistence.Find(
                new PersistenceCollectionSearcher<ProductAttribute>(
                    pa => pa.AttributeType.Id == attributeType.Id &&
                          pa.ProductSpecification.Category.Id == category.Id))
                .DistinctBy(pa => pa.Value.ToLower());

            return attibutes;
        }
예제 #10
0
        public void TestGetRelatedProductsWithCategory()
        {
            var attributeType1 = new ProductAttributeType { Id = 1 };
            var attributeType2 = new ProductAttributeType { Id = 2 };
            var attributeType3 = new ProductAttributeType { Id = 3 };

            var category1 = new ProductCategory { Id = 1 };
            var category2 = new ProductCategory { Id = 2 };

            const string attributeValue1 = "TestValue1";
            const string attributeValue2 = "TestValue2";

            var product1 = new Product
            {
                Category = category1,
                ProductSpecifications =
                    new Collection<ProductSpecification>
                                   {
                                       new ProductSpecification
                                       {
                                           ActiveFrom = DateTime.Now.AddDays(-3),
                                           ActiveUntil = DateTime.Now.AddDays(+3),
                                           ProductAttributes = new Collection<ProductAttribute>
                                                {
                                                   new ProductAttribute
                                                   {
                                                       AttributeType = attributeType1,
                                                       Value = attributeValue1
                                                   },
                                                   new ProductAttribute
                                                   {
                                                       AttributeType = attributeType3,
                                                       Value = "No one cares"
                                                   }
                                               }
                                       }
                                   }
            };

            var product2 = new Product
            {
                Category = category2,
                ProductSpecifications =
                    new Collection<ProductSpecification>
                                   {
                                       new ProductSpecification
                                       {
                                           ActiveFrom = DateTime.Now.AddDays(-3),
                                           ActiveUntil = DateTime.Now.AddDays(+3),
                                           ProductAttributes = new Collection<ProductAttribute>
                                                {
                                                   new ProductAttribute
                                                   {
                                                       AttributeType = attributeType1,
                                                       Value = attributeValue1
                                                   },
                                                   new ProductAttribute
                                                   {
                                                       AttributeType = attributeType2,
                                                       Value = attributeValue2
                                                   },
                                                   new ProductAttribute
                                                   {
                                                       AttributeType = attributeType3,
                                                       Value = "No one cares"
                                                   }
                                               }
                                       }
                                   }
            };

            var product3 = new Product
            {
                Category = category1,
                ProductSpecifications =
                    new Collection<ProductSpecification>
                                   {
                                       new ProductSpecification
                                       {
                                           ActiveFrom = DateTime.Now.AddDays(-3),
                                           ActiveUntil = DateTime.Now.AddDays(+3),
                                           ProductAttributes = new Collection<ProductAttribute>
                                                {
                                                   new ProductAttribute
                                                   {
                                                       AttributeType = attributeType1,
                                                       Value = attributeValue1
                                                   },
                                                   new ProductAttribute
                                                   {
                                                       AttributeType = attributeType2,
                                                       Value = attributeValue2
                                                   },
                                                   new ProductAttribute
                                                   {
                                                       AttributeType = attributeType3,
                                                       Value = "No one cares"
                                                   }
                                               }
                                       }
                                   }
            };

            this._fakePersistenceManager
                .Setup(p => p.Find(It.IsAny<IPersistenceCollectionSearcher<Product>>()))
                .Returns(new List<Product> { product1, product2, product3 });

            var actual =
                this._target.GetRelatedProducts(
                    category2,
                    new ProductAttribute { AttributeType = attributeType1, Value = attributeValue1 },
                    new ProductAttribute { AttributeType = attributeType2, Value = attributeValue2 });

            Assert.IsTrue(actual.Count() == 1);
            Assert.AreEqual(product2, actual.FirstOrDefault());
        }
예제 #11
0
        public void TestGetProductAttributeTypeById()
        {
            const int expectedId = 1;

            var expected = new ProductAttributeType { Id = expectedId };

            this._fakePersistenceManager.Setup(
                pm => pm.Find(It.IsAny<PersistenceSearcher<ProductAttributeType>>()))
                .Returns(expected);

            var actual = this._target.GetProductAttributeType(expectedId);

            Assert.AreEqual(expected, actual);
        }
예제 #12
0
        public void TestGetGetUniqueProductAttributes()
        {
            var fakeCategory = new ProductCategory();

            var fakeAttributeType = new ProductAttributeType();

            var fakeAttribute1 = new ProductAttribute
            {
                AttributeType = fakeAttributeType,
                Value = "Hello"
            };

            var fakeAttribute2 = new ProductAttribute
            {
                AttributeType = fakeAttributeType,
                Value = "hello"
            };

            var fakeAttribute3 = new ProductAttribute
            {
                AttributeType = fakeAttributeType,
                Value = "0"
            };

            var fakeAttribute4 = new ProductAttribute
            {
                AttributeType = fakeAttributeType,
                Value = "0"
            };

            this._fakePersistenceManager.Setup(
                pm => pm.Find(It.IsAny<PersistenceCollectionSearcher<ProductAttribute>>()))
                .Returns(new List<ProductAttribute>
                {
                    fakeAttribute1,
                    fakeAttribute2,
                    fakeAttribute3,
                    fakeAttribute4
                });

            var actual = this._target.GetUniqueProductAttributes(fakeCategory, fakeAttributeType);

            Assert.IsTrue(actual.Count() == 2);
        }
예제 #13
0
        public void TestGetAllProductAttributeTypes()
        {
            var attributeType1 = new ProductAttributeType { Id = 1 };
            var attributeType2 = new ProductAttributeType { Id = 2 };
            var attributeType3 = new ProductAttributeType { Id = 3 };

            var expected = new List<ProductAttributeType> { attributeType1, attributeType2, attributeType3 };

            this._fakePersistenceManager.Setup(
                pm => pm.Find(It.Is<PersistenceCollectionSearcher<ProductAttributeType>>(pcs => pcs.Predicate == null)))
                .Returns(expected);

            var actual = this._target.GetProductAttributeTypes();

            Assert.AreEqual(expected, actual);
        }