예제 #1
0
        static void VisitorTester()
        {
            #region sample 1
            // Setup structure
            ObjectStructure o = new ObjectStructure();
            o.Attach(new ConcreteElementA());
            o.Attach(new ConcreteElementB());

            // Create visitor objects
            ConcreteVisitor1 v1 = new ConcreteVisitor1();
            ConcreteVisitor2 v2 = new ConcreteVisitor2();

            // Structure accepting visitors
            o.Accept(v1);
            o.Accept(v2);
            #endregion

            #region sample 2
            // Setup employee collection
            EmployeeVs e = new EmployeeVs();
            e.Attach(new ClerkV());
            e.Attach(new DirectorV());
            e.Attach(new PresidentV());

            // Employees are 'visited'
            e.Accept(new IncomeVisitor());
            e.Accept(new VacationVisitor());
            #endregion
        }
예제 #2
0
        public static void TestVacations()
        {
            var e = new EmployeeVs();

            e.Attach(new ClerkV());
            e.Attach(new DirectorV());
            e.Attach(new PresidentV());

            var firstAccept = e.Accept(new IncomeVisitor(), true);

            StringAssert.AreEqualIgnoringCase("ClerkV Hank's new income: $27,500.00\r\nDirectorV Elly's new income: $38,500.00\r\nPresidentV Dick's new income: $49,500.00\r\n", firstAccept);
            var secondAccept = e.Accept(new VacationVisitor(), true);

            StringAssert.AreEqualIgnoringCase("ClerkV Hank's new vacation days: 17\r\nDirectorV Elly's new vacation days: 19\r\nPresidentV Dick's new vacation days: 24\r\n", secondAccept);
        }