예제 #1
0
        static void Main(string[] args)
        {
            var parent = new Person {
                Name = "Dick"
            };
            var child = new Person {
                Name = "Tom"
            };
            var sibling1 = new Person {
                Name = "Harry"
            };
            var sibling2 = new Person {
                Name = "Sally"
            };

            var persons = new List <Person>();

            persons.Add(parent);
            persons.Add(child);
            persons.Add(sibling1);
            persons.Add(sibling2);

            var relationships = new Relationships();

            relationships.AddParentChild(parent, child);
            relationships.AddSiblings(parent, sibling1);
            relationships.AddSiblings(parent, sibling2);
            relationships.AddSiblings(sibling1, sibling2);


            new Program(relationships, persons);  //horrible :D

            Console.ReadLine();
        }
예제 #2
0
        public void FindAllChildrenOfAParent()
        {
            //find all children of a parent
            var adultAna = new Person()
            {
                Name = "Ana"
            };
            var adultPeca = new Person()
            {
                Name = "Peca"
            };

            var childVeronica = new Person()
            {
                Name = "Veronika"
            };
            var childMarija = new Person()
            {
                Name = "Marija"
            };
            var childMilos = new Person()
            {
                Name = "Milos"
            };

            var relationships = new Relationships();

            var childrenOfAna = new Person[3] {
                childVeronica, childMarija, childMilos
            };

            foreach (var child in childrenOfAna)
            {
                relationships.AddParentChild(adultAna, child);
            }

            relationships.AddParentChild(adultPeca, childMarija);
            relationships.AddParentChild(adultPeca, childMilos);


            var research           = new Research(relationships);
            var childrenOfAnaFound = research.FindAllChildrenOf(adultAna);

            var isAllChildrenPresent = true;

            foreach (var child in childrenOfAna)
            {
                var isChildFound = false;
                foreach (var childFromResearch in childrenOfAnaFound)
                {
                    if (childFromResearch.Name == child.Name)
                    {
                        isChildFound = true;
                        break;
                    }
                }
                if (!isChildFound)
                {
                    isAllChildrenPresent = false;
                    break;
                }
            }

            Assert.True(isAllChildrenPresent);

            //count children from result, there should be exactly childrenOfAna.Count
            var countChildrenOfAnaFound = 0;

            foreach (var c in childrenOfAnaFound)
            {
                countChildrenOfAnaFound++;
            }

            Assert.True(countChildrenOfAnaFound == childrenOfAna.Length);

            //Console.WriteLine($"children of Ana: {Environment.NewLine}{String.Join(Environment.NewLine, childrenOfAnaFound)}");
        }
예제 #3
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);
        }