public void AddPost_PostTitleAlreadyExist_notCreate() { //Arange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const int userId = 1; const string title = "abc"; const string content = "def"; const bool enableCom = false; _postsRepo .Query() .Returns(new List<Post> { new Post { Id = userId, Title = title } }.AsQueryable()); //Act postBo.AddNewPost(userId, title, content, enableCom); //Assert _postsRepo .Received(0).Create(Arg.Is<Post>(new Post())); }
public void AddPost_AddPostOnceWithCorrectParamValue() { //Arange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const int userId = 2; const string title = "abc"; const string content = "def"; const bool enableCom = false; _postsRepo .Query() .Returns(new List<Post> { new Post { Id = 1, Title = "cba" } }.AsQueryable()); //Act postBo.AddNewPost(userId, title, content, enableCom); //Assert _postsRepo .Received(1).Create(Arg.Is<Post>(x => x.UserId == userId && x.Title == title && x.Content == content && x.IsEnableComments == enableCom)); }
public void RatingVote_ratingCalculation_ratingCalculationIsCorrectAndPostRatingSaveOnce() { //Arange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const int userId = 1; const int postId = 1; const int rate = 3; //rating = (postRait * voutesNum + rate) / (voutesNum + 1); _postsRepo .GetItem(Arg.Is<int>(x => x >= 1)) .Returns(new Post { Id = postId, UserId = userId, Rating = 3, VotesNum = 2 }); _postRatigVotesRepo .Query() .Returns(new List<PostRatigVote> { new PostRatigVote { Id=2, UserId = 2, PostId = 2 } }.AsQueryable()); //Act postBo.RatingVote(userId, postId, rate); //Assert var post = _postsRepo.GetItem(postId); Assert.AreEqual(3, post.Rating); _postRatigVotesRepo .Received(1).Create(Arg.Is<PostRatigVote>(x => x.UserId == userId && x.PostId == postId)); _postRatigVotesRepo .Received(1).Save(); _postsRepo .Received(1).Save(); }
public void GetUserPostQuery_byUserID_postsWithCurrentUserIdReturndOnly() { //Arrange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const int currentUserId = 1; _postsRepo .Query() .Returns(new List<Post> { new Post { Id = 1, }, new Post { Id = 2, } }.AsQueryable()); //Act var posts = postBo.GetUserPostQuery(currentUserId, null); //Assert foreach (var p in posts) { Assert.AreEqual(currentUserId, p.UserId); } }
public void RatingVote_PostRatingVoteAlreadyExist_ratingMarkNotAdded() { //Arange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const int userId = 1; const int postId = 1; const int rate = 2; _postRatigVotesRepo .Query() .Returns(new List<PostRatigVote> { new PostRatigVote { Id = 1, UserId = 1, PostId = 1 } }.AsQueryable()); //Act postBo.RatingVote(userId, postId, rate); //Assert _postRatigVotesRepo .Received(0).Create(Arg.Is<PostRatigVote>(x => x.UserId == userId && x.PostId == postId)); }
public void GetPageUserPosts_GetByUserIdAndbyCurrentPageValueAndByPageSize_returnPostWithId3() { //Arrange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const int currentUserId = 1; const int currentPage = 2; const int pageSize = 1; _postsRepo .Query() .Returns(new List<Post> { new Post { Id = 1, UserId = 1 }, new Post { Id = 2, UserId = 2 }, new Post { Id = 3, UserId = 1 }, new Post { Id = 4, UserId = 1 } }.AsQueryable()); //Act var query = postBo.GetPageUserPosts(currentUserId,null, currentPage, pageSize); var post = query.FirstOrDefault(); //Assert Assert.AreEqual(3, post.Id); }
public void GetPagePosts_sortingByRating_postWithId2() { // Arrange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const PostOrderEnum sortVal = PostOrderEnum.ByRating; _postsRepo .Query() .Returns(new List<Post> { new Post { Id = 1, Date =DateTime.Parse("2015-12-31"), Rating = 1 }, new Post { Id = 2, Date =DateTime.Parse("2015-01-01"), Rating = 2 } }.AsQueryable()); // Act var firstPostInQuery = postBo.GetPagePosts(null, sortVal, 4, 1) .First(); // Assert Assert.AreEqual(2, firstPostInQuery.Id); }
public void EditPost_whenPostNotExist_notDone() { //Arange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const int postId = 1; const string title = "abc"; const string content = "def"; const bool enableCom = false; _postsRepo .GetItem(Arg.Is<int>(x => x >= 1)).ReturnsNull(); //Act postBo.EditPost(postId, title, content, enableCom); //Assert _postsRepo.Received(0).Save(); }
public void EditPost_EditPostOnceWithCorrectParamValue() { //Arange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const int postId = 1; const string title = "abc"; const string content = "def"; const bool enableCom = false; _postsRepo .GetItem(Arg.Is<int>(x => x >= 1)) .Returns(new Post { Id = postId, Title = "www", Content = "www", IsEnableComments = true }); //Act postBo.EditPost(postId, title, content, enableCom); //Assert var editedPost = _postsRepo.GetItem(postId); Assert.AreEqual(editedPost.Title, title); Assert.AreEqual(editedPost.Content, content); Assert.AreEqual(editedPost.IsEnableComments, enableCom); _postsRepo.Received(1).Save(); }
public void DeletePost_deletePostOnceWithCorrectParamValue() { //Arange var postBo = new PostsBo(_postsRepo, _postRatigVotesRepo, _avatarImgRepo); const int postId = 1; //Act postBo.DeletePost(postId); //Assert _postsRepo .Received(1).Delete(Arg.Is<int>(x => x == postId)); }