public async Task TestPostSendToSevisAsync_InvalidModel() { var model = new SendToSevisBindingModel { ParticipantIds = new List <int> { 1 }, SevisOrgId = "org", SevisUsername = "******" }; controller.ModelState.AddModelError("key", "error"); var response = await controller.PostSendToSevisAsync(1, 1, model); Assert.IsInstanceOfType(response, typeof(InvalidModelStateResult)); }
public async Task TestPostSendToSevisAsync_UserDoesNotHaveProvidedSevisCredentials() { var model = new SendToSevisBindingModel { ParticipantIds = new List <int> { 1 }, SevisOrgId = "org", SevisUsername = "******" }; var projectId = 10; var user = new User(100); userProvider.Setup(x => x.HasSevisUserAccountAsync(It.IsAny <IWebApiUser>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(false); participantPersonSevisService.Setup(x => x.SendToSevisAsync(It.IsAny <ParticipantsToBeSentToSevis>())).ReturnsAsync(new int[] { }); Func <Task> f = () => controller.PostSendToSevisAsync(1, projectId, model); f.ShouldThrow <HttpResponseException>().And.Response.StatusCode.Should().Be(HttpStatusCode.Forbidden); }
public void TestMethod1() { var model = new SendToSevisBindingModel { ParticipantIds = new List <int> { 1 }, SevisOrgId = "org", SevisUsername = "******" }; var user = new User(100); var projectId = 10; var instance = model.ToParticipantsToBeSentToSevis(user, projectId); Assert.AreEqual(model.SevisOrgId, instance.SevisOrgId); Assert.AreEqual(model.SevisUsername, instance.SevisUsername); Assert.AreEqual(projectId, instance.ProjectId); Assert.IsTrue(Object.ReferenceEquals(user, instance.Audit.User)); CollectionAssert.AreEqual(model.ParticipantIds.ToList(), instance.ParticipantIds.ToList()); }
public async Task TestPostSendToSevisAsync() { var model = new SendToSevisBindingModel { ParticipantIds = new List <int> { 1 }, SevisOrgId = "org", SevisUsername = "******" }; var projectId = 10; var user = new User(100); userProvider.Setup(x => x.HasSevisUserAccountAsync(It.IsAny <IWebApiUser>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); participantPersonSevisService.Setup(x => x.SendToSevisAsync(It.IsAny <ParticipantsToBeSentToSevis>())).ReturnsAsync(new int[] { }); var response = await controller.PostSendToSevisAsync(1, projectId, model); participantPersonSevisService.Verify(x => x.SaveChangesAsync(), Times.Once); Assert.IsInstanceOfType(response, typeof(OkNegotiatedContentResult <int[]>)); }
public async Task <IHttpActionResult> PostSendToSevisAsync(int applicationId, int projectId, SendToSevisBindingModel model) { if (ModelState.IsValid) { var currentUser = userProvider.GetCurrentUser(); var businessUser = userProvider.GetBusinessUser(currentUser); var hasSevisCredentials = await userProvider.HasSevisUserAccountAsync(currentUser, model.SevisUsername, model.SevisOrgId); if (!hasSevisCredentials) { throw new HttpResponseException(System.Net.HttpStatusCode.Forbidden); } var businessModel = model.ToParticipantsToBeSentToSevis(businessUser, projectId); var statuses = await participantService.SendToSevisAsync(businessModel); await participantService.SaveChangesAsync(); return(Ok(statuses)); } else { return(BadRequest(ModelState)); } }