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; }
public void IsAuthorizedFor_NullAuthorization_ReturnsTrue() { Authorization.Provider = null; controller = Substitute.ForPartsOf<BaseControllerProxy>(); Assert.Null(controller.AuthorizationProvider); Assert.True(controller.IsAuthorizedFor(null, null, null)); }
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); }