public void CheckIfEmployeePersonalDetailsIsSaved() { // ARRANGE var uow = Mock.Create<IQTecUnitOfWork>(Behavior.Loose); var employeeToBeUpdated = new Employee { DateOfBirth = new DateTime(2012, 1, 1), DesignationId = 2, Email = "*****@*****.**", FirstName = "Abc", LastName = "XYZ" }; var employeePersonalDtoinParamater = new EmployeePersonalInfo { DateOfBirth = new DateTime(2012, 1, 1), DesignationId = 2, Email = "*****@*****.**", FirstName = "AbcDef", //firstname is changed LastName = "XYZ" }; Mock.Arrange(() => uow.EmployeeRepository.GetById(Arg.AnyInt)).Returns(employeeToBeUpdated); Mock.Arrange(() => uow.EmployeeRepository.Update(Arg.IsAny<Employee>())) .DoInstead(() => { employeeToBeUpdated.FirstName = employeePersonalDtoinParamater.FirstName; }) .OccursOnce(); Mock.Arrange(() => uow.EmployeeLanguagesRepository.GetAll()).DoNothing(); // ACT var classunderTest = new EmployeeManager(uow); classunderTest.SaveEmployee(1, employeePersonalDtoinParamater, null); // ASSERT Assert.AreEqual("AbcDef", employeeToBeUpdated.FirstName); Mock.Assert(uow); }
public void CheckWhetherLanguagesAreGettingUpdatedInEmployeeSave() { // ARRANGE var uow = Mock.Create<IQTecUnitOfWork>(Behavior.Loose); var employeeToBeUpdated = new Employee { DateOfBirth = new DateTime(2012, 1, 1), DesignationId = 2, Email = "*****@*****.**", FirstName = "Abc", LastName = "XYZ" }; var employeePersonalDtoinParamater = new EmployeePersonalInfo { DateOfBirth = new DateTime(2012, 1, 1), DesignationId = 2, Email = "*****@*****.**", FirstName = "AbcDef", // firstname is changed LastName = "XYZ" }; Mock.Arrange(() => uow.EmployeeRepository.GetById(Arg.AnyInt)).Returns(employeeToBeUpdated); var currentEmployeeLanguagesKnown = new List<EmployeeLanguages> { new EmployeeLanguages { EmployeeId = 1, Fluency = 1, LanguageId = 1 }, new EmployeeLanguages { EmployeeId = 1, Fluency = 1, LanguageId = 2 } }; Mock.Arrange(() => uow.EmployeeLanguagesRepository.GetAll()).Returns(currentEmployeeLanguagesKnown.AsQueryable); //// updating fluency from 1 to 2 var employeeLanguagesInfoParamater = new List<EmployeeLanguageInfo> { new EmployeeLanguageInfo { EmployeeId = 1, Fluency = (Fluency)2, LanguageId = 1 }, new EmployeeLanguageInfo { EmployeeId = 1, Fluency = (Fluency)2, LanguageId = 2 } }; Mock.Arrange(() => uow.EmployeeLanguagesRepository.Update(Arg.IsAny<EmployeeLanguages>())).DoInstead( () => { foreach (var employeeLanguageInfo in employeeLanguagesInfoParamater) { var languageToBeUpdated = currentEmployeeLanguagesKnown.FirstOrDefault( lang => lang.EmployeeId == 1 && lang.LanguageId == employeeLanguageInfo.LanguageId); if (languageToBeUpdated != null) { languageToBeUpdated.Fluency = (int)employeeLanguageInfo.Fluency; } } }); // ACT var classunderTest = new EmployeeManager(uow); classunderTest.SaveEmployee(1, employeePersonalDtoinParamater, employeeLanguagesInfoParamater); // ASSERT var firstOrDefault = currentEmployeeLanguagesKnown.FirstOrDefault(); if (firstOrDefault != null) { Assert.AreEqual(2, firstOrDefault.Fluency); } Mock.Assert(uow); }
/// <summary> /// Adds the employee. /// </summary> /// <param name="employee">The employee.</param> public void AddEmployee(Employee employee) { this.qTecUnitOfWork.EmployeeRepository.Add(employee); this.qTecUnitOfWork.Commit(); }
public void Valid_Employee_Should_Be_Returned_When_Requested() { // ARRANGE var expectedEmployee = new Employee { EmployeeId = 1, DateOfBirth = new DateTime(1998, 2, 3), DesignationId = 2 }; var uow = Mock.Create<IQTecUnitOfWork>(Behavior.Loose); Mock.Arrange(() => uow.EmployeeRepository.GetById(Arg.AnyInt)).Returns(expectedEmployee); // ACT var classunderTest = new EmployeeManager(uow); // ASSERT var actualEmployee = classunderTest.GetEmployeeById(1); Assert.AreEqual(expectedEmployee, actualEmployee); }
/// <summary> /// Updates the employee. /// </summary> /// <param name="employee">The employee.</param> public void UpdateEmployee(Employee employee) { this.qTecUnitOfWork.EmployeeRepository.Update(employee); this.qTecUnitOfWork.Commit(); }