예제 #1
0
        public void ExtractAndSaveAllNewBlogPostsSavesAllNewBlogPosts()
        {
            // Arrange
            BlogInfo blogInfoA = new BlogInfo
            {
                Description = _blogA.Link,
                Title = _blogA.Title
            };
            BlogInfo blogInfoB = new BlogInfo
            {
                Description = _blogB.Link,
                Title = _blogB.Title
            };
            _wordPressBlogReaderMock.Setup(wp => wp.VerifyBlog(_blogA.Link)).Returns(blogInfoA);
            _wordPressBlogReaderMock.Setup(wp => wp.VerifyBlog(_blogB.Link)).Returns(blogInfoB);
            _wordPressBlogReaderMock.Setup(wp =>
                    wp.GetBlogPosts(_blogA.Link)).Returns(_postsNewForBlogA.AsQueryable());
            _wordPressBlogReaderMock.Setup(wp =>
                    wp.GetBlogPosts(_blogB.Link)).Returns(_postsNewForBlogB.AsQueryable());
            _postRepositoryMock.Setup(pr => pr.Any(It.IsAny<Expression<Func<Post, bool>>>())).Returns(false);

            // Act
            _blogService.ExtractAndSaveAllNewBlogPosts();

            // Assert
            // Verify that:
            //  Add is called for Post object the correct number of times
            //  unit of work is committed for each blog
            _postRepositoryMock.Verify(p => p.Add(It.IsAny<Post>()),
                                            Times.Exactly(_postsNewForBlogA.Length + _postsNewForBlogB.Length));
            _unitOfWorkMock.Verify(uow => uow.Commit(), Times.Exactly(_blogs.Length));
        }
        public void PutBlogApprovedChangedtoTrueReturnsHttpStatusCodeNoContentAndAddsPosts()
        {
            // Arrange
            _userRepositoryMock.Setup(pr => pr.FirstOrDefault(It.IsAny<Expression<Func<User, bool>>>()))
                                                                       .Returns(_users[_userAuthorizedIndexInArray]);
            BlogInfo blogInfo = new BlogInfo
            {
                Description = "Stupendous Blog",
                Title = "KDS Blog"
            };
            _wordPressBlogReaderMock.Setup(m => m.VerifyBlog(It.IsAny<string>())).Returns(blogInfo);

            // Act
            IHttpActionResult actionResult =
                _controller.PutBlog(
                    _blogIDNotApproved,
                     new BlogModel
                     {
                         BlogID = _blogIDNotApproved,
                         BlogType = BlogTypes.WordPress,
                         CreatedDate = new DateTime(2015, 12, 1, 10, 55, 32),
                         Approved = true,
                         AuthorEmail = "*****@*****.**",
                         AuthorName = "KDS",
                         Description = "Stupendous Blog",
                         Link = "XXXX",
                         Title = "KDS Blog"
                     });
            var statusCodeResult = actionResult as StatusCodeResult;

            // Assert
            // Verify that:
            //  GetByID is called just once
            //  Update is called for Blog object
            //  unit of work is committed at least once
            //  ExtractAndSaveBlogPosts is called
            //  result of update is HTTP status code with no content
            _blogRepositoryMock.Verify(b => b.GetByID(_blogIDNotApproved), Times.Once);
            _blogRepositoryMock.Verify(b => b.Update(It.IsAny<Blog>()), Times.Once);
            _blogServiceMock.Verify(bs => bs.ExtractAndSaveBlogPosts(It.IsAny<Blog>()), Times.Once);
            _unitOfWorkMock.Verify(uow => uow.Commit(), Times.AtLeastOnce);
            Assert.IsNotNull(actionResult);
            Assert.IsNotNull(statusCodeResult);
            Assert.AreEqual(statusCodeResult.StatusCode, HttpStatusCode.NoContent);
        }
        public void PostBlogAddsBlog()
        {
            // Arrange
            BlogInfo blogInfo = new BlogInfo
            {
                Description = "New Testing",
                Title = "New Testy's Blog"
            };
            _wordPressBlogReaderMock.Setup(m => m.VerifyBlog(It.IsAny<string>())).Returns(blogInfo);

            // Act
            IHttpActionResult actionResult =
                _controller.PostBlog(
                    new BlogModel
                    {
                        BlogID = 0,
                        BlogType = BlogTypes.WordPress,
                        CreatedDate = new DateTime(2015, 12, 2, 14, 55, 32),
                        Approved = false,
                        AuthorEmail = "*****@*****.**",
                        AuthorName = "TestNew McTesterson",
                        Description = "New Testing",
                        Link = "http://testy.wordpress.com",
                        Title = "New Testy's Blog"
                    });

            // Assert
            // Verify:
            //  Add is called just once with Blog object
            //  Unit of work is committed just once
            //  HTTP result is CreatedAtRouteNegotiatedContentResult
            //  Location header is set in created result
            _blogRepositoryMock.Verify(p => p.Add(It.IsAny<Blog>()), Times.Once);
            _unitOfWorkMock.Verify(uow => uow.Commit(), Times.Once);
            Assert.IsInstanceOfType
                    (actionResult, typeof(CreatedAtRouteNegotiatedContentResult<BlogModel>));
            var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult<BlogModel>;
            Assert.IsNotNull(createdResult);
            Assert.AreEqual(createdResult.RouteName, "DefaultApi");
        }
예제 #4
0
        public void ExtractBlogPostsReturnsBlogPosts()
        {
            // Arrange
            BlogInfo blogInfo = new BlogInfo
            {
                Description = _blogA.Description,
                Title = _blogA.Title
            };
            _wordPressBlogReaderMock.Setup(wp => wp.VerifyBlog(_blogA.Link)).Returns(blogInfo);
            _wordPressBlogReaderMock.Setup(wp =>
                        wp.GetBlogPosts(_blogA.Link)).Returns(_postsBlogA.AsQueryable());

            // Act
            IEnumerable<Post> posts = _blogService.ExtractBlogPosts(_blogs[_blogIDAWithPostsIndexInArray]);

            // Assert
            Assert.AreEqual(posts.Count(), _postsBlogA.Length);
        }
예제 #5
0
        public void ExtractAndSaveBlogPostsExtractsAndSavesBlogPosts()
        {
            // Arrange
            BlogInfo blogInfo = new BlogInfo
            {
                Description = _blogA.Description,
                Title = _blogA.Title
            };
            _wordPressBlogReaderMock.Setup(wp => wp.VerifyBlog(_blogA.Link)).Returns(blogInfo);
            _wordPressBlogReaderMock.Setup(wp =>
                        wp.GetBlogPosts(_blogA.Link)).Returns(_postsBlogA.AsQueryable());

            // Act
            _blogService.ExtractAndSaveBlogPosts(_blogA);

            // Assert
            // Verify that:
            //  Add is called for Post object the correct number of times
            //  unit of work is committed once
            _postRepositoryMock.Verify(p => p.Add(It.IsAny<Post>()), Times.Exactly(_postsBlogA.Length));
            _unitOfWorkMock.Verify(uow => uow.Commit(), Times.Once);
        }