public void It_should_be_able_to_read_the_value_out()
        {
            //  ARRANGE
            var mvc = new Framework();

            mvc.HttpContext.AddCookieFixture("firstName", "peter");

            //  ACT
            var result = mvc.HttpPost<SampleController, ContentResult>(c => c.Index(), null);

            //  ASSERT
            Assert.That(result.ActionResult.Content, Is.EqualTo("peter"));
        }
        public void It_should_add_error_to_ModelState()
        {
            //  ARRANGE
            var mvc = new Framework();
            var model = mvc.New<SampleModel>();

            model.Name = "ptran";   // greater than 5 characters.  should pass validation

            // ACT
            var result = mvc.HttpPost<SampleController, ViewResult>(c => c.Index(model), model);

            //  ASSERT
            Assert.True(result.ModelStateValidationResult.IsValid);
        }
        public void It_should_add_error_to_ModelState()
        {
            //  ARRANGE
            var mvc = new Framework();
            var model = mvc.New<SampleModel>();

            model.Name = "p";   // less then 5 characters.  should fail validation

            // ACT
            var result = mvc.HttpPost<SampleController, ViewResult>(c => c.Index(model), model);

            //  ASSERT
            var hasError = result.ModelStateValidationResult.HasError<SampleModel>(m => m.Name, "Invalid length.");
            Assert.True(hasError);
        }
        public void It_should_add_error_to_modelstate()
        {
            //  ARRANGE
            var mvc = new Framework();
            var model = mvc.New<SampleModel>();

            model.Name = null;

            //  ACT
            var result = mvc.HttpPost<SampleController, ViewResult>(c => c.Index(model), model);

            //  ASSERT
            var hasError = result.ModelStateValidationResult.HasError<SampleModel>(m => m.Name, "Name is required.");
            Assert.True(hasError);
        }
        public void It_should_display_an_error_message()
        {
            // ARRANGE
            var mvc = new Framework();
            var modelView = new CreateModelView();

            modelView.CategoryName = null;

            // ACT
            var result = mvc.HttpPost<CategoryController, ViewResult>(c => c.Create(modelView), modelView);
            var model = result.ActionResult.Model as CreateModelView;

            // ASSERT
            Assert.That(result.ModelStateValidationResult.HasError<CreateModelView>(mv => mv.CategoryName, "A category is required."));
        }