Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 11
0
        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());
        }
Exemplo n.º 12
0
        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());
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        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);
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 22
0
        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());
        }
Exemplo n.º 23
0
        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
            })
                                                             );
        }
Exemplo n.º 24
0
        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());
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        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);
        }
Exemplo n.º 27
0
        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);
        }
Exemplo n.º 28
0
        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());
        }
Exemplo n.º 29
0
        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());
        }
Exemplo n.º 30
0
        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);
        }