private PartialViewResultExecutor 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*/ false)) .Returns <string, string, bool>( (executing, name, isMainPage) => ViewEngineResult.NotFound(name, Enumerable.Empty <string>())); viewEngine .Setup(e => e.FindView(It.IsAny <ActionContext>(), It.IsAny <string>(), /*isMainPage*/ false)) .Returns <ActionContext, string, bool>( (context, name, isMainPage) => ViewEngineResult.Found(name, Mock.Of <IView>())); var options = Options.Create(new MvcViewOptions()); options.Value.ViewEngines.Add(viewEngine.Object); var viewExecutor = new PartialViewResultExecutor( options, new TestHttpResponseStreamWriterFactory(), new CompositeViewEngine(options), Mock.Of <ITempDataDictionaryFactory>(), diagnosticListener, NullLoggerFactory.Instance, new EmptyModelMetadataProvider()); return(viewExecutor); }
private HttpContext GetHttpContext() { var options = new TestOptionsManager <MvcViewOptions>(); var viewExecutor = new PartialViewResultExecutor( 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 PartialViewResultExecutor( options, new TestHttpResponseStreamWriterFactory(), new CompositeViewEngine(options), Mock.Of <ITempDataDictionaryFactory>(), new DiagnosticListener("Microsoft.AspNetCore"), NullLoggerFactory.Instance, new EmptyModelMetadataProvider()); var services = new ServiceCollection(); services.AddSingleton <IActionResultExecutor <PartialViewResult> >(viewExecutor); var httpContext = new DefaultHttpContext(); httpContext.RequestServices = services.BuildServiceProvider(); return(httpContext); }