示例#1
0
        public void TestFindByColorSizeAndBelowPrice()
        {
            // Arrange
            ColorSpecification      colorSpecification      = new ColorSpecification(ProductColor.Red);
            SizeSpecification       sizeSpecification       = new SizeSpecification(ProductSize.Small);
            BelowPriceSpecification belowPriceSpecification = new BelowPriceSpecification(10.00M);

            AndSpecification firstAndSpecification  = new AndSpecification(colorSpecification, sizeSpecification);
            AndSpecification secondAndSpecification = new AndSpecification(firstAndSpecification, belowPriceSpecification);

            // Act
            ReadOnlyCollection <Product> foundProducts = this._finder.SelectBy(secondAndSpecification);

            // Assert
            Assert.AreEqual(0, foundProducts.Count, "found no small red products below $10.00");

            // Arrange
            colorSpecification      = new ColorSpecification(ProductColor.Red);
            sizeSpecification       = new SizeSpecification(ProductSize.Medium);
            belowPriceSpecification = new BelowPriceSpecification(10.00M);

            firstAndSpecification  = new AndSpecification(colorSpecification, sizeSpecification);
            secondAndSpecification = new AndSpecification(firstAndSpecification, belowPriceSpecification);

            // Act
            foundProducts = this._finder.SelectBy(secondAndSpecification);

            // Assert
            Assert.AreEqual(this._fireTruck, foundProducts[0], "found firetruck when looking for cheap medium red toys");
        }
示例#2
0
        public void TestFindBelowPriceAvoidingAColor()
        {
            // Arrange
            BelowPriceSpecification belowPriceSpecification = new BelowPriceSpecification(9.00M);
            ColorSpecification      colorSpecification      = new ColorSpecification(ProductColor.White);

            AndSpecification andSpecification = new AndSpecification(belowPriceSpecification, new NotSpecification(colorSpecification));

            // Act
            ReadOnlyCollection <Product> foundProducts = this._finder.SelectBy(andSpecification);

            // Assert
            Assert.AreEqual(1, foundProducts.Count, "found 1 non-white product < $9.00");
            Assert.IsTrue(foundProducts.Contains(this._fireTruck), "found fireTruck");

            // Arrange
            belowPriceSpecification = new BelowPriceSpecification(9.00M);
            colorSpecification      = new ColorSpecification(ProductColor.Red);

            andSpecification = new AndSpecification(belowPriceSpecification, new NotSpecification(colorSpecification));

            // Act
            foundProducts = this._finder.SelectBy(andSpecification);

            // Arrange
            Assert.AreEqual(1, foundProducts.Count, "found 1 non-red product < $9.00");
            Assert.IsTrue(foundProducts.Contains(this._baseball), "found baseball");
        }
        public void FindProductsByColorAndBelowPriceTest()
        {
            ColorSpecification colorSpecification = new ColorSpecification(ProductColor.GREEN);

            BelowPriceSpecification belowPriceSpecification = new BelowPriceSpecification(10);

            Specification colorAndBelowPriceSpecification =
                new AndSpecification(colorSpecification, belowPriceSpecification);

            IList <Product> filteredProducts =
                _productRepositoryWithSpecification.FindProducts(colorAndBelowPriceSpecification);

            Assert.AreEqual(1, filteredProducts.Count);
            Assert.AreEqual("Frisbee", filteredProducts.First().Description);
        }