public void SetUp() { //initializing controller.... //m_controller = new Controller (...what the heck should be here...?) //approach 1. create "fake" class implementing IEmployeeRepository this.m_controller = new Controller(new FakeEmployeeRepository()); // a gdzie tu czytelnoœæ? Osoba, która potem ogl¹da takie testy, nie wie co siê dzieje! }
public void SetUp() { //create result set this.m_employeesList = new List<Employee> (); this.m_employeesList.Add (new Employee () { FirstName = "Mój", Salary = 2000 }); //approach 2. create moq... var repository = new Mock<IEmployeeRepository> (); repository.Setup (x => x.GetEmployees ()).Returns (this.m_employeesList); this.m_controller = new Controller (repository.Object); }
public void WhetherEveryUserHasRiseSalaryCalledTest() { var employee = new Mock<Employee> (); employee.Setup (x => x.RaiseSalaryLinear (It.IsAny<double> ())).Verifiable (); var employeesList = new List<Employee> { employee.Object, employee.Object }; var employeeRepo = new Mock<IEmployeeRepository> (); employeeRepo.Setup (x => x.GetEmployees ()).Returns (employeesList); var controller = new Controller (employeeRepo.Object); controller.RaiseSalaryOfAllUsers (150.00); //mozemy sprawdzic, czy byla wywolana tyle razy employee.Verify (x => x.RaiseSalaryLinear (It.IsAny<double> ()), Times.Exactly (2)); //a nawet, czy z konkretnymi argumentami employee.Verify (x => x.RaiseSalaryLinear (It.Is<double> (y => y == 150.0)), Times.Exactly (2)); }