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 = 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_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);
        }
コード例 #4
0
        public void It_should_display_a_list_of_categories()
        {
            // ARRANGE
            var mvc = new Framework();
            var repoStub = mvc.Inject<Mock<ICategoryRepository>>();
            var categoriesActual = new List<Category> {mvc.New<Category>()};

            repoStub.Setup(r => r.FindAll()).Returns(categoriesActual.AsQueryable());

            // ACT
            var result = mvc.HttpGet<HomeController, ViewResult>(c => c.Index());
            var categoriesExpected = result.ActionResult.Model as List<Category>;

            // ASSERT
            Assert.That(categoriesExpected.Count, Is.EqualTo(1));
            Assert.That(categoriesExpected[0].Id, Is.EqualTo(categoriesActual[0].Id));
        }