private ViewResultExecutor GetViewExecutor(DiagnosticListener diagnosticListener = null) { if (diagnosticListener == null) { diagnosticListener = new DiagnosticListener("Test"); } var viewEngine = new Mock <IViewEngine>(MockBehavior.Strict); viewEngine .Setup(e => e.GetView(/*executingFilePath*/ null, It.IsAny <string>(), /*isMainPage*/ true)) .Returns <string, string, bool>( (path, name, partial) => ViewEngineResult.NotFound(name, Enumerable.Empty <string>())); viewEngine .Setup(e => e.FindView(It.IsAny <ActionContext>(), It.IsAny <string>(), /*isMainPage*/ true)) .Returns <ActionContext, string, bool>( (context, name, partial) => ViewEngineResult.Found(name, Mock.Of <IView>())); var options = Options.Create(new MvcViewOptions()); options.Value.ViewEngines.Add(viewEngine.Object); var viewExecutor = new ViewResultExecutor( options, new TestHttpResponseStreamWriterFactory(), new CompositeViewEngine(options), new TempDataDictionaryFactory(Mock.Of <ITempDataProvider>()), diagnosticListener, NullLoggerFactory.Instance, new EmptyModelMetadataProvider()); return(viewExecutor); }
private HttpContext GetHttpContext() { var options = new TestOptionsManager <MvcViewOptions>(); var viewExecutor = new ViewResultExecutor( options, new TestHttpResponseStreamWriterFactory(), new CompositeViewEngine(options), new DiagnosticListener("Microsoft.AspNet"), NullLoggerFactory.Instance); var services = new ServiceCollection(); services.AddInstance(viewExecutor); var httpContext = new DefaultHttpContext(); httpContext.RequestServices = services.BuildServiceProvider(); return(httpContext); }
private HttpContext GetHttpContext() { var options = Options.Create(new MvcViewOptions()); var viewExecutor = new ViewResultExecutor( options, new TestHttpResponseStreamWriterFactory(), new CompositeViewEngine(options), Mock.Of <ITempDataDictionaryFactory>(), new DiagnosticListener("Microsoft.AspNetCore"), NullLoggerFactory.Instance, new EmptyModelMetadataProvider()); var services = new ServiceCollection(); services.AddSingleton <IActionResultExecutor <ViewResult> >(viewExecutor); var httpContext = new DefaultHttpContext(); httpContext.RequestServices = services.BuildServiceProvider(); return(httpContext); }