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(); }
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); }