public void SaveDeleteTest(
            [Values(true, false)] bool hasAssociatedPost)
        {
            var postID        = "TestPostID";
            var postCommentID = "TestPostCommentID";

            var postComment = new PostComment();

            postComment.ID = postCommentID;

            if (hasAssociatedPost)
            {
                var post = new Post();
                post.ID = postID;

                postComment.Post = post;
            }


            _postCommentRepositoryMock.Expect(r => r.Get(postCommentID)).Return(postComment);
            _postCommentRepositoryMock.Expect(r => r.Delete(postComment));
            _postCommentRepositoryMock.Expect(r => r.SubmitChanges());


            var result = TestedController.SaveDelete(postCommentID);

            if (hasAssociatedPost)
            {
                VerifyRedirectToRouteResult(result, expectedController: "Posts", expectedAction: "Detail", expectedID: postID);
            }
            else
            {
                VerifyRedirectToRouteResult(result, expectedAction: "Index");
            }
        }
        public void SaveDeleteTest()
        {
            var postCategoryID = "TestPostCategoryID";

            var postCategory = new PostCategory();
            postCategory.ID = postCategoryID;


            _postCategoryRepositoryMock.Expect(r => r.Get(postCategoryID)).Return(postCategory);
            _postCategoryRepositoryMock.Expect(r => r.Delete(postCategory));
            _postCategoryRepositoryMock.Expect(r => r.SubmitChanges());


            var result = TestedController.SaveDelete(postCategoryID);


            VerifyRedirectToRouteResult(result, expectedAction: "Index");
        }
Exemple #3
0
        public void SaveDeleteNotFoundTest()
        {
            var positionReportID = "TestPositionReportID";


            _positionReportRepositoryMock.Expect(r => r.Get(positionReportID)).Return(null);


            try
            {
                var result = TestedController.SaveDelete(positionReportID);

                Assert.Fail("404 not raised.");
            }
            catch (HttpException ex)
            {
                Assert.That(ex.GetHttpCode(), Is.EqualTo(404));
            }
        }