public void GetDepartmentOptions_Valid() { // Arrange var department = new DepartmentRepository(context).FindById("COMM"); var expectedRepresentative = department.Representative != null ? $"{department.Representative.FirstName} {department.Representative.LastName}" : ""; var expectedEmployeeEmail = "*****@*****.**"; var expectedDepartment = department.Name; var controller = new DepartmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), }; // Act IHttpActionResult actionResult = controller.GetDepartmentOptions(new EmailViewModel() { Email = "*****@*****.**", }); var contentResult = actionResult as OkNegotiatedContentResult <DepartmentOptionsViewModel>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(expectedDepartment, contentResult.Content.Department); Assert.AreEqual(expectedRepresentative, contentResult.Content.Representative); Assert.IsTrue(contentResult.Content.Employees.Select(e => e.Email).Contains(expectedEmployeeEmail)); }
public void ChangeRepresentative_Valid() { // Arrange var expected = "*****@*****.**"; var controller = new DepartmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; var department = departmentService.FindDepartmentByDepartmentCode("COMM"); // Act IHttpActionResult actionResult = controller.ChangeRepresentative(new ChangeRepresentativeViewModel() { RepresentativeEmail = "*****@*****.**", HeadEmail = "*****@*****.**", }); var contentResult = actionResult as OkNegotiatedContentResult <MessageViewModel>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(contentResult.Content.Message, "Successfully changed"); Assert.AreEqual(expected, new UserService(context).FindUserByEmail("*****@*****.**").Department.Representative.Email); }
public void CancelDelegation_NotHead_BadRequest() { // Arrange var controller = new DepartmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; delegationService.DelegateManagerRole("*****@*****.**", "*****@*****.**", "Sat Jul 28 00:00:00 GMT + 08:00 2018", "Sun Jul 29 00:00:00 GMT+08:00 2018"); // Act var latestDelegation = delegationService.FindAllDelegations().OrderByDescending(d => d.DelegationId).FirstOrDefault(); IHttpActionResult actionResult = controller.CancelDelegation(new CancelDelegationViewModel() { DelegationId = latestDelegation.DelegationId, HeadEmail = "*****@*****.**", }); var badRequestResult = actionResult as BadRequestErrorMessageResult; // Assert Assert.IsNotNull(badRequestResult); Assert.AreEqual("Only Department Heads can cancel delegations", badRequestResult.Message); }
public void CancelDelegation_Valid() { // Arrange var controller = new DepartmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; delegationService.DelegateManagerRole("*****@*****.**", "*****@*****.**", "Sat Jul 28 00:00:00 GMT + 08:00 2018", "Sun Jul 29 00:00:00 GMT+08:00 2018"); // Act var latestDelegation = delegationService.FindAllDelegations().OrderByDescending(d => d.DelegationId).FirstOrDefault(); IHttpActionResult actionResult = controller.CancelDelegation(new CancelDelegationViewModel() { DelegationId = latestDelegation.DelegationId, HeadEmail = "*****@*****.**", }); var contentResult = actionResult as OkNegotiatedContentResult <MessageViewModel>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(contentResult.Content.Message, "Successfully cancelled"); Assert.AreEqual(3, delegationService.FindAllDelegations().OrderByDescending(d => d.DelegationId).FirstOrDefault().Status.StatusId); }
public void DelegateManagerRole_Valid() { // Arrange var expected = "*****@*****.**"; var controller = new DepartmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; // Act IHttpActionResult actionResult = controller.DelegateManagerRole(new DelegationSubmitViewModel() { RecipientEmail = "*****@*****.**", HeadEmail = "*****@*****.**", StartDate = "Sat Jul 28 00:00:00 GMT + 08:00 2018", EndDate = "Sun Jul 29 00:00:00 GMT+08:00 2018" }); var contentResult = actionResult as OkNegotiatedContentResult <MessageViewModel>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(contentResult.Content.Message, "Successfully delegated"); Assert.AreEqual(expected, new DelegationService(context).FindAllDelegations().OrderByDescending(d => d.DelegationId).FirstOrDefault().Receipient.Email); }
public void CancelDelegation_InvalidId_BadRequest() { // Arrange var controller = new DepartmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; // Act IHttpActionResult actionResult = controller.CancelDelegation(new CancelDelegationViewModel() { DelegationId = 999999, HeadEmail = "*****@*****.**", }); var badRequestResult = actionResult as BadRequestErrorMessageResult; // Assert Assert.IsNotNull(badRequestResult); Assert.AreEqual("Delegation does not exist", badRequestResult.Message); }
public void ChangeRepresentative_NoRights_BadRequest() { // Arrange var expected = "User does not have managerial rights"; var controller = new DepartmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; // Act IHttpActionResult actionResult = controller.ChangeRepresentative(new ChangeRepresentativeViewModel() { RepresentativeEmail = "*****@*****.**", HeadEmail = "*****@*****.**", }); BadRequestErrorMessageResult badRequest = actionResult as BadRequestErrorMessageResult; // Assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult)); Assert.AreEqual(expected, badRequest.Message); }
public void DelegateManagerRole_NotSameDepartment_BadRequest() { // Arrange var controller = new DepartmentAPIController() { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration(), Context = context, }; // Act IHttpActionResult actionResult = controller.DelegateManagerRole(new DelegationSubmitViewModel() { RecipientEmail = "*****@*****.**", HeadEmail = "*****@*****.**", StartDate = "Sat Jul 28 00:00:00 GMT + 08:00 2018", EndDate = "Sun Jul 29 00:00:00 GMT+08:00 2018", }); var badRequestResult = actionResult as BadRequestErrorMessageResult; // Assert Assert.IsNotNull(badRequestResult); Assert.AreEqual("Representative and Department Head not from same Department", badRequestResult.Message); }