Exemple #1
0
        private PartialViewResultExecutor GetViewExecutor(DiagnosticSource 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*/ 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 = new TestOptionsManager <MvcViewOptions>();

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

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

            return(viewExecutor);
        }
        private HttpContext GetHttpContext()
        {
            var options = new TestOptionsManager <MvcViewOptions>();

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

            var services = new ServiceCollection();

            services.AddSingleton(viewExecutor);

            var httpContext = new DefaultHttpContext();

            httpContext.RequestServices = services.BuildServiceProvider();
            return(httpContext);
        }
        private HttpContext GetHttpContext()
        {
            var options = new TestOptionsManager<MvcViewOptions>();

            var viewExecutor = new PartialViewResultExecutor(
                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;
        }
        private PartialViewResultExecutor GetViewExecutor(DiagnosticSource 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*/ 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 = new TestOptionsManager<MvcViewOptions>();
            options.Value.ViewEngines.Add(viewEngine.Object);

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

            return viewExecutor;
        }