public void SubmitShouldUpdateUserDetailsWhenExistingUser() { var mockRepo = new Mock <IApplicantDetailsRepository>(); var loadResult = new ApplicantDetails { Id = 1, FirstName = "test", AnnualIncome = 20000 }; loadResult.Initialize(); mockRepo.Setup(x => x.LoadApplicantDetails(It.IsAny <ApplicantDetails>())).ReturnsAsync(loadResult); var controller = new SearchController(mockRepo.Object, new CardsRepository()); var newApplicant = new ApplicantDetails { FirstName = "test", DateOfBirth = new DateTime(2002, 01, 10), AnnualIncome = 40000 }; var result = controller.Create(newApplicant); Assert.IsInstanceOf <RedirectToActionResult>(result.Result); Assert.AreEqual(loadResult.GuId, ((RedirectToActionResult)result.Result).RouteValues["guid"]); }
public async Task WebApp_Create_returns_ok_on_successful_insert() { _searchApi.Setup(m => m.Add(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(OkResponse)); var controller = new SearchController(_searchApi.Object, _logger.Object); var result = await controller.Create(JohnSmith); _searchApi.Verify(m => m.Add(It.IsAny <string>(), It.IsAny <string>()), Times.Once); Assert.IsInstanceOfType(result, typeof(ContentResult)); Assert.AreEqual(Ok, ((ContentResult)result).Content); }
public async Task WebApp_Create_returns_error_on_insert_failure() { _searchApi.Setup(m => m.Add(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(FailureResponse)); var controller = new SearchController(_searchApi.Object, _logger.Object); var result = await controller.Create(""); _searchApi.Verify(m => m.Add(It.IsAny <string>(), It.IsAny <string>()), Times.Once); Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult)); Assert.AreEqual(ErrorMessage, ((HttpNotFoundResult)result).StatusDescription); }
public void SubmitShouldCreateUserDetails() { var mockRepo = new Mock <IApplicantDetailsRepository>(); mockRepo.Setup(x => x.LoadApplicantDetails(It.IsAny <ApplicantDetails>())).ReturnsAsync((ApplicantDetails)null); var controller = new SearchController(mockRepo.Object, new CardsRepository()); var newApplicant = new ApplicantDetails { FirstName = "test" }; var result = controller.Create(newApplicant); Assert.IsInstanceOf <RedirectToActionResult>(result.Result); }