Esempio n. 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");
        }
Esempio n. 2
0
        public static AndSpecification <Product> And(this Color color, Size size)
        {
            var colosSpec = new ColorSpecification(color);
            var sizeSpec  = new SizeSpecification(size);

            return(new AndSpecification <Product>(colosSpec, sizeSpec));
        }
        public void SetSpotlightViewfinderSizeSpec(SizeSpecification spec)
        {
            ViewfinderType currentViewfinder = this.GetCurrentViewfinderType();

            if (currentViewfinder is ViewfinderTypeSpotlight)
            {
                ((ViewfinderTypeSpotlight)currentViewfinder).SizeSpecification = spec;
                this.SetViewfinderType(currentViewfinder);
            }
        }
Esempio n. 4
0
        public void SetRectangularViewfinderSizeSpec(SizeSpecification spec)
        {
            ViewfinderType currentViewfinder = this.GetCurrentViewfinderType();

            if (currentViewfinder is ViewfinderTypeRectangular)
            {
                ((ViewfinderTypeRectangular)currentViewfinder).SizeSpecification = spec;
                this.SetViewfinderType(currentViewfinder);
            }
        }
Esempio n. 5
0
        public bool IsSatisfied(Window window)
        {
            var nameLack   = new NameLackSpecification();
            var visibility = new VisibilitySpecification();
            var size       = new SizeSpecification();

            var filter = nameLack.And(visibility).And(size);

            return(filter.IsSatisfiedBy(window));
        }
Esempio n. 6
0
        public async Task SetRectangularLocationSizeSpecAsync(SizeSpecification spec)
        {
            LocationType locationType = this.GetCurrentLocationType();

            if (locationType is LocationTypeRectangular)
            {
                ((LocationTypeRectangular)locationType).SizeSpecification = spec;
                await this.SetLocationTypeAsync(locationType);
            }
        }
Esempio n. 7
0
 public void ProductFilterColorBlack_IsFail()
 {
     var productFilter = new ProductFilter();
     var sizeSpecify   = new SizeSpecification(Size.Midium);
     var data          = new List <ProductManage>()
     {
         new ProductManage("P3", Color.Blue, Size.Small, 3000),
         new ProductManage("P4", Color.Black, Size.Midium, 3000)
     };
 }
        public void TestSizeFilter()
        {
            Size size = Size.Middle;

            var sizeSpecification = new SizeSpecification(size);
            IList<IProduct> filterList = filter.Filter(_productList, sizeSpecification);
            foreach (var product in filterList)
            {
                Assert.AreEqual(product.Size, size);
            }
        }
        public void TestSizeFilter()
        {
            Size size = Size.Middle;

            var sizeSpecification       = new SizeSpecification(size);
            IList <IProduct> filterList = filter.Filter(_productList, sizeSpecification);

            foreach (var product in filterList)
            {
                Assert.AreEqual(product.Size, size);
            }
        }
Esempio n. 10
0
        private void SetupForRectangularViewfinder(ViewfinderTypeRectangular viewfinder)
        {
            this.textType.Visibility           = ViewStates.Visible;
            this.cardRectangular.Visibility    = ViewStates.Visible;
            this.cardAnimation.Visibility      = ViewStates.Visible;
            this.cardSpecifications.Visibility = ViewStates.Visible;
            this.cardMeasures.Visibility       = ViewStates.Visible;
            this.cardLaserline.Visibility      = ViewStates.Gone;
            this.cardAimer.Visibility          = ViewStates.Gone;

            SizeSpecification spec = viewfinder.SizeSpecification;

            switch (spec)
            {
            case SizeSpecification.WidthAndHeight:
                this.containerHeight.Visibility                 = ViewStates.Visible;
                this.containerWidth.Visibility                  = ViewStates.Visible;
                this.containerHeightAspect.Visibility           = ViewStates.Gone;
                this.containerWidthAspect.Visibility            = ViewStates.Gone;
                this.containerShorterDimension.Visibility       = ViewStates.Gone;
                this.containerShorterDimensionAspect.Visibility = ViewStates.Gone;
                break;

            case SizeSpecification.HeightAndWidthAspect:
                this.containerHeight.Visibility                 = ViewStates.Visible;
                this.containerWidth.Visibility                  = ViewStates.Gone;
                this.containerHeightAspect.Visibility           = ViewStates.Gone;
                this.containerWidthAspect.Visibility            = ViewStates.Visible;
                this.containerShorterDimension.Visibility       = ViewStates.Gone;
                this.containerShorterDimensionAspect.Visibility = ViewStates.Gone;
                break;

            case SizeSpecification.WidthAndHeightAspect:
                this.containerHeight.Visibility                 = ViewStates.Gone;
                this.containerWidth.Visibility                  = ViewStates.Visible;
                this.containerHeightAspect.Visibility           = ViewStates.Visible;
                this.containerWidthAspect.Visibility            = ViewStates.Gone;
                this.containerShorterDimension.Visibility       = ViewStates.Gone;
                this.containerShorterDimensionAspect.Visibility = ViewStates.Gone;
                break;

            case SizeSpecification.ShorterDimensionAndAspect:
                this.containerHeight.Visibility                 = ViewStates.Gone;
                this.containerWidth.Visibility                  = ViewStates.Gone;
                this.containerHeightAspect.Visibility           = ViewStates.Gone;
                this.containerWidthAspect.Visibility            = ViewStates.Gone;
                this.containerShorterDimension.Visibility       = ViewStates.Visible;
                this.containerShorterDimensionAspect.Visibility = ViewStates.Visible;
                break;
            }

            this.RefreshRectangularViewfinderData(viewfinder);
        }
        public void FindProductsBySizeNotEqualToTest()
        {
            SizeSpecification sizeSpecification = new SizeSpecification(ProductSize.SMALL);

            Specification notSpecification = new NotSpecification(sizeSpecification);

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

            Assert.AreEqual(4, filteredProducts.Count);
            Assert.AreEqual("Fire Truck", filteredProducts.First().Description);
            Assert.AreEqual("Toy Porsche Convertible", filteredProducts.Last().Description);
        }
        public void FindProductsByColorAndSizeTest()
        {
            ColorSpecification colorSpecification = new ColorSpecification(ProductColor.GREEN);

            SizeSpecification sizeSpecification = new SizeSpecification(ProductSize.SMALL);

            Specification colorAndSizeSpecification =
                new AndSpecification(colorSpecification, sizeSpecification);

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

            Assert.AreEqual(0, filteredProducts.Count);
        }
        public void FindProductsByColorAndSizeTest()
        {
            ColorSpecification colorSpecification = new ColorSpecification(ProductColor.GREEN);

            SizeSpecification sizeSpecification = new SizeSpecification(ProductSize.SMALL);

            Specification colorAndSizeSpecification =
                new AndSpecification(colorSpecification, sizeSpecification);

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

            Assert.AreEqual(0, filteredProducts.Count);
        }
        public void TestOrFilter()
        {
            Size size = Size.Large;
            Color color = Color.Red;
            var spec1 = new SizeSpecification(size);
            var spec2 = new ColorSpecification(color);
            var orSizeSpecification = new OrSpecification(spec1, spec2);

            IList<IProduct> filterList = filter.Filter(_productList, orSizeSpecification);
            foreach (var product in filterList)
            {
                bool matched = (product.Color == color) || (product.Size == size);
                Assert.IsTrue(matched);
            }
        }
 private LocationTypeRectangular(
     int displayNameResourceId,
     bool enabled,
     SizeSpecification sizeSpecification,
     FloatWithUnit width,
     FloatWithUnit height,
     float heightAspectRatio,
     float widthAspectRatio) : base(displayNameResourceId, enabled)
 {
     this.SizeSpecification = sizeSpecification;
     this.Width             = width;
     this.Height            = height;
     this.HeightAspectRatio = heightAspectRatio;
     this.WidthAspectRatio  = widthAspectRatio;
 }
        public void TestColorAndSizeFilter()
        {
            Size  size  = Size.Large;
            Color color = Color.Red;
            var   spec1 = new SizeSpecification(size);
            var   spec2 = new ColorSpecification(color);
            var   andSizeSpecification = new AndSpecification(spec1, spec2);

            IList <IProduct> filterList = filter.Filter(_productList, andSizeSpecification);

            foreach (var product in filterList)
            {
                bool matched = (product.Color == color) && (product.Size == size);
                Assert.IsTrue(matched);
            }
        }
        public void FindProductsByColorOrSizeTest()
        {
            ColorSpecification colorSpecification = new ColorSpecification(ProductColor.GREEN);

            SizeSpecification sizeSpecification = new SizeSpecification(ProductSize.SMALL);

            Specification colorOrSizeSpecification =
                new OrSpecification(colorSpecification, sizeSpecification);

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

            Assert.AreEqual(2, filteredProducts.Count);
            Assert.AreEqual("Barbie Classic", filteredProducts.First().Description);
            Assert.AreEqual("Frisbee", filteredProducts.Last().Description);
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var apple = new Product("Apple", Color.Green, Size.Small);
            var tree  = new Product("Tree", Color.Green, Size.Large);
            var house = new Product("House", Color.Blue, Size.Large);

            Product[] products = { apple, tree, house };

            var fs = new FilterService();

            Console.WriteLine("Green products (new):");
            var specification = new ColorSpecification(Color.Green);
            var filtered      = fs.Filter(products, specification);

            foreach (var p in filtered)
            {
                Console.WriteLine($" - {p.Name} is green");
            }

            Console.WriteLine("Large products");
            foreach (var p in fs.Filter(products, new SizeSpecification(Size.Large)))
            {
                Console.WriteLine($" - {p.Name} is large");
            }

            Console.WriteLine("Medium Red products");
            var redSpec           = new ColorSpecification(Color.Red);
            var mediumSpec        = new SizeSpecification(Size.Medium);
            var andSpecification  = new AndSpecification <Product>(redSpec, mediumSpec);
            var mediumRedFiltered = fs.Filter(products, andSpecification);

            foreach (var p in mediumRedFiltered)
            {
                Console.WriteLine($" - {p.Name} is large");
            }

            Console.WriteLine("Large blue items");
            foreach (var p in fs.Filter(products,
                                        new AndSpecification <Product>(
                                            new ColorSpecification(Color.Blue),
                                            new SizeSpecification(Size.Large)))
                     )
            {
                Console.WriteLine($" - {p.Name} is big and blue");
            }
        }
        private void SetupForSpotlightViewfinder(ViewfinderTypeSpotlight viewfinder)
        {
            this.textType.Visibility                       = ViewStates.Visible;
            this.cardColor.Visibility                      = ViewStates.Gone;
            this.cardSpecifications.Visibility             = ViewStates.Gone;
            this.cardMeasures.Visibility                   = ViewStates.Gone;
            this.cardLaserline.Visibility                  = ViewStates.Gone;
            this.cardSpotlightColor.Visibility             = ViewStates.Visible;
            this.cardSpotlightSizeSpecification.Visibility = ViewStates.Visible;
            this.cardSpotlightMeasures.Visibility          = ViewStates.Visible;

            SizeSpecification spec = viewfinder.SizeSpecification;

            switch (spec)
            {
            case SizeSpecification.WidthAndHeight:
                this.containerSpotlightHeight.Visibility       = ViewStates.Visible;
                this.containerSpotlightWidth.Visibility        = ViewStates.Visible;
                this.containerSpotlightHeightAspect.Visibility = ViewStates.Gone;
                this.containerSpotlightWidthAspect.Visibility  = ViewStates.Gone;
                break;

            case SizeSpecification.HeightAndWidthAspect:
                this.containerSpotlightHeight.Visibility       = ViewStates.Visible;
                this.containerSpotlightWidth.Visibility        = ViewStates.Gone;
                this.containerSpotlightHeightAspect.Visibility = ViewStates.Gone;
                this.containerSpotlightWidthAspect.Visibility  = ViewStates.Visible;
                break;

            case SizeSpecification.WidthAndHeightAspect:
                this.containerSpotlightHeight.Visibility       = ViewStates.Gone;
                this.containerSpotlightWidth.Visibility        = ViewStates.Visible;
                this.containerSpotlightHeightAspect.Visibility = ViewStates.Visible;
                this.containerSpotlightWidthAspect.Visibility  = ViewStates.Gone;
                break;
            }

            this.RefreshSpotlightViewfinderData(viewfinder);
        }
        public void FindProductsBySizeNotEqualToTest()
        {
            SizeSpecification sizeSpecification = new SizeSpecification(ProductSize.SMALL);

            Specification notSpecification = new NotSpecification(sizeSpecification);

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

            Assert.AreEqual(4, filteredProducts.Count);
            Assert.AreEqual("Fire Truck", filteredProducts.First().Description);
            Assert.AreEqual("Toy Porsche Convertible", filteredProducts.Last().Description);
        }
        public void FindProductsByColorOrSizeTest()
        {
            ColorSpecification colorSpecification = new ColorSpecification(ProductColor.GREEN);

            SizeSpecification sizeSpecification = new SizeSpecification(ProductSize.SMALL);

            Specification colorOrSizeSpecification =
                new OrSpecification(colorSpecification, sizeSpecification);

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

            Assert.AreEqual(2, filteredProducts.Count);
            Assert.AreEqual("Barbie Classic", filteredProducts.First().Description);
            Assert.AreEqual("Frisbee", filteredProducts.Last().Description);
        }
Esempio n. 22
0
 public AndSpecification(ColorSpecification colorSpecification, SizeSpecification sizeSpecification)
 {
     _colorSpecification = colorSpecification;
     _sizeSpecification  = sizeSpecification;
 }
Esempio n. 23
0
        private static void SolidPrinciples()
        {
            var journal = new Journal();

            journal.AddEntry("I Started today Udemy.");
            journal.AddEntry("I started with Solid.");
            Console.WriteLine(journal);

            var persistence = new Persistence();
            var fileName    = @"C:\dev\designPatterns\journal.txt";

            persistence.SaveToFile(journal, fileName, true);

            var apple  = new Product("apple", Enums.Color.Green, Enums.Size.Small);
            var orange = new Product("orange", Enums.Color.Red, Enums.Size.Small);
            var tree   = new Product("tree", Enums.Color.Blue, Enums.Size.Large);
            var house  = new Product("house", Enums.Color.Blue, Enums.Size.Large);

            Product[] products = { apple, tree, house, orange };

            var productFilter = new ProductFilter();

            Console.WriteLine("Blue products (old): ");
            foreach (var p in productFilter.FilterByColor(products, Enums.Color.Blue))
            {
                Console.WriteLine($" - {p.Name} is Blue");
            }

            var betterFilter = new BetterFilter();
            var colorSpec    = new ColorSpecification(Enums.Color.Blue);

            Console.WriteLine("Blue products (new): ");
            foreach (var p in betterFilter.Filter(products, colorSpec))
            {
                Console.WriteLine($" - {p.Name} is Blue");
            }
            var sizeSpec   = new SizeSpecification(Enums.Size.Large);
            var doubleSpec = new AndSpecification <Product>(colorSpec, sizeSpec);

            Console.WriteLine("Blue and Large products (new): ");
            foreach (var p in betterFilter.Filter(products, doubleSpec))
            {
                Console.WriteLine($" - {p.Name} is Blue and large");
            }

            var rectangle = new Rectangle(2, 3);

            Console.WriteLine($"{rectangle} has area {Area(rectangle)}");

            Rectangle square = new Square();

            square.Width = 3;
            Console.WriteLine($"{square} has area {Area(square)}");

            var parent = new PersonDependencyInversion {
                Name = "Otman"
            };
            var child1 = new PersonDependencyInversion {
                Name = "Loreto"
            };
            var child2 = new PersonDependencyInversion {
                Name = "Emilio"
            };

            rS.AddParentChild(parent, child1);
        }