private static UpdateNameController CreateController(ScenarioOptions scenarioOptions = null) { scenarioOptions = scenarioOptions ?? new ScenarioOptions(); scenarioOptions.MockQueryProcessor = new Mock <IProcessQueries>(MockBehavior.Strict); scenarioOptions.MockCommandHandler = new Mock <IHandleCommands <UpdateMyNameCommand> >(MockBehavior.Strict); var services = new UpdateNameServices(scenarioOptions.MockQueryProcessor.Object, scenarioOptions.MockCommandHandler.Object); var controller = new UpdateNameController(services); var builder = ReuseMock.TestControllerBuilder(); if (!string.IsNullOrWhiteSpace(scenarioOptions.PrincipalIdentityName)) { builder.HttpContext.User = scenarioOptions.PrincipalIdentityName.AsPrincipal(); } builder.InitializeController(controller); if (scenarioOptions.IsChildAction) { var controllerContext = new Mock <ControllerContext>(MockBehavior.Strict); var parentContext = new ViewContext { TempData = new TempDataDictionary() }; builder.RouteData.DataTokens.Add("ParentActionViewContext", parentContext); controllerContext.Setup(p => p.IsChildAction).Returns(true); controllerContext.Setup(p => p.HttpContext).Returns(builder.HttpContext); controllerContext.Setup(p => p.RouteData).Returns(builder.RouteData); controller.ControllerContext = controllerContext.Object; } return(controller); }
public UpdateNameController(UpdateNameServices services) { _services = services; }
private static UpdateNameController CreateController(ScenarioOptions scenarioOptions = null) { scenarioOptions = scenarioOptions ?? new ScenarioOptions(); scenarioOptions.MockQueryProcessor = new Mock<IProcessQueries>(MockBehavior.Strict); scenarioOptions.MockCommandHandler = new Mock<IHandleCommands<UpdateMyNameCommand>>(MockBehavior.Strict); var services = new UpdateNameServices(scenarioOptions.MockQueryProcessor.Object, scenarioOptions.MockCommandHandler.Object); var controller = new UpdateNameController(services); var builder = ReuseMock.TestControllerBuilder(); if (!string.IsNullOrWhiteSpace(scenarioOptions.PrincipalIdentityName)) builder.HttpContext.User = scenarioOptions.PrincipalIdentityName.AsPrincipal(); builder.InitializeController(controller); if (scenarioOptions.IsChildAction) { var controllerContext = new Mock<ControllerContext>(MockBehavior.Strict); var parentContext = new ViewContext { TempData = new TempDataDictionary() }; builder.RouteData.DataTokens.Add("ParentActionViewContext", parentContext); controllerContext.Setup(p => p.IsChildAction).Returns(true); controllerContext.Setup(p => p.HttpContext).Returns(builder.HttpContext); controllerContext.Setup(p => p.RouteData).Returns(builder.RouteData); controller.ControllerContext = controllerContext.Object; } return controller; }