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); }
public void TestGetPostById_ValidID_Success() { var mockPostRepo = new MockPostRepo(); var postDataAccess = new PostDataAccess(mockPostRepo, new MockPostValidator(), new MockAuthorRepo(), new MockAuthorValidator()); var post = new Post("", new Author("", 0), ""); var listOfPosts = new List <Post>() { post }; mockPostRepo.StubGetAllPosts(listOfPosts); var returnedPost = postDataAccess.GetPostById(post.PostID); mockPostRepo.AssertGetAllPostsCalled(); Assert.NotNull(returnedPost); AssertPostsEqual(post, returnedPost); }
public void TestGetAllPosts() { var mockPostRepo = new MockPostRepo(); var postDataAccess = new PostDataAccess(mockPostRepo, new MockPostValidator(), new MockAuthorRepo(), new MockAuthorValidator()); var post = new Post("", new Author("", 0), ""); var listOfPosts = new List <Post>() { post }; mockPostRepo.StubGetAllPosts(listOfPosts); var returnedListOfPosts = postDataAccess.GetAllPosts(); mockPostRepo.AssertGetAllPostsCalled(); Assert.Equal(listOfPosts.Count, returnedListOfPosts.Count); AssertPostsEqual(listOfPosts[0], returnedListOfPosts[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); }
public void TestGetSortedListOfPosts(PostComponent postComp) { var mockPostRepo = new MockPostRepo(); var postDataAccess = new PostDataAccess(mockPostRepo, new MockPostValidator(), new MockAuthorRepo(), new MockAuthorValidator()); var aPost = new Post("AAA", new Author("AAA", 0), "AAA", Convert.ToDateTime("1111-01-01T11:11:11.1111111Z"), Guid.Parse("11111111-1111-1111-1111-111111111111")); var bPost = new Post("BBB", new Author("BBB", 1), "BBB", Convert.ToDateTime("1112-02-02T12:22:22.2222222Z"), Guid.Parse("22222222-2222-2222-2222-222222222222")); var cPost = new Post("CCC", new Author("CCC", 2), "CCC", Convert.ToDateTime("1113-03-03T13:33:33.3333333Z"), Guid.Parse("33333333-3333-3333-3333-333333333333")); var listOfPosts = new List <Post>() { cPost, aPost, bPost }; mockPostRepo.StubGetAllPosts(listOfPosts); var returnedListOfPosts = postDataAccess.GetSortedListOfPosts(postComp); mockPostRepo.AssertGetAllPostsCalled(); Assert.Equal(listOfPosts.Count, returnedListOfPosts.Count); AssertPostsEqual(aPost, returnedListOfPosts[0]); AssertPostsEqual(bPost, returnedListOfPosts[1]); AssertPostsEqual(cPost, returnedListOfPosts[2]); }