public static void InitializeSchemaAndData(string filePath) { Database.Delete("DatabaseContext"); var initializer = new DatabaseContextInitializer(filePath); Database.SetInitializer(initializer); initializer.InitializeDatabase(DependencyHelper.GetInstance <DatabaseContext>()); }
public void Edit_Positive_Get_Test() { // Arrange var controller = DependencyHelper.GetInstance <EmployeesController>(); // Act var viewResult = controller.Edit(1) as ViewResult; // Assert Assert.AreEqual(string.Empty, viewResult.ViewName); }
public void Edit_Negative_Test_Post_Test() { //Arrange var controller = DependencyHelper.GetInstance <EmployeesController>(); var employee = TestDataHelper.CreateEmployeeWithValidData(1); employee.Address.AddressLine = "2, ABC Road"; controller.FireValidationForModel(employee); //Act controller.Edit(employee); //Assert Assert.IsTrue(EmployeeAddressMustBeUnique.IsErrorAvalilableIn(controller, employee)); }
public static ValidationResult Validate(Employee employee) { List <Employee> otherEmployeesHavingSameAddress = DependencyHelper.GetInstance <DatabaseContext>(). EmployeeRepository. Where(e => (e.Address.AddressLine == employee.Address.AddressLine) && (e.Id != employee.Id)). ToList(); if (otherEmployeesHavingSameAddress.Count > 0) { return(new ValidationResult(GetFormattedErrorMessage(employee), new string[] { string.Empty, "Address.AddressLine" })); } return(ValidationResult.Success); }
public static IEnumerable <SelectListItem> SupervisorSelectList(int?reportsToId) { var supervisors = DependencyHelper.GetInstance <DatabaseContext>().EmployeeRepository.AsEnumerable(); var supervisorSelectList = supervisors.Select(option => new SelectListItem { Text = option.FirstName + " " + option.LastName, Value = option.Id.ToString(), Selected = reportsToId != null && option.Id == reportsToId }); return(supervisorSelectList); }
public void Edit_Positive_Post_Test() { //Arrange var controller = DependencyHelper.GetInstance <EmployeesController>(); var employee = TestDataHelper.CreateEmployeeWithValidData(1); controller.FireValidationForModel(employee); //Act var result = controller.Edit(employee); //Assert Assert.IsTrue(controller.ModelState.IsValid); }
public static ValidationResult Validate(Employee employee) { if (employee.ReportsTo == null) { return(ValidationResult.Success); } if (employee.Supervisor == null) { employee.Supervisor = DependencyHelper.GetInstance <DatabaseContext>(). EmployeeRepository. Find((int)employee.ReportsTo); } return(employee.Address.Country != employee.Supervisor.Address.Country ? new ValidationResult(ERROR_MESSAGE, new[] { string.Empty, nameof(Address.Country) }) : ValidationResult.Success); }
public void Edit_Test() { //Arrange var controller = DependencyHelper.GetInstance <EmployeesController>(); var employee = TestDataHelper.CreateEmployeeWithValidData(1); employee.Address.AddressLine = string.Empty; controller.FireValidationForModel(employee.Address); //Act var result = controller.Edit(employee); //Assert Assert.IsFalse(controller.ModelState.IsValid); }
public void Edit_Test() { //Arrange TestInitialize(); var controller = DependencyHelper.GetInstance <EmployeesController>(); var employee = TestDataHelper.CreateEmployeeWithValidData(1); employee.Address.AddressLine = string.Empty; controller.Validate(employee.Address); //Act var result = controller.Edit(employee); //Assert Assert.NotNull(result); Assert.False(controller.ModelState.IsValid); }