Esempio n. 1
0
        public void EditTest()
        {
            var postID = "TestPostID";

            var post = new Post();

            post.ID = postID;

            var postCategoryList = new PagedList <PostCategory>(new PostCategory[] { }, 1, 10, 1);

            AddRole("Author");
            _postRepositoryMock.Expect(r => r.Get(postID)).Return(post);
            _postCategoryRepositoryMock.Expect(r => r.List(1, int.MaxValue)).Return(postCategoryList);


            var result = TestedController.Edit(postID);


            VerifyViewResult(result, "Edit", typeof(EditPostData));
            var resultModel = (EditPostData)((ViewResult)result).ViewData.Model;

            Assert.That(resultModel.EditMode, Is.EqualTo(EditMode.Edit));
            Assert.That(resultModel.Post, Is.EqualTo(post));
            Assert.That(resultModel.PostCategories, Is.SameAs(postCategoryList.Items));
        }
Esempio n. 2
0
        public void SaveExistingTest(
            [Values(false, true)] bool isPublished,
            [Values("1", null)] string categoryID,
            [Values(null, "2")] string newCategory,
            [Values(42.0, null)] double?latitude,
            [Values(15.0, null)] double?longitude,
            [Values(false, true)] bool setPublishDate,
            [Values(false, true)] bool setDateFrom,
            [Values(false, true)] bool setDateTo)
        {
            var editMode = EditMode.Edit;

            var postID      = "TestPostID";
            var title       = "A post title";
            var body        = string.Empty;
            var tags        = new string[] { "Tag1", "Tag2", "Tag3" };
            var publishDate = setPublishDate ? new DateTime?(new DateTime(2001, 1, 1)) : null;
            var dateFrom    = setDateFrom ? new DateTime?(new DateTime(2001, 1, 2)) : null;
            var dateTo      = setDateTo ? new DateTime?(new DateTime(2001, 1, 3)) : null;
            var position    = latitude != null && longitude != null ? new Position(latitude.Value, longitude.Value) : null;


            var post = new Post();

            post.ID       = postID;
            post.Title    = "oldTitle";
            post.Body     = "oldBody";
            post.Position = new Position(41, 14);
            post.Tags.Add("Tag2");
            post.Tags.Add("Tag4");


            var category = MockRepository.GenerateStub <PostCategory>();

            if (!String.IsNullOrEmpty(newCategory))
            {
                _postCategoryRepositoryMock.Expect(r => r.Create()).Return(category);
                _postCategoryRepositoryMock.Expect(
                    r => r.Save(category))
                .WhenCalled(
                    p => Assert.That(category.Title, Is.EqualTo(newCategory)));
            }
            else
            {
                category.ID = categoryID;
                _postCategoryRepositoryMock.Expect(r => r.Get(categoryID)).Return(category);
            }

            _postRepositoryMock.Expect(r => r.Get(postID)).Return(post);
            _postRepositoryMock.Expect(
                r => r.SubmitChanges())
            .WhenCalled(
                b => VerifyPost(post, postID, title, body, isPublished, position, category, tags, publishDate, dateFrom, dateTo));


            var result = TestedController.Save(editMode, postID, title, body, isPublished, latitude, longitude, categoryID, newCategory, tags.Concat(";"), publishDate, dateFrom, dateTo);


            VerifyRedirectToRouteResult(result, expectedAction: "Detail", expectedID: postID);
        }
        public void AddTest(
            [Values(null, "PostID")] string postID)
        {
            var postCommentID = Guid.Empty.ToString();

            var postComment = new PostComment();

            postComment.ID = postCommentID;

            _postCommentRepositoryMock.Expect(r => r.Create()).Return(postComment);

            Post post;

            if (postID != null)
            {
                post    = new Post();
                post.ID = postID;

                _postRepositoryMock.Expect(r => r.Get(postID)).Return(post);
            }
            else
            {
                post = null;
            }


            var result = TestedController.Add(postID);


            VerifyViewResult(result, "Edit", typeof(EditPostCommentData));
            var resultModel = (EditPostCommentData)((ViewResult)result).ViewData.Model;

            Assert.That(resultModel.EditMode, Is.EqualTo(EditMode.Add));
            Assert.That(resultModel.PostComment.Post, Is.EqualTo(post));
        }
Esempio n. 4
0
        public void IndexTest(
            [Values(10, 10, 10, 10, 10)] int pages,
            [Values(null, 10, 12, null, 10, 12)] int?requestedPage,
            [Values(1, 10, 10, 1, 10, 10)] int expectedPage,
            [Values(false, false, false, true, true, true)] bool asAuthor,
            [Values("text", null, null, null, null, null)] string mode,
            [Values("ListText", "List", "List", "List", "List", "List")] string expectedView)
        {
            var expectedPageSize      = TestedController.DefaultPageSize;
            var expectedRequestedPage = requestedPage == null ? 1 : requestedPage.Value;

            var postListPage = new PagedList <Post>(new Post[] { }, expectedPage, expectedPageSize, pages);

            if (asAuthor)
            {
                AddRole("Author");
            }

            if (asAuthor)
            {
                _postRepositoryMock.Expect(r => r.List(expectedRequestedPage, expectedPageSize)).Return(postListPage);
            }
            else
            {
                _postRepositoryMock.Expect(r => r.ListPublished(expectedRequestedPage, expectedPageSize)).Return(postListPage);
            }


            var result = TestedController.Index(requestedPage, mode);


            VerifyViewResult(result, expectedView, typeof(PagedList <Post>), postListPage);
        }
        public void SaveExistingTest(
            [Values(PostListOrder.Date, PostListOrder.Title)] PostListOrder postListOrder)
        {
            var editMode = EditMode.Edit;

            var postCategoryID = "TestPostCategoryID";
            var title = "A post category title";
            var body = string.Empty;

            var postCategory = new PostCategory();
            postCategory.ID = postCategoryID;
            postCategory.Title = "oldTitle";
            postCategory.Body = "oldBody";
            postCategory.PostListOrder = (PostListOrder)Int32.MaxValue;

            _postCategoryRepositoryMock.Expect(r => r.Get(postCategoryID)).Return(postCategory);
            _postCategoryRepositoryMock.Expect(
                r => r.SubmitChanges())
            .WhenCalled(
                b => VerifyPostCategory(postCategory, postCategoryID, title, body, postListOrder));


            var result = TestedController.Save(editMode, postCategoryID, title, body, postListOrder);


            VerifyRedirectToRouteResult(result, expectedAction: "Detail", expectedID: postCategoryID);
        }
        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");
            }
        }
Esempio n. 7
0
        public void SaveExistingTest(
            [Values(15.0, null)] double?latitude,
            [Values(42.0, null)] double?longitude,
            [Values(false, true)] bool setPositionDateTime)
        {
            var editMode = EditMode.Edit;

            var positionDateTime = setPositionDateTime ? new DateTime?(new DateTime(2001, 1, 1)) : null;
            var positionReportID = "TestPositionReportID";
            var comment          = "A position report comment";
            var position         = latitude != null && longitude != null ? new Position(latitude.Value, longitude.Value) : null;


            var positionReport = new PositionReport();

            positionReport.ID      = positionReportID;
            positionReport.Comment = "";


            _positionReportRepositoryMock.Expect(r => r.Get(positionReportID)).Return(positionReport);
            _positionReportRepositoryMock.Expect(
                r => r.SubmitChanges())
            .WhenCalled(
                b => VerifyPositionReport(positionReport, positionReportID, positionDateTime, comment, position));

            var result = TestedController.Save(editMode, positionReportID, positionDateTime, comment, latitude, longitude);


            VerifyRedirectToRouteResult(result, expectedAction: "Index");
        }
Esempio n. 8
0
        public void SaveWithInvalidEditModeTest()
        {
            var editMode = (EditMode)Int32.MaxValue;

            var postID = Guid.Empty.ToString();
            var title  = "A post title";
            var body   = string.Empty;
            var tags   = new[] { "Tag1", "Tag2", "Tag3" };

            var post = new Post();

            post.ID = postID;


            try
            {
                var result = TestedController.Save(editMode, postID, title, body, false, null, null, null, null, tags.Concat(";"), null, null, null);

                Assert.Fail("ArgumentException not raised.");
            }
            catch (ArgumentException ex)
            {
                Assert.That(ex.ParamName, Is.EqualTo("editMode"));
            }
        }
        public void SaveNewTest(
            [Values(PostListOrder.Date, PostListOrder.Title)] PostListOrder postListOrder)
        {
            var editMode = EditMode.Add;

            var postCategoryID = Guid.Empty.ToString();
            var title = "A post category title";
            var body = string.Empty;

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

            _postCategoryRepositoryMock.Expect(r => r.Create()).Return(postCategory);
            _postCategoryRepositoryMock.Expect(r => r.Save(postCategory));
            _postCategoryRepositoryMock.Expect(
                r => r.SubmitChanges())
            .WhenCalled(
                b => VerifyPostCategory(postCategory, postCategoryID, title, body, postListOrder));


            var result = TestedController.Save(editMode, postCategoryID, title, body, postListOrder);


            VerifyRedirectToRouteResult(result, expectedAction: "Detail", expectedID: postCategoryID);
        }
        public void ShouldReturnBaseServiceResultSuccess()
        {
            BaseServiceResult result = TestedController.Update(It.IsAny <UpdateCommentModel>());

            Assert.NotNull(result);
            Assert.True(result.IsSuccess);
            Assert.Empty(result.ErrorMessage);
        }
        public void ShouldReturnBaseServiceResultSuccess()
        {
            BaseServiceResult result = TestedController.Delete(It.IsAny <Guid>());

            Assert.NotNull(result);
            Assert.True(result.IsSuccess);
            Assert.Empty(result.ErrorMessage);
        }
Esempio n. 12
0
        public void ShouldReturnBaseServiceResultSuccess()
        {
            BaseServiceResult <string> result = TestedController.GetDescription(It.IsAny <Guid>());

            Assert.NotNull(result);
            Assert.True(result.IsSuccess);
            Assert.Empty(result.ErrorMessage);
        }
Esempio n. 13
0
        public void ShouldReturnBaseServiceResultSuccess()
        {
            BaseServiceResult <ExtendedCommentModel> result = TestedController.Get(It.IsAny <Guid>());

            Assert.NotNull(result);
            Assert.True(result.IsSuccess);
            Assert.Empty(result.ErrorMessage);
        }
Esempio n. 14
0
        public void ShouldReturnBaseServiceResultSuccess()
        {
            BaseServiceResult <IEnumerable <CommentModel> > result = TestedController.Get();

            Assert.NotNull(result);
            Assert.True(result.IsSuccess);
            Assert.Empty(result.ErrorMessage);
        }
Esempio n. 15
0
        public void ShouldReturnFalseWhenReadOnlyModeIsFalse()
        {
            SettingReadOnlyMode = false;

            var result = TestedController.IsReadOnly();

            Assert.NotNull(result);
            Assert.False(result.Result);
        }
Esempio n. 16
0
        public void ShouldReturnBaseServiceResultSuccess()
        {
            AddCommentModel model = null;

            BaseServiceResult <Guid> result = TestedController.Add(model);

            Assert.NotNull(result);
            Assert.True(result.IsSuccess);
            Assert.Empty(result.ErrorMessage);
        }
Esempio n. 17
0
        public void WidgetTest()
        {
            var albumListPage = new PagedList <AlbumSummary>(new AlbumSummary[] { }, 1, 1, 1);

            _pictureRepositoryMock.Expect(r => r.ListAlbums(1, 1)).Return(albumListPage);


            var result = TestedController.Widget();


            VerifyViewResult(result, "LatestAlbumsWidget", typeof(PagedList <AlbumSummary>), albumListPage);
        }
Esempio n. 18
0
        public void WidgetTest()
        {
            var tags = new TagSummary[] { };

            _postRepositoryMock.Expect(r => r.ListTags()).Return(tags);


            var result = TestedController.Widget();


            VerifyViewResult(result, "SearchWidget", typeof(IEnumerable <TagSummary>), tags);
        }
Esempio n. 19
0
        public void WidgetTest()
        {
            var postListPage = new PagedList <Post>(new Post[] { }, 1, 10, 1);

            _postRepositoryMock.Expect(r => r.ListPublished(1, 10)).Return(postListPage);


            var result = TestedController.Widget();


            VerifyViewResult(result, "LatestPostsWidget", typeof(PagedList <Post>), postListPage);
        }
        public void WidgetTest()
        {
            var positionReport         = new PositionReport();
            var positionReportListPage = new PagedList <PositionReport>(new [] { positionReport }, 1, 1, 1);

            _positionReportRepositoryMock.Expect(r => r.ListPublished(1, 1)).Return(positionReportListPage);


            var result = TestedController.Widget();


            VerifyViewResult(result, "LatestPositionsWidget", typeof(PositionReport), positionReport);
        }
        public void WidgetTest()
        {
            var postCategories       = new PostCategory[] { };
            var postCategoryListPage = new PagedList <PostCategory>(postCategories, 1, 10, 1);

            _postCategoryRepositoryMock.Expect(r => r.List(1, int.MaxValue)).Return(postCategoryListPage);


            var result = TestedController.Widget();


            VerifyViewResult(result, "PostCategoriesListWidget", typeof(IEnumerable <PostCategory>), postCategories);
        }
Esempio n. 22
0
        public void FeedTest(
            [Values(FeedFormat.Atom, FeedFormat.Rss)] FeedFormat format)
        {
            _feedServiceMock.Expect(m => m.CreateFeed(format, TestedController.Url)).Return(_syndicationFeedFormaterMock);
            _syndicationFeedFormaterMock.Expect(m => m.WriteTo(null)).IgnoreArguments()
            .WhenCalled(c => ((XmlWriter)c.Arguments[0]).WriteRaw("<feed/>"));


            var result = TestedController.GetFeed(format);


            VerifyContentResult(result, "text/xml", "<feed/>");
        }
        public void ReplyTest(
            [Values(null, "TestPostID")] string postID)
        {
            Post post;

            if (postID != null)
            {
                post    = new Post();
                post.ID = postID;
            }
            else
            {
                post = null;
            }

            var originalPostCommentID = "TestPostCommentID";

            var originalPostComment = new PostComment();

            originalPostComment.Post  = post;
            originalPostComment.ID    = originalPostCommentID;
            originalPostComment.Title = "Original title";
            originalPostComment.Body  = "Original body";


            var postCommentID = Guid.Empty.ToString();

            var postComment = new PostComment();

            postComment.ID = postCommentID;

            _postCommentRepositoryMock.Expect(r => r.Get(originalPostCommentID)).Return(originalPostComment);
            if (postID != null)
            {
                _postRepositoryMock.Expect(r => r.Get(postID)).Return(post);
            }
            _postCommentRepositoryMock.Expect(r => r.Create()).Return(postComment);

            var result = TestedController.Reply(originalPostCommentID);


            VerifyViewResult(result, "Edit", typeof(EditPostCommentData));
            var resultModel = (EditPostCommentData)((ViewResult)result).ViewData.Model;

            Assert.That(resultModel.EditMode, Is.EqualTo(EditMode.Add));
            Assert.That(resultModel.PostComment.Post, Is.EqualTo(originalPostComment.Post));
            Assert.That(resultModel.PostComment.Title, Is.EqualTo("Re: Original title"));
            Assert.That(resultModel.PostComment.Body, Is.EqualTo(Utils.QuoteBody(originalPostComment.Body)));
        }
        public void DetailTest()
        {
            var postCategoryID = "TestPostCategoryID";

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


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


            var result = TestedController.Detail(postCategoryID);


            VerifyViewResult(result, "Detail", typeof(PostCategory), postCategory);
        }
Esempio n. 25
0
        public void DeleteTest()
        {
            var positionReportID = "TestPositionReportID";

            var positionReport = new PositionReport();

            positionReport.ID = positionReportID;


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


            var result = TestedController.Delete(positionReportID);


            VerifyViewResult(result, "ConfirmDelete", typeof(PositionReport), positionReport);
        }
Esempio n. 26
0
        public void AddTest()
        {
            var positionReport = new PositionReport();

            AddRole("Author");
            _positionReportRepositoryMock.Expect(r => r.Create()).Return(positionReport);


            var result = TestedController.Add();


            VerifyViewResult(result, "Edit", typeof(EditPositionReportData));
            var resultModel = (EditPositionReportData)((ViewResult)result).ViewData.Model;

            Assert.That(resultModel.EditMode, Is.EqualTo(EditMode.Add));
            Assert.That(resultModel.PositionReport, Is.EqualTo(positionReport));
        }
Esempio n. 27
0
        public void DetailTest()
        {
            var videoID = "TestVideoID";

            var video = new Video();

            video.ID = videoID;


            _videoRepositoryMock.Expect(r => r.GetVideo(videoID)).Return(video);


            var result = TestedController.Detail(videoID);


            VerifyViewResult(result, "Detail", typeof(Video), video);
        }
Esempio n. 28
0
        public void PrintTest()
        {
            var postID = "TestPostID";

            var post = new Post();

            post.ID = postID;


            _postRepositoryMock.Expect(r => r.Get(postID)).Return(post);


            var result = TestedController.Print(postID);


            VerifyViewResult(result, "Print", typeof(Post), post);
        }
        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");
        }
Esempio n. 30
0
        public void IndexTest(
            [Values(10, 10, 10, 10, 10)] int pages,
            [Values(null, 10, 12, null, 10, 12)] int?requestedPage,
            [Values(1, 10, 10, 1, 10, 10)] int expectedPage)
        {
            var expectedPageSize      = TestedController.DefaultPageSize;
            var expectedRequestedPage = requestedPage == null ? 1 : requestedPage.Value;

            var positionReportListPage = new PagedList <PositionReport>(new PositionReport [] { }, expectedPage, expectedPageSize, pages);

            _positionReportRepositoryMock.Expect(r => r.List(expectedRequestedPage, expectedPageSize)).Return(positionReportListPage);


            var result = TestedController.Index(requestedPage);


            VerifyViewResult(result, "List", typeof(PagedList <PositionReport>), positionReportListPage);
        }