public void DoYourOwnLogic3() { //implement your idea and own logic //use mocks var nonAdmin = new User() { UserName = "******", Password = "******" }; const int id = 1; List <double> weeklySalaries = new List <double>(); weeklySalaries.Add(1200); weeklySalaries.Add(1100); weeklySalaries.Add(1500); var mockLogin = new Mock <ILoginModule>(); mockLogin.Setup(x => x.Login(nonAdmin)) .Callback(() => nonAdmin.Rights = Right.None); var mock = new Mock <IEmployeeRepository>(); mock.Setup(m => m.LoadEmployee(id)).Returns(() => new Employee() { Id = id, Name = "Hans", Type = "Teacher", Wage = 1000 }); Employee e = mock.Object.LoadEmployee(id); mockLogin.Object.Login(nonAdmin); double averageSalary = e.CalculateAverageSalary(weeklySalaries, nonAdmin); }
public void CanCalulateAverageWeeklySaleryPerEmployee() { //implement your own logic //use mocks const int id = 1; List <double> weeklySalaries = new List <double>(); weeklySalaries.Add(1200); weeklySalaries.Add(1100); weeklySalaries.Add(1500); var mock = new Mock <IEmployeeRepository>(); mock.Setup(m => m.LoadEmployee(id)).Returns(() => new Employee() { Id = id, Name = "Hans", Type = "Teacher", Wage = 1000 }); double expectedResult = (1200 + 1100 + 1500) / (3.0); Employee e = mock.Object.LoadEmployee(id); double averageSalary = e.CalculateAverageSalary(weeklySalaries); Assert.AreEqual(expectedResult, averageSalary); }