public void AddEmployee_400_Name_Missing() { var controller = new ServiceController(mockAppSettings.Object, mockDatabaseRepository.Object); var request = new AddEmployeeRequest() { }; var validationResults = ValidateRequest(request); foreach (var validationResult in validationResults) { controller.ModelState.AddModelError(validationResult.MemberNames.First(), validationResult.ErrorMessage); } var response = controller.AddEmployee(request) as ObjectResult; var result = response.Value as AddEmployeeResponse; Assert.AreEqual(result.Success, false); Assert.IsTrue(result.ErrorResponse.Message.Contains("Name")); Assert.AreEqual(response.StatusCode, 400); }
public void AddEmployee_200_OK() { var controller = new ServiceController(mockAppSettings.Object, mockDatabaseRepository.Object); var request = new AddEmployeeRequest() { Name = "Unit Testing", Address = "TestAddress", DepartmentId = 1002, Salary = 3200 }; var validationResults = ValidateRequest(request); foreach (var validationResult in validationResults) { controller.ModelState.AddModelError(validationResult.MemberNames.First(), validationResult.ErrorMessage); } var response = controller.AddEmployee(request) as ObjectResult; var result = response.Value as AddEmployeeResponse; Assert.AreEqual(result.Success, true); Assert.AreEqual(response.StatusCode, 200); }