コード例 #1
0
        public void InitializeSetsControllerContext() {
            // Arrange
            ControllerBaseHelper helper = new ControllerBaseHelper();
            RequestContext requestContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());

            // Act
            helper.PublicInitialize(requestContext);

            // Assert
            Assert.AreSame(requestContext.HttpContext, helper.ControllerContext.HttpContext);
            Assert.AreSame(requestContext.RouteData, helper.ControllerContext.RouteData);
            Assert.AreSame(helper, helper.ControllerContext.Controller);
        }
コード例 #2
0
        public void InitializeSetsControllerContext()
        {
            // Arrange
            ControllerBaseHelper helper         = new ControllerBaseHelper();
            RequestContext       requestContext = new RequestContext(new Mock <HttpContextBase>().Object, new RouteData());

            // Act
            helper.PublicInitialize(requestContext);

            // Assert
            Assert.Same(requestContext.HttpContext, helper.ControllerContext.HttpContext);
            Assert.Same(requestContext.RouteData, helper.ControllerContext.RouteData);
            Assert.Same(helper, helper.ControllerContext.Controller);
        }
コード例 #3
0
        public void TempDataReturnsParentTempDataWhenInChildRequest()
        {
            // Arrange
            TempDataDictionary tempData    = new TempDataDictionary();
            ViewContext        viewContext = new ViewContext {
                TempData = tempData
            };
            RouteData routeData = new RouteData();

            routeData.DataTokens[ControllerContext.ParentActionViewContextToken] = viewContext;
            RequestContext       requestContext = new RequestContext(new Mock <HttpContextBase>().Object, routeData);
            ControllerBaseHelper controller     = new ControllerBaseHelper();

            controller.PublicInitialize(requestContext);

            // Act
            TempDataDictionary result = controller.TempData;

            // Assert
            Assert.Same(result, tempData);
        }
コード例 #4
0
        public void TempDataReturnsParentTempDataWhenInChildRequest() {
            // Arrange
            TempDataDictionary tempData = new TempDataDictionary();
            ViewContext viewContext = new ViewContext { TempData = tempData };
            RouteData routeData = new RouteData();
            routeData.DataTokens[ControllerContext.PARENT_ACTION_VIEWCONTEXT] = viewContext;
            RequestContext requestContext = new RequestContext(new Mock<HttpContextBase>().Object, routeData);
            ControllerBaseHelper controller = new ControllerBaseHelper();
            controller.PublicInitialize(requestContext);

            // Act
            TempDataDictionary result = controller.TempData;

            // Assert
            Assert.AreSame(result, tempData);
        }