private ViewResultExecutor GetViewExecutor(DiagnosticListener diagnosticSource = null)
        {
            if (diagnosticSource == null)
            {
                diagnosticSource = 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 = new TestOptionsManager <MvcViewOptions>();

            options.Value.ViewEngines.Add(viewEngine.Object);

            var viewExecutor = new ViewResultExecutor(
                options,
                new TestHttpResponseStreamWriterFactory(),
                new CompositeViewEngine(options),
                new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
                diagnosticSource,
                NullLoggerFactory.Instance,
                new EmptyModelMetadataProvider());

            return(viewExecutor);
        }
Esempio n. 2
0
        private HttpContext GetHttpContext()
        {
            var options = new TestOptionsManager<MvcViewOptions>();

            var viewExecutor = new ViewResultExecutor(
                options,
                new TestHttpResponseStreamWriterFactory(),
                new CompositeViewEngine(options),
                new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
                new DiagnosticListener("Microsoft.AspNetCore"),
                NullLoggerFactory.Instance,
                new EmptyModelMetadataProvider());

            var services = new ServiceCollection();
            services.AddSingleton(viewExecutor);

            var httpContext = new DefaultHttpContext();
            httpContext.RequestServices = services.BuildServiceProvider();
            return httpContext;
        }
Esempio n. 3
0
        private ViewResultExecutor GetViewExecutor(DiagnosticListener diagnosticSource = null)
        {
            if (diagnosticSource == null)
            {
                diagnosticSource = 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 = new TestOptionsManager<MvcViewOptions>();
            options.Value.ViewEngines.Add(viewEngine.Object);

            var viewExecutor = new ViewResultExecutor(
                options,
                new TestHttpResponseStreamWriterFactory(),
                new CompositeViewEngine(options),
                new TempDataDictionaryFactory(new SessionStateTempDataProvider()),
                diagnosticSource,
                NullLoggerFactory.Instance,
                new EmptyModelMetadataProvider());

            return viewExecutor;
        }