public async Task Verify_ReturnsSameView_WithUnSuccessfulInput() { // Arrange var mockService = new Mock <IAccessLogService>(); var mockLogger = new Mock <ILogger <AccessLogController> >(); var accessAttempt = new AccessLog() { UserName = "******", EmailAddress = "*****@*****.**", DOB = DateTime.Now.AddYears(-1) }; mockService.Setup(service => service.VerifyNewRequestAsync(It.IsAny <AccessLog>())) .ReturnsAsync(false); var controller = new AccessLogController(mockService.Object, mockLogger.Object); // Act var result = await controller.Verify(accessAttempt); // Assert var viewResult = Assert.IsType <ViewResult>(result); Assert.IsAssignableFrom <AccessLog>(viewResult.ViewData.Model); }
public async Task Verify_ReturnsRedirect_WithSuccessfulInput() { // Arrange var mockService = new Mock <IAccessLogService>(); var mockLogger = new Mock <ILogger <AccessLogController> >(); mockService.Setup(service => service.VerifyNewRequestAsync(It.IsAny <AccessLog>())) .ReturnsAsync(true); var controller = new AccessLogController(mockService.Object, mockLogger.Object); // Act var result = await controller.Verify(It.IsAny <AccessLog>()); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", redirectToActionResult.ActionName); }