Inheritance: vlko.core.Base.BaseController
コード例 #1
0
ファイル: CommentControllerTest.cs プロジェクト: vlko/vlko
        public void Details()
        {
            // Arrange
            CommentController controller = new CommentController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            var id = RepositoryFactory.Command<ICommentData>().GetAllForAdmin()
                .OrderBy(item => item.Name)
                .ToPage(1, 1).First().Id;

            // Act
            ActionResult result = controller.Details(id);

            // Assert
            var model = result.AssertViewRendered().WithViewData<CommentCRUDModel>();

            Assert.AreEqual(id, model.Id);
        }
コード例 #2
0
ファイル: CommentControllerTest.cs プロジェクト: vlko/vlko
        public void Delete_post_success()
        {
            // Arrange
            CommentController controller = new CommentController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            var data = RepositoryFactory.Command<ICommentData>().GetAllForAdmin()
                .OrderBy(item => item.Name);
            var count = data.Count();

            var dataModel = RepositoryFactory.Command<ICommentCrud>().FindByPk(data.ToPage(1, 1).First().Id);

            // Act
            ActionResult result = controller.Delete(dataModel);

            // Assert
            result.AssertActionRedirect().ToAction("Index");

            Assert.AreEqual(count - 1, data.Count());
        }
コード例 #3
0
ファイル: CommentControllerTest.cs プロジェクト: vlko/vlko
        public void Index()
        {
            // Arrange
            CommentController controller = new CommentController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            // Act
            ActionResult result = controller.Index(new PagedModel<CommentForAdminViewModel>());

            // Assert
            var model = result.AssertViewRendered()
                .WithViewData<PagedModel<CommentForAdminViewModel>>();

            Assert.AreEqual(NumberOfGeneratedItems, model.Count);

            int i = 0;
            foreach (var comment in model)
            {
                Assert.AreEqual("Comment" + i, comment.Name);
                Assert.AreEqual("Static page" + i, comment.Text);
                ++i;
            }
            Assert.AreEqual(PagedModel<StaticTextViewModel>.DefaultPageItems, i);
        }
コード例 #4
0
ファイル: CommentControllerTest.cs プロジェクト: vlko/vlko
        public void Edit_post_success()
        {
            // Arrange
            CommentController controller = new CommentController();

            TestControllerBuilder builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            var id = RepositoryFactory.Command<ICommentData>().GetAllForAdmin()
                .OrderBy(item => item.Name)
                .ToPage(1, 1).First().Id;

            var dataModel = RepositoryFactory.Command<ICommentCrud>().FindByPk(id);

            dataModel.Name = "changed comment";
            dataModel.Text = "changed text";
            // Act
            ActionResult result = controller.Edit(dataModel);

            // Assert
            result.AssertActionRedirect().ToAction("Index");

            var changedItem = RepositoryFactory.Command<ICommentCrud>().FindByPk(id);
            Assert.IsNotNull(changedItem);
            Assert.AreEqual(dataModel.Id, changedItem.Id);
            Assert.AreEqual("changed comment", changedItem.Name);
            Assert.AreEqual("changed text", changedItem.Text);
        }