public async Task BlogController_New_For_Post_Does_Not_Add_Post_If_Invalid()
        {
            // Arrange
            DateTime now = DateTime.UtcNow;

            now = now.AddMilliseconds(now.Millisecond * -1);

            NewPostViewModel model = new NewPostViewModel();

            using (BlogController target = new BlogController())
            {
                target.ModelState.AddModelError("Body", "A body must be specified.");

                // Act
                ActionResult result = await target.New(model);

                // Assert
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(ViewResult));

                ViewResult view = result as ViewResult;

                Assert.IsNotNull(view.Model);
                Assert.AreSame(model, view.Model);
                Assert.AreEqual(string.Empty, view.ViewName);
            }
        }
        public void BlogController_New_For_Get_Returns_Correct_View()
        {
            // Arrange
            using (BlogController target = new BlogController())
            {
                // Act
                ActionResult result = target.New();

                // Assert
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(ViewResult));

                ViewResult view = result as ViewResult;

                Assert.AreEqual(string.Empty, view.ViewName);
            }
        }
        public async Task BlogController_New_For_Post_Adds_Post_If_Valid()
        {
            // Arrange
            DateTime now = DateTime.UtcNow;

            now = now.AddMilliseconds(now.Millisecond * -1);

            NewPostViewModel model = new NewPostViewModel()
            {
                Title   = "New Blog Post Title",
                Body    = "This is my blog post about things.",
                Preview = "This is a preview.",
            };

            // Use the shared database as this test only inserts
            // so other tests cannot interfer with its asserts.
            using (BlogController target = CreateTarget())
            {
                // Act
                ActionResult result = await target.New(model);

                // Assert
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(ViewResult));

                ViewResult view = result as ViewResult;

                Assert.IsNotNull(view.Model);
                Assert.IsInstanceOfType(view.Model, typeof(BlogPostViewModel));
                Assert.AreEqual("Post", view.ViewName);

                BlogPostViewModel viewModel = view.Model as BlogPostViewModel;

                Assert.AreEqual(model.Body, viewModel.Body);
                Assert.AreNotEqual(0, viewModel.Id);
                Assert.AreEqual(model.Preview, viewModel.Preview);
                Assert.IsTrue(viewModel.PublishedAt >= now);
                Assert.AreEqual(model.Title, viewModel.Title);
            }
        }
        public async Task BlogController_New_For_Post_Does_Not_Add_Post_If_Invalid()
        {
            // Arrange
            DateTime now = DateTime.UtcNow;
            now = now.AddMilliseconds(now.Millisecond * -1);

            NewPostViewModel model = new NewPostViewModel();

            using (BlogController target = new BlogController())
            {
                target.ModelState.AddModelError("Body", "A body must be specified.");

                // Act
                ActionResult result = await target.New(model);

                // Assert
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(ViewResult));

                ViewResult view = result as ViewResult;

                Assert.IsNotNull(view.Model);
                Assert.AreSame(model, view.Model);
                Assert.AreEqual(string.Empty, view.ViewName);
            }
        }
        public void BlogController_New_For_Get_Returns_Correct_View()
        {
            // Arrange
            using (BlogController target = new BlogController())
            {
                // Act
                ActionResult result = target.New();

                // Assert
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(ViewResult));

                ViewResult view = result as ViewResult;

                Assert.AreEqual(string.Empty, view.ViewName);
            }
        }