Ejemplo n.º 1
0
        public void PostPresenterInitilizingShouldReturnPostAttributes()
        {
            // Arrange
            string postTitle = null;
            CategoryViewModel postCategory = null;

            var postViewMock = new Mock<IPostView>();
            postViewMock.SetupSet(p => p.PostTitle = It.IsAny<string>()).Callback<string>((title) => postTitle = title);
            postViewMock.SetupSet(p => p.Category = It.IsAny<CategoryViewModel>()).Callback<CategoryViewModel>((category) => postCategory = category);

            var fakePostPresenter = new PostPresenter(postViewMock.Object, this.mocksContainer.DataMock.Object);

            // Act
            fakePostPresenter.Initialize("Gosho", "Test-Post-1");

            // Assert
            Assert.IsNotNull(postTitle);
            Assert.IsNotNull(postCategory);
        }
Ejemplo n.º 2
0
        public void LikingPostShouldAddNewLikeInTheRepo()
        {
            // Arrange
            string loggedUserId = "bbb";
            string ipAddress = "fakeIp";
            int postId = 1;
            var postAuthor = new AuthorViewModel { Id = "aaa" };
            var likes = new List<LikeViewModel>();

            var postViewMock = new Mock<IPostView>();
            postViewMock.Setup(v => v.Id).Returns(postId);
            postViewMock.Setup(v => v.Author).Returns(postAuthor);
            postViewMock.Setup(v => v.Likes).Returns(likes);
            postViewMock.SetupSet(v => v.Likes = It.IsAny<List<LikeViewModel>>())
                .Callback<List<LikeViewModel>>((list) => likes = list);

            var fakePostPresenter = new PostPresenter(postViewMock.Object, this.mocksContainer.DataMock.Object);

            // Act
            fakePostPresenter.LikePost(loggedUserId, ipAddress);

            // Assert
            Assert.AreEqual(3, this.mocksContainer.LikesRepoMock.Object.All().Count());
        }
Ejemplo n.º 3
0
        public void LikingPostByTheAuthorShouldThrowExeption()
        {
            // Arrange
            string loggedUserId = "aaa";
            string ipAddress = "";
            int postId = 1;
            var postAuthor = new AuthorViewModel { Id = loggedUserId };

            var postViewMock = new Mock<IPostView>();
            postViewMock.Setup(v => v.Id).Returns(postId);
            postViewMock.Setup(v => v.Author).Returns(postAuthor);

            var fakePostPresenter = new PostPresenter(postViewMock.Object, this.mocksContainer.DataMock.Object);

            // Act
            fakePostPresenter.LikePost(loggedUserId, ipAddress);
        }
Ejemplo n.º 4
0
        public void AddNewCommentWithValidDataShouldAddItToTheRepo()
        {
            // Arrange
            string author = "testAuthor";
            string content = "testContent";
            int postId = 1;
            List<CommentViewModel> comments = new List<CommentViewModel>();

            var postViewMock = new Mock<IPostView>();
            postViewMock.Setup(v => v.Id).Returns(postId);
            postViewMock.Setup(v => v.Comments).Returns(comments);
            postViewMock.SetupSet(v => v.Comments = It.IsAny<List<CommentViewModel>>())
                .Callback<List<CommentViewModel>>((list) => comments = list);

            var fakePostPresenter = new PostPresenter(postViewMock.Object, this.mocksContainer.DataMock.Object);

            // Act
            fakePostPresenter.AddComment(author, content);

            // Assert
            Assert.AreEqual(3, this.mocksContainer.CommentsRepoMock.Object.All().Count());
            Assert.AreEqual(1, comments.Count);
        }
Ejemplo n.º 5
0
        public void AddNewCommentWithNotValidDataShouldThrowExeption()
        {
            // Arrange
            string author = "";
            string content = "";
            int postId = 1;
            List<CommentViewModel> comments = new List<CommentViewModel>();

            var postViewMock = new Mock<IPostView>();
            postViewMock.Setup(v => v.Id).Returns(postId);
            postViewMock.Setup(v => v.Comments).Returns(comments);
            postViewMock.SetupSet(v => v.Comments = It.IsAny<List<CommentViewModel>>())
                .Callback<List<CommentViewModel>>((list) => comments = list);

            var fakePostPresenter = new PostPresenter(postViewMock.Object, this.mocksContainer.DataMock.Object);

            // Act
            fakePostPresenter.AddComment(author, content);
        }
Ejemplo n.º 6
0
 protected Post()
 {
     this.presenter = new PostPresenter(this);
 }