예제 #1
0
        public void TestEditPost_ValidData_Success()
        {
            var mockPostRepo        = new MockPostRepo();
            var mockPostValidator   = new MockPostValidator();
            var mockAuthorValidator = new MockAuthorValidator();
            var postDataAccess      = new PostDataAccess(mockPostRepo, mockPostValidator, new MockAuthorRepo(), mockAuthorValidator);
            var post         = new Post("OriginalTitle", new Author("OriginalAuthor", 0), "OriginalBody");
            var expectedPost = new Post("newTitle", new Author("newAuthor", 0), "newBody", post.Timestamp, post.PostID);
            var listOfPosts  = new List <Post>()
            {
                post
            };

            mockPostValidator.StubPostExists(true)
            .StubValidPost(true);
            mockPostRepo.StubGetAllPosts(listOfPosts)
            .StubTryEditPostBool(true)
            .StubTryEditPostResult(expectedPost);
            mockAuthorValidator.StubIsValidAuthor(true);
            var returnedPost = postDataAccess.EditPost(post);

            mockPostValidator.AssertPostExistsCalled();
            mockPostRepo.AssertGetAllPostsCalled();
            mockPostValidator.AssertIsValidPostCalled();
            mockPostRepo.AssertTryEditPostCalled();
            mockAuthorValidator.AssertIsValidAuthorCalled();
            Assert.NotNull(returnedPost);
            AssertPostsEqual(expectedPost, returnedPost);
        }
예제 #2
0
        public void TestDeletePost_InvalidPost_Failure()
        {
            var mockPostValidator = new MockPostValidator();
            var postDataAccess    = new PostDataAccess(new MockPostRepo(), mockPostValidator, new MockAuthorRepo(), new MockAuthorValidator());
            var post = new Post("", new Author("", 0), "");

            mockPostValidator.StubPostExists(false);

            Assert.Throws <ArgumentException>(() => postDataAccess.DeletePost(post));
            mockPostValidator.AssertPostExistsCalled();
        }
예제 #3
0
        public void TestEditPost_PostExistsButInvalidPost()
        {
            var mockPostValidator = new MockPostValidator();
            var postDataAccess    = new PostDataAccess(new MockPostRepo(), mockPostValidator, new MockAuthorRepo(), new MockAuthorValidator());
            var post = new Post("", new Author("", 0), "");

            mockPostValidator.StubPostExists(true)
            .StubValidPost(false);

            Assert.Throws <ArgumentException>(() => postDataAccess.EditPost(post));
            mockPostValidator.AssertPostExistsCalled();
            mockPostValidator.AssertIsValidPostCalled();
        }
예제 #4
0
        public void TestDeletePost_ValidData_Success()
        {
            var mockPostRepo      = new MockPostRepo();
            var mockPostValidator = new MockPostValidator();
            var postDataAccess    = new PostDataAccess(mockPostRepo, mockPostValidator, new MockAuthorRepo(), new MockAuthorValidator());
            var post        = new Post("", new Author("", 0), "");
            var listOfPosts = new List <Post>();

            listOfPosts.Add(post);
            mockPostValidator.StubPostExists(true);
            mockPostRepo.StubGetAllPosts(listOfPosts)
            .StubTryDeletePostBool(true)
            .StubTryDeletePostResult(post);
            var returnedPost = postDataAccess.DeletePost(post);

            mockPostValidator.AssertPostExistsCalled();
            mockPostRepo.AssertGetAllPostsCalled();
            mockPostRepo.AssertTryDeletePostCalled();
            Assert.NotNull(returnedPost);
            AssertPostsEqual(post, returnedPost);
        }