public async Task AddUser_ReturnsViewResult_WithModelError_WhenUsernamIsNullOrEmpty(int id) { // Arrange FindByNameAsyncReturns = new User { Id = 1, UserName = "******" }; // Act var result = await ControllerSUT.AddUser(id); // Assert var viewResult = Assert.IsAssignableFrom <ViewResult>(result); Assert.IsAssignableFrom <ModelStateEntry>(ControllerSUT.ModelState["username"]); }
public async Task AddUser_ReturnsViewResult_WithModelError_WhenUserIsNotFound() { // Arrange GetUserAsyncReturns = new User { Id = 2, UserName = null }; FindByNameAsyncReturns = null; // Act var result = await ControllerSUT.AddUser(0); // Assert var viewResult = Assert.IsAssignableFrom <ViewResult>(result); Assert.IsAssignableFrom <ModelStateEntry>(ControllerSUT.ModelState["username"]); }
public async Task AddUser_ReturnsRedirectToActionResult_WhenRelatingIsAdded() { // Arrange FindByNameAsyncReturns = new User { Id = 1, UserName = "******" }; GetUserAsyncReturns = new User { Id = 2, UserName = "******" }; // Act var result = await ControllerSUT.AddUser(0); // Assert var redirectToActionResult = Assert.IsAssignableFrom <RedirectToActionResult>(result); Assert.Equal("Index", redirectToActionResult.ActionName); Assert.IsAssignableFrom <string>(ControllerSUT.TempData["FriendInvite"]); }