public void FollowRemove_CountingRemove_Test() { var init = new InitializeMockContext(); var mock = init.mock; var followID = 1; var expectedFollowedCountInt = mock.Object.Users. Where(x => x.Id == mock.Object.UserFollowers. Where(y => y.Id == followID).First().FollowedUserId).First().FollowedCount; var expectedFollowingCountnewInt = mock.Object.Users. Where(x => x.Id == mock.Object.UserFollowers. Where(y => y.Id == followID).First().FollowingUserId).First().FollowingCount; var controller = new FollowersService(mock.Object, mapper); var editedCom = controller.FollowRemove(2, 1); mock.Verify(m => m.SaveChanges(), Times.Once()); Assert.AreEqual(expectedFollowedCountInt - 1, mock.Object.Users. Where(x => x.Id == mock.Object.UserFollowers. Where(y => y.Id == followID).First().FollowedUserId).First().FollowedCount); Assert.AreEqual(expectedFollowingCountnewInt - 1, mock.Object.Users. Where(x => x.Id == mock.Object.UserFollowers. Where(y => y.Id == followID).First().FollowingUserId).First().FollowingCount); }
public void GetFollowingPost_UserWithPosts_PostList() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new PostService(mock.Object, mapper, cloudinaryService); var editedCom = controller.GetFollowingPosts(2); Assert.AreEqual(4, editedCom.First().Id); }
public void RemoveImageLike_ValidLikeId_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new LikesService(mock.Object); controller.RemoveImageLike(2, 1); mock.Verify(m => m.SaveChanges(), Times.Once()); }
public void GetImages_UserImagesMostPopularTest() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new UsersService(mock.Object, new PostService(mock.Object, mapper, cloudinaryService), new FollowersService(mock.Object, mapper), new SignInService(mock.Object)); var result = controller.GetPosts(1, "most_popular"); var expected = 5; Assert.AreEqual(expected, result.First().Id); }
public void GetPost_NoLoggedUser_ReturnPost() { var init = new InitializeMockContext(); var mock = init.mock; var postService = new PostService(mock.Object, mapper, cloudinaryService); var result = postService.GetPost(-1, 1); var expected = false; Assert.AreEqual(expected, result.Liked); }
public void GetPost_ValidPostId_ReturnPost() { var init = new InitializeMockContext(); var mock = init.mock; var postService = new PostService(mock.Object, mapper, cloudinaryService); var result = postService.GetPost(1, 1); var expected = "link1"; Assert.AreEqual(expected, result.ImgLink); }
public void GetPostsByTag_Tags_MostRecent() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new PostService(mock.Object, mapper, cloudinaryService); var result = controller.GetPostsByTag("owoce").Count; var expected = 2; Assert.AreEqual(result, expected); }
public void GetComments_NoCommentsLiked_CheckNumber() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new PostCommentsService(mock.Object, mapper); var result = controller.GetComments(1, 2).First(); var expected = false; Assert.AreEqual(expected, result.Liked); }
public void GetSearch_NoElement_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new SearchController(mock.Object); var name = "dasasddasfgassad"; var searchList = controller.GetSearch(name); Assert.AreEqual(searchList.Count(), 0); }
public void GetComments_ValidPostId_CheckNumber() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new PostCommentsService(mock.Object, mapper); var result = controller.GetComments(1, 3).Count(); var expected = 2; Assert.AreEqual(expected, result); }
public void AddTags_NoTagInDb_AddTag() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new TagsService(mock.Object); controller.GetOrAddTag("Yellow", mock.Object); init.mockSetTags.Verify(m => m.Add(It.IsAny <Tags>()), Times.Once()); mock.Verify(m => m.SaveChanges(), Times.Once()); }
public void FollowRemove_FollowRemove_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new FollowersService(mock.Object, mapper); var editedCom = controller.FollowRemove(2, 1); mock.Verify(m => m.SaveChanges(), Times.Once()); init.mockSetUserFollowers.Verify(m => m.Remove(It.IsAny <UserFollowers>()), Times.Once()); }
public void GetAllPosts_MostPopular_MostPopular() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new PostService(mock.Object, mapper, cloudinaryService); var result2 = controller.GetAllPosts("most_popular"); var result = result2.Select(x => x.Title).First(); var expected = "Najkomentowszy "; Assert.AreEqual(expected, result); }
public void GetAllPosts_TheNewest_MostRecent() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new PostService(mock.Object, mapper, cloudinaryService); var result2 = controller.GetAllPosts("the_newest"); var result = result2.Select(x => x.Title).First(); var expected = "comm bez lików"; Assert.AreEqual(result, expected); }
public void CommentRemove_ValidId_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new PostCommentsService(mock.Object, mapper); var editedCom = controller.CommentRemove(1); mock.Verify(m => m.SaveChanges(), Times.Once()); init.mockSetComments.Verify(m => m.Remove(It.IsAny <PostComments>()), Times.Once()); init.mockSetCommentLikes.Verify(m => m.Remove(It.IsAny <CommentLikes>()), Times.Exactly(2)); }
public void GetPostTags_ValidPostId_Test() { var init = new InitializeMockContext(); var mock = init.mock; var postId = 1; var tagsService = new TagsService(mock.Object); var result = tagsService.GetTags(postId).Count; var expected = 2; Assert.AreEqual(expected, result); }
public void GetSearch_Tag_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new SearchController(mock.Object); var name = "banan"; var searchList = controller.GetSearch(name); Assert.AreEqual(name, searchList.First().TagName); Assert.AreEqual(searchList.Count(), 1); }
public void GetSearch_User_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new SearchController(mock.Object); var name = "zosia"; var searchList = controller.GetSearch(name); Assert.AreEqual(searchList.First().Name.ToLower(), name); Assert.AreEqual(searchList.Count(), 1); }
public void EditUserCredentials_WithBadPassword_ThrowUnauthEx() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new UsersService(mock.Object, new PostService(mock.Object, mapper, cloudinaryService), new FollowersService(mock.Object, mapper), new SignInService(mock.Object)); var expectedEmail = "Testowy Komentarz"; var expectedHash = "hashSW@"; Assert.Throws <UnauthorizedAccessException>(() => controller.EditUserCredentials(new EditUserCredentialsCommand { Id = 1, OldEmail = expectedEmail, OldPassword = expectedHash })); }
public void AddComment_ValidComment_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new PostCommentsService(mock.Object, mapper); controller.AddComment(new AddPostCommentCommand { Content = "Testowy Komentarz", PostId = 1, UserId = 1 }); init.mockSetComments.Verify(m => m.Add(It.IsAny <PostComments>()), Times.Once()); mock.Verify(m => m.SaveChanges(), Times.Once()); }
public void GetComments_MostPopular_CheckValid() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new PostCommentsService(mock.Object, mapper); var result = controller.GetComments(1, 3).First(); var expected = 1; var expected2 = "Zosia"; Assert.AreEqual(expected2, result.UserName); Assert.AreEqual(expected, result.LikeCount); }
public void AddFollow_ValidUser_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new FollowersService(mock.Object, mapper); controller.AddFollower(new AddUserFollowersCommand { FollowedUserId = 2, FollowingUserId = 1 }); init.mockSetUserFollowers.Verify(m => m.Add(It.IsAny <UserFollowers>()), Times.Once()); mock.Verify(m => m.SaveChanges(), Times.Once()); }
public void AddImageLike_DuplicateLike_ThrowEx() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new LikesService(mock.Object); Assert.Throws <NegotiatedContentResultException>(() => controller.AddImageLike(new PostLikes { UserId = 2, PostId = 1 }) ); }
public void AddImageLike_ValidLike_Test() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new LikesService(mock.Object); controller.AddImageLike(new PostLikes { UserId = 2, PostId = 3 }); init.mockSetPostLikes.Verify(m => m.Add(It.IsAny <PostLikes>()), Times.Once()); mock.Verify(m => m.SaveChanges(), Times.Once()); }
public void GetPostLikes_ValidPostId_ReturnsTwo() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new LikesService(mock.Object); var result = controller.GetPostLikes(1, 1); var expected = 2; var expected2 = "wyrak"; Assert.AreEqual(expected, result.Count()); Assert.AreEqual(expected2, result.First().Name); }
public void GetUser_NoLoggedUser_ReturnUserNoFOllowed() { var init = new InitializeMockContext(); var mock = init.mock; var usersService = new UsersService(mock.Object, new PostService(mock.Object, mapper, cloudinaryService), new FollowersService(mock.Object, mapper), new SignInService(mock.Object)); var result = usersService.GetUser(-1, 1); var expected2 = false; var expected = "Kasia"; Assert.AreEqual(expected2, result.Followed); Assert.AreEqual(result.Name, expected); }
public void AddTags_TagInDb_AddTag() { var init = new InitializeMockContext(); var mock = init.mock; var controller = new TagsService(mock.Object); var tagBanan = controller.GetOrAddTag("banan", mock.Object); mock.Verify(m => m.SaveChanges(), Times.Never()); init.mockSetTags.Verify(m => m.Add(It.IsAny <Tags>()), Times.Never()); var expected = 1; Assert.AreEqual(1, tagBanan.Count); }
public void SignOut_SignedUser_EraseToken() { var init = new InitializeMockContext(); var mock = init.mock; var signInService = new SignInService(mock.Object); var result = signInService.SignOut(new SignOutCommand() { UserId = 3 }); Assert.AreEqual(result, true); mock.Verify(m => m.SaveChanges(), Times.Once()); }
public void SignIn_ValidEmail_GenerateToken() { var init = new InitializeMockContext(); var mock = init.mock; var signInService = new SignInService(mock.Object); var result = signInService.SignIn(new SignInCommand() { Email = "*****@*****.**", Password = "******" }); Assert.AreNotEqual(result.Token, null); mock.Verify(m => m.SaveChanges(), Times.Once()); }
public void RemoveCommentLike_Counting_Test() { var init = new InitializeMockContext(); var mock = init.mock; var commentId = 1; var expectedLikeCountInt = mock.Object.PostComments.Where(x => x.Id == commentId).First().LikeCount; var controller = new LikesService(mock.Object); controller.RemoveCommentLike(2, 1); mock.Verify(m => m.SaveChanges(), Times.Once()); Assert.AreEqual(expectedLikeCountInt - 1, mock.Object.PostComments.Where(x => x.Id == commentId).First().LikeCount); }