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 TestEditPost_PostDoesNotExists()
        {
            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.EditPost(post));
            mockPostValidator.AssertPostExistsCalled();
        }