public async Task AddUsername_ReturnsRedirectToActionResult_WhenRelatedExists() { // Arrange FindByNameAsyncReturns = new User { Id = 1, UserName = "******" }; GetUserAsyncReturns = new User { Id = 2, UserName = "******" }; _context.UserRelationships.Add(new UserRelationship { RelatingUserId = 1, RelatedUserId = 2 }); // Act await _context.SaveChangesAsync(); var result = await ControllerSUT.AddUsername("admin"); // Assert var redirectToActionResult = Assert.IsAssignableFrom <RedirectToActionResult>(result); Assert.Equal("Index", redirectToActionResult.ActionName); Assert.IsAssignableFrom <string>(ControllerSUT.TempData["FriendInvite"]); }
public async Task AddUsername_ReturnsViewResult_WithModelError_WhenUsernamIsNullOrEmpty(string username) { // Arrange FindByNameAsyncReturns = new User { Id = 1, UserName = "******" }; // Act var result = await ControllerSUT.AddUsername(username); // Assert var viewResult = Assert.IsAssignableFrom <ViewResult>(result); Assert.IsAssignableFrom <ModelStateEntry>(ControllerSUT.ModelState["username"]); }
public async Task AddUsername_ReturnsViewResult_WithModelError_WhenUserIsNotFound() { // Arrange GetUserAsyncReturns = new User { Id = 2, UserName = null }; FindByNameAsyncReturns = null; // Act var result = await ControllerSUT.AddUsername("does not exist"); // Assert var viewResult = Assert.IsAssignableFrom <ViewResult>(result); Assert.IsAssignableFrom <ModelStateEntry>(ControllerSUT.ModelState["username"]); }
public async Task AddUsername_ReturnsViewResult_WithModelError_WhenUserIsItself() { // Arrange GetUserAsyncReturns = new User { Id = 1, UserName = "******" }; FindByNameAsyncReturns = new User { Id = 1, UserName = "******" }; // Act var result = await ControllerSUT.AddUsername("testing username comparison on Identity User"); // Assert var viewResult = Assert.IsAssignableFrom <ViewResult>(result); Assert.IsAssignableFrom <ModelStateEntry>(ControllerSUT.ModelState["username"]); }
public async Task AddUsername_ReturnsRedirectToActionResult_WhenRelatingIsAdded() { // Arrange FindByNameAsyncReturns = new User { Id = 1, UserName = "******" }; GetUserAsyncReturns = new User { Id = 2, UserName = "******" }; // Act var result = await ControllerSUT.AddUsername("admin"); // Assert var redirectToActionResult = Assert.IsAssignableFrom <RedirectToActionResult>(result); Assert.Equal("Index", redirectToActionResult.ActionName); Assert.IsAssignableFrom <string>(ControllerSUT.TempData["FriendInvite"]); }