public void ExecuteRequest_ReleasesController_After_Executing() { // Arrange var app = new ModuleApplication(); var controller = new Mock <IDnnController>(); var controllerFactory = SetupControllerFactory(controller.Object); app.ControllerFactory = controllerFactory.Object; ModuleRequestContext moduleRequestContext = CreateModuleContext(ControllerName, ActionName); // Act ModuleRequestResult result = app.ExecuteRequest(moduleRequestContext); // Assert controllerFactory.Verify(cf => cf.ReleaseController(controller.Object)); }
public void ExecuteRequest_Throws_InvalidOperationException_If_Controller_Has_NonStandard_Action_Invoker() { // Arrange var app = new ModuleApplication(); var controller = new Mock <Controller>(); var invoker = new Mock <IActionInvoker>(); controller.Object.ActionInvoker = invoker.Object; var controllerFactory = SetupControllerFactory(controller.Object); app.ControllerFactory = controllerFactory.Object; ModuleRequestContext moduleRequestContext = CreateModuleContext(ControllerName, ActionName); // Act and Assert Assert.Throws <InvalidOperationException>(() => app.ExecuteRequest(moduleRequestContext)); }
private ModuleRequestContext GetModuleRequestContext(HttpContextBase httpContext) { var module = ModuleContext.Configuration; //TODO DesktopModuleControllerAdapter usage is temporary in order to make method testable var desktopModule = DesktopModuleControllerAdapter.Instance.GetDesktopModule(module.DesktopModuleID, module.PortalID); var defaultControl = ModuleControlControllerAdapter.Instance.GetModuleControlByControlKey("", module.ModuleDefID); var defaultRouteData = ModuleRoutingProvider.Instance().GetRouteData(null, defaultControl); var moduleApplication = GetModuleApplication(desktopModule, defaultRouteData); RouteData routeData; if (String.IsNullOrEmpty(_controlKey)) { _controlKey = httpContext.Request.QueryString.GetValueOrDefault("ctl", String.Empty); } var moduleId = httpContext.Request.QueryString.GetValueOrDefault("moduleId", -1); if (moduleId != ModuleContext.ModuleId && String.IsNullOrEmpty(_controlKey)) { //Set default routeData for module that is not the "selected" module routeData = defaultRouteData; } else { var control = ModuleControlControllerAdapter.Instance.GetModuleControlByControlKey(_controlKey, module.ModuleDefID); routeData = ModuleRoutingProvider.Instance().GetRouteData(httpContext, control); } var moduleRequestContext = new ModuleRequestContext { DnnPage = Page, HttpContext = httpContext, ModuleContext = ModuleContext, ModuleApplication = moduleApplication, RouteData = routeData }; return(moduleRequestContext); }
public void ExecuteModule_Returns_Result_Of_Executing_ModuleApplication() { // Arrange var engine = new ModuleExecutionEngine(); var expected = new ModuleRequestResult(); var moduleApp = new Mock <ModuleApplication>(); moduleApp.Setup(app => app.ExecuteRequest(It.IsAny <ModuleRequestContext>())) .Returns(expected); var requestContext = new ModuleRequestContext() { ModuleApplication = moduleApp.Object }; // Act ModuleRequestResult actual = engine.ExecuteModule(requestContext); // Assert Assert.AreSame(expected, actual); }
private ModuleRequestContext GetModuleRequestContext(HttpContextBase httpContext) { var moduleInfo = httpContext.Request.FindModuleInfo(); var moduleContext = new ModuleInstanceContext() { Configuration = moduleInfo }; var desktopModule = DesktopModuleControllerAdapter.Instance.GetDesktopModule(moduleInfo.DesktopModuleID, moduleInfo.PortalID); var moduleRequestContext = new ModuleRequestContext { HttpContext = httpContext, ModuleContext = moduleContext, ModuleApplication = new ModuleApplication(this.RequestContext, DisableMvcResponseHeader) { ModuleName = desktopModule.ModuleName, FolderPath = desktopModule.FolderName, }, }; return(moduleRequestContext); }
public void ExecuteRequest_ReleasesController_Even_If_It_Throws_An_Exception() { // Arrange var app = new ModuleApplication(); var controller = new Mock <IDnnController>(); controller.Setup(c => c.Execute(It.IsAny <RequestContext>())) .Throws(new Exception("Uh Oh!")); var controllerFactory = SetupControllerFactory(controller.Object); app.ControllerFactory = controllerFactory.Object; ModuleRequestContext moduleRequestContext = CreateModuleContext(ControllerName, ActionName); // Act (and verify the exception is thrown; also supresses the exception so it doesn't fail the test) Assert.Throws <Exception>(() => app.ExecuteRequest(moduleRequestContext)); // Assert controllerFactory.Verify(f => f.ReleaseController(controller.Object)); }
public void ExecuteRequest_Calls_ControllerFactory_To_Construct_Controller() { // Arrange var app = new ModuleApplication(); var controllerFactory = new Mock <IControllerFactory>(); RequestContext actualRequestContext = null; controllerFactory.Setup(f => f.CreateController(It.IsAny <RequestContext>(), ControllerName)) .Callback <RequestContext, string>((c, n) => actualRequestContext = c) .Returns(new Mock <IDnnController>().Object); app.ControllerFactory = controllerFactory.Object; ModuleRequestContext moduleRequestContext = CreateModuleContext(ControllerName, ActionName); // Act app.ExecuteRequest(moduleRequestContext); // Assert controllerFactory.Verify(f => f.CreateController(It.IsAny <RequestContext>(), ControllerName)); Assert.AreSame(moduleRequestContext.HttpContext, actualRequestContext.HttpContext); }
public void ExecuteRequest_Returns_Result_And_ControllerContext_From_Controller() { // Arrange var app = new ModuleApplication(); ControllerContext controllerContext = MockHelper.CreateMockControllerContext(); ActionResult actionResult = new Mock <ActionResult>().Object; var controller = SetupMockController(actionResult, controllerContext); var controllerFactory = SetupControllerFactory(controller.Object); app.ControllerFactory = controllerFactory.Object; ModuleRequestContext moduleRequestContext = CreateModuleContext(ControllerName, ActionName); // Act ModuleRequestResult result = app.ExecuteRequest(moduleRequestContext); // Assert Assert.AreSame(actionResult, result.ActionResult); Assert.AreSame(controllerContext, result.ControllerContext); }
public void ExecuteRequest_Executes_Constructed_Controller_And_Provides_RequestContext() { // Arrange var app = new ModuleApplication(); var controller = new Mock <IController>(); controller.As <IDnnController>(); var controllerFactory = SetupControllerFactory(controller.Object); app.ControllerFactory = controllerFactory.Object; ModuleRequestContext moduleRequestContext = CreateModuleContext(ControllerName, ActionName); // Act ModuleRequestResult result = app.ExecuteRequest(moduleRequestContext); // Assert controller.Verify(c => c.Execute(It.Is <RequestContext>(rc => rc.HttpContext == moduleRequestContext.HttpContext && rc.RouteData.GetRequiredString("controller") == ControllerName))); }