public void Save_IsNotValid_ReturnsFailureView()
        {
            //Arrange
            var controller = new ContentController { RavenSession = _documentStore.OpenSession() };
            var viewModel = new ContentViewModel { Id = "Slogan", Body = "My content view model" };
            controller.ModelState.AddModelError("Body", "Body is too long");

            //Act
            var result = (PartialViewResult)controller.Save(viewModel);

            //Assert
            result.ViewName.ShouldBe("Failure");
        }
        public void Save_IsNotValid_DoesNotStore()
        {
            //Arrange
            var controller = new ContentController { RavenSession = _documentStore.OpenSession() };
            var viewModel = new ContentViewModel { Id = "Slogan", Body = "My content view model" };
            controller.ModelState.AddModelError("Body", "Body is too long");

            //Act
            var result = controller.Save(viewModel);
            controller.RavenSession.SaveChanges();

            //Assert
            using (var session = _documentStore.OpenSession())
            {
                var content = session.Load<Content.Content>("Slogan");
                Assert.IsNull(content);
            }
        }
        public void Save_IsValid_ReturnsSuccessView()
        {
            //Arrange
            var controller = new ContentController { RavenSession = _documentStore.OpenSession() };
            var viewModel = new ContentViewModel { Id = "Slogan", Body = "My content view model" };

            //Act
            var result = (PartialViewResult)controller.Save(viewModel);

            //Assert
            result.ViewName.ShouldBe("Success");
        }
        public void Show_Exists_ReturnsViewModel()
        {
            //Arrange
            StoreSampleContent();

            var controller = new ContentController { RavenSession = _documentStore.OpenSession() };

            //Act
            var result = (PartialViewResult)controller.Show("Slogan");
            var model = (ContentViewModel)result.Model;

            //Assert
            Assert.AreEqual("A good slogan for your website", model.Body);
        }
        public void Show_DoesNotExist_ReturnsPlaceholderViewModel()
        {
            //Arrange
            var controller = new ContentController {RavenSession = _documentStore.OpenSession()};
            string contentName = "Slogan";

            //Act
            var result = (PartialViewResult)controller.Show(contentName);
            var model = (ContentViewModel)result.Model;

            //Assert
            Assert.AreEqual("Slogan", model.Body);
        }
        public void Save_IsValid_StoresInDatabase()
        {
            //Arrange
            var controller = new ContentController { RavenSession = _documentStore.OpenSession() };
            var viewModel = new ContentViewModel {Id = "Slogan", Body = "My content view model"};

            //Act
            controller.Save(viewModel);
            controller.RavenSession.SaveChanges();

            //Assert
            using (var session = _documentStore.OpenSession())
            {
                var content = session.Load<Content.Content>("Slogan");
                Assert.AreEqual("Slogan", content.Id);
                Assert.AreEqual("My content view model", content.Body);
            }
        }