예제 #1
0
        public void OnActionExecuted_get_LocalAndGlobalResources_for_IndexActionResult()
        {
            string viewResultName = "testView";
            string actionName     = "Index";
            string controllerName = "Home";

            // Arrange : Create actionExecutedContext
            var hp                    = Container.createHp();
            var homeController        = Container.createHomeController();
            var actionExecutedContext = FilterActionFake.FakeActionExecutedContext(homeController, false, controllerName, actionName);

            ResourceFilter resourceFilter = new ResourceFilter(); // Instantiate filter and set properties

            resourceFilter.LocalResources = Container.createIResource();
            resourceFilter.hp             = hp;

            // Act: Set view result and execute the onActionExecuted
            actionExecutedContext.Result = FilterActionFake.getViewResult(viewResultName, actionExecutedContext.Controller.ViewData);
            resourceFilter.OnActionExecuted(actionExecutedContext);

            // Assert
            var expectedlocalResource = Container.createIResource();

            expectedlocalResource.getResources(string.Format("{0}{1}", controllerName, actionName));

            var actualLocalResource = actionExecutedContext.Controller.ViewData[hp.getLocalResourceKey()] as IResource;

            Assert.IsTrue(compareTwoResources(expectedlocalResource, actualLocalResource), "Local resource is not set in viewdata.");
        }
예제 #2
0
        public void CheckModelState_onEnd_is_Ok()
        {
            CheckModelState checkModelState = new CheckModelState();
            string          viewName        = "invalidViewName";

            // Arrange
            checkModelState.GoToIfInvalidOnEnd = viewName;
            var FakeActionExecutedContext = FilterActionFake.FakeActionExecutedContext(Container.createHomeController());

            // Act
            checkModelState.OnActionExecuted(FakeActionExecutedContext);


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

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

            // Arrange
            checkModelState.GoToIfInvalidOnEnd = viewName;
            var actionExecuted = FilterActionFake.FakeActionExecutedContext(Container.createHomeController());

            // Act
            actionExecuted.Controller.ViewData.ModelState.AddModelError(testErrorMessage, testErrorMessage);
            checkModelState.OnActionExecuted(actionExecuted);

            // Assert
            var result = actionExecuted.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.");
        }
예제 #4
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.");
        }