public void CanUserVisitor() { var employees = new Employees(); employees.Add(new Clerk()); employees.Add(new Manager()); employees.Add(new President()); var salary = new SalaryVisitor(); employees.Visit(salary); Assert.AreEqual(4500, salary.Total); var vacation = new VacationVisitor(); employees.Visit(vacation); Assert.AreEqual(60, vacation.Total); }
static void Main(string[] args) { // Setup structure ElementStructure structure = new ElementStructure(); structure.Attach(new Employee { Name = "Risto Reipas", Salary = 3000, VacationDays = 20 }); structure.Attach(new Employee { Name = "Erno Perälä", Salary = 3200, VacationDays = 40 }); structure.Attach(new Employee { Name = "Sauli Niinistö", Salary = 13000, VacationDays = 2 }); // Create visitor objects IVisitor salaryFairy = new SalaryVisitor(); IVisitor vacationFairy = new VacationVisitor(); // Structure accepting visitors structure.Accept(salaryFairy); structure.Accept(vacationFairy); // Wait for user Console.ReadLine(); }