public void Delete_ReturnsNotFound_IdIsNull() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IFriendRepository>(); var controller = new FriendsController(mapper, mockUserManager.Object, mockRepo.Object); var result = controller.Delete(null); Assert.IsType <NotFoundResult>(result.Result); }
public void Remove_ReturnsRedirect() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IRequestRepository>(); mockRepo.Setup(repo => repo.RemoveRequest(It.IsAny <int>())); var controller = new RequestsController(mockRepo.Object, mockUserManager.Object, mapper); var result = controller.Revoke(It.IsAny <int>()); var redirectResult = Assert.IsType <RedirectToActionResult>(result.Result); Assert.Equal("Index", redirectResult.ActionName); }
public void DeleteConfirmed_ReturnBadRequest_BadDelete() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IFriendRepository>(); mockRepo.Setup(r => r.RemoveFriendAsync(It.IsAny <int>())) .ReturnsAsync(false); var controller = new FriendsController(mapper, mockUserManager.Object, mockRepo.Object); var result = controller.DeleteConfirmed(It.IsAny <int>()); Assert.IsType <BadRequestResult>(result.Result); }
public void Delete_ReturnsNotFound_FriendIsNull() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IFriendRepository>(); mockRepo.Setup(r => r.GetFriendAsync(It.IsAny <int>())) .ReturnsAsync(NullFriend()); var controller = new FriendsController(mapper, mockUserManager.Object, mockRepo.Object); var result = controller.Delete(null); Assert.IsType <NotFoundResult>(result.Result); }
public void DeleteConfirmed_ReturnRedirect_GoodDelete() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IFriendRepository>(); mockRepo.Setup(r => r.RemoveFriendAsync(It.IsAny <int>())) .ReturnsAsync(true); var controller = new FriendsController(mapper, mockUserManager.Object, mockRepo.Object); var result = controller.DeleteConfirmed(It.IsAny <int>()); var redirectResult = Assert.IsType <RedirectToActionResult>(result.Result); Assert.Equal("Index", redirectResult.ActionName); }
public void Delete_ReturnsNotFound_WithFriend() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IFriendRepository>(); mockRepo.Setup(r => r.GetFriendAsync(It.IsAny <int>())) .ReturnsAsync(GetFriend()); var controller = new FriendsController(mapper, mockUserManager.Object, mockRepo.Object); var result = controller.Delete(It.IsAny <int>()); var viewResult = Assert.IsType <ViewResult>(result.Result); var model = Assert.IsAssignableFrom <FriendViewModel>( viewResult.ViewData.Model); }
public void VerifyUserName_ReturnFalse() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); ApplicationUser friend = null; var mockRepo = new Mock <IFriendRepository>(); mockRepo.Setup(repo => repo.FindUserAsync(It.IsAny <string>())) .ReturnsAsync(friend); var controller = new FriendsController(mapper, mockUserManager.Object, mockRepo.Object); var result = controller.VerifyUserName(It.IsAny <string>()); var jsonResult = Assert.IsType <JsonResult>(result.Result); Assert.Equal(false, jsonResult.Value); }
public void Index_ReturnsAViewResult_WithAllFriends() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IRequestRepository>(); mockRepo.Setup(repo => repo.GetAllFriendRequests(It.IsAny <string>())) .ReturnsAsync(FriendControllerUnitTests.GetFriends()); var controller = new RequestsController(mockRepo.Object, mockUserManager.Object, mapper); var result = controller.Index(); var viewResult = Assert.IsType <ViewResult>(result.Result); var model = Assert.IsAssignableFrom <IEnumerable <FriendViewModel> >( viewResult.ViewData.Model); Assert.Equal(2, model.Count()); }
public void Create_ReturnsBadRequest_FailCreate() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IFriendRepository>(); mockRepo.Setup(repo => repo.AddFriendAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(false); FriendViewModel friendViewModel = new FriendViewModel(); friendViewModel.FriendUniqueName = "Test_User"; var controller = new FriendsController(mapper, mockUserManager.Object, mockRepo.Object); var result = controller.Create(friendViewModel); Assert.IsType <BadRequestResult>(result.Result); }
public void Index_ReturnsAViewResult_WithNoFriends() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); List <Friend> noFriends = new List <Friend>(); var mockRepo = new Mock <IFriendRepository>(); mockRepo.Setup(repo => repo.GetAllFriendsAsync(It.IsAny <string>())) .ReturnsAsync(noFriends); var controller = new FriendsController(mapper, mockUserManager.Object, mockRepo.Object); var result = controller.Index(); var viewResult = Assert.IsType <ViewResult>(result.Result); var model = Assert.IsAssignableFrom <IEnumerable <FriendViewModel> >( viewResult.ViewData.Model); Assert.Empty(model); }
public void Create_ReturnsRedirect_SuccessfulCreate() { var mockUserManager = UserMockService.BaseUser(); var mapper = MapperService.DefaultMapper(); var mockRepo = new Mock <IFriendRepository>(); mockRepo.Setup(repo => repo.AddFriendAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(true); FriendViewModel friendViewModel = new FriendViewModel(); friendViewModel.FriendUniqueName = "Test_User"; var controller = new FriendsController(mapper, mockUserManager.Object, mockRepo.Object); var result = controller.Create(friendViewModel); var redirectResult = Assert.IsType <RedirectToActionResult>(result.Result); Assert.Equal("Index", redirectResult.ActionName); }