Ejemplo n.º 1
0
        public BaseControllerTests()
        {
            HttpContextBase httpContext = HttpContextFactory.CreateHttpContextBase();
            Authorization.Provider = Substitute.For<IAuthorizationProvider>();

            controller = Substitute.ForPartsOf<BaseControllerProxy>();
            controller.ControllerContext = new ControllerContext();
            controller.ControllerContext.HttpContext = httpContext;
            controller.ControllerContext.Controller = controller;
            controller.ControllerContext.RouteData =
                httpContext.Request.RequestContext.RouteData;
            controller.Url = Substitute.For<UrlHelper>();

            controllerName = controller.RouteData.Values["controller"] as String;
            areaName = controller.RouteData.Values["area"] as String;
        }
Ejemplo n.º 2
0
        public void IsAuthorizedFor_NullAuthorization_ReturnsTrue()
        {
            Authorization.Provider = null;
            controller = Substitute.ForPartsOf<BaseControllerProxy>();

            Assert.Null(controller.AuthorizationProvider);
            Assert.True(controller.IsAuthorizedFor(null, null, null));
        }
Ejemplo n.º 3
0
        public void OnActionExecuted_MergesTempDataAlerts()
        {
            HttpContextBase context = controller.HttpContext;

            BaseControllerProxy mergedController = new BaseControllerProxy();
            mergedController.ControllerContext = new ControllerContext();
            mergedController.ControllerContext.HttpContext = context;
            mergedController.TempData = controller.TempData;
            mergedController.Alerts.AddError("Test1");

            IEnumerable<Alert> controllerAlerts = controller.Alerts;
            IEnumerable<Alert> mergedAlerts = mergedController.Alerts;

            controller.Alerts.AddError("Test2");
            controller.BaseOnActionExecuted(new ActionExecutedContext());
            mergedController.BaseOnActionExecuted(new ActionExecutedContext());

            IEnumerable<Alert> actual = controller.TempData["Alerts"] as AlertsContainer;
            IEnumerable<Alert> expected = controllerAlerts.Union(mergedAlerts);

            Assert.Equal(expected, actual);
        }