예제 #1
0
        public void CheckModelState_onStart_is_Ok()
        {
            CheckModelState checkModelState = new CheckModelState();
            string          viewName        = "invalidViewName";

            // Arrange
            checkModelState.GoToIfInvalidOnStart = viewName;
            var actionExecuting = FilterActionFake.FakeActionExecutingContext(Container.createHomeController());

            // Act
            checkModelState.OnActionExecuting(actionExecuting);


            // Assert
            var result = actionExecuting.Result as ViewResultBase;

            Assert.IsTrue(result == null, "It does not return the right view.");
        }
예제 #2
0
        public void CheckModelState_return_invalidView_onStart()
        {
            CheckModelState checkModelState  = new CheckModelState();
            string          viewName         = "invalidViewName";
            string          testErrorMessage = "testError";

            // Arrange
            checkModelState.GoToIfInvalidOnStart = viewName;
            var actionExecuting = FilterActionFake.FakeActionExecutingContext(Container.createHomeController());

            // Act
            actionExecuting.Controller.ViewData.ModelState.AddModelError(testErrorMessage, testErrorMessage);
            checkModelState.OnActionExecuting(actionExecuting);

            // Assert
            var result = actionExecuting.Result as ViewResultBase;

            Assert.AreEqual("invalidViewName", result.ViewName, "It does not return the right view.");
            Assert.IsTrue(result.ViewData.ModelState[testErrorMessage].Errors.Count > 0, "The error is not build.");
        }
예제 #3
0
        public void CheckModelState_return_json_onEnd()
        {
            CheckModelState checkModelState  = new CheckModelState();
            string          viewName         = "invalidViewName";
            string          testErrorMessage = "testError";

            // Arrange
            checkModelState.GoToIfInvalidOnStart = viewName;
            var FakeActionExecutingContext = FilterActionFake.FakeActionExecutingContext(Container.createHomeController(), true);

            // Act
            FakeActionExecutingContext.Controller.ViewData.ModelState.AddModelError(testErrorMessage, testErrorMessage);
            checkModelState.OnActionExecuting(FakeActionExecutingContext);

            // Assert
            var result = FakeActionExecutingContext.Result as HttpStatusCodeResult;

            Assert.IsTrue(result != null && result.StatusCode == (int)HttpStatusCode.BadRequest, "It does not return a bad request.");
            Assert.IsTrue(FakeActionExecutingContext.Controller.ViewData.ModelState[testErrorMessage].Errors.Count > 0, "The error is not build.");
        }