Esempio n. 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);
        }
Esempio n. 2
0
        public void TestSearchBy_InvalidData_Failure()
        {
            var mockPostRepo        = new MockPostRepo();
            var mockPostValidator   = new MockPostValidator();
            var mockAuthorRepo      = new MockAuthorRepo();
            var mockAuthorValidator = new MockAuthorValidator();
            var postDataAccess      = new PostDataAccess(mockPostRepo, mockPostValidator, mockAuthorRepo, mockAuthorValidator);

            //TODO
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        public void TestAddPost_InvalidPost_Failure(string title, string authorName, string body)
        {
            var mockPostValidator = new MockPostValidator();
            var postDataAccess    = new PostDataAccess(new MockPostRepo(), mockPostValidator, new MockAuthorRepo(), new MockAuthorValidator());
            var post = new Post(title, new Author(authorName, 0), body);

            mockPostValidator.StubValidPost(false);

            Assert.Throws <ArgumentException>(() => postDataAccess.AddPost(post));
            mockPostValidator.AssertIsValidPostCalled();
        }
Esempio n. 5
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();
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public void TestAddPost_ValidData_Success()
        {
            var mockPostRepo        = new MockPostRepo();
            var mockPostValidator   = new MockPostValidator();
            var mockAuthorValidator = new MockAuthorValidator();
            var postDataAccess      = new PostDataAccess(mockPostRepo, mockPostValidator, new MockAuthorRepo(), mockAuthorValidator);
            var author = new Author("author", 0);
            var post   = new Post("title", author, "body");

            mockPostValidator.StubValidPost(true);
            mockPostRepo.StubTryAddPostResult(post)
            .StubTryAddPostBool(true);
            mockAuthorValidator.StubIsValidAuthor(true);
            var returnedPost = postDataAccess.AddPost(post);

            mockPostValidator.AssertIsValidPostCalled();
            mockPostRepo.AssertTryAddPostCalled();
            mockAuthorValidator.AssertIsValidAuthorCalled();
            Assert.NotNull(returnedPost);
            AssertPostsEqual(post, returnedPost);
        }