예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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());
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }