Пример #1
0
        private static IServiceProvider CreateServices()
        {
            var options = new TestOptionsManager <MvcOptions>();

            options.Value.OutputFormatters.Add(new StringOutputFormatter());
            options.Value.OutputFormatters.Add(new JsonOutputFormatter());

            var services = new ServiceCollection();

            services.AddSingleton(new ObjectResultExecutor(
                                      options,
                                      new TestHttpResponseStreamWriterFactory(),
                                      NullLoggerFactory.Instance));

            return(services.BuildServiceProvider());
        }
Пример #2
0
        private IServiceProvider GetServiceProvider(Dictionary <string, CacheProfile> cacheProfiles)
        {
            var serviceProvider = new Mock <IServiceProvider>();
            var optionsAccessor = new TestOptionsManager <MvcOptions>();

            if (cacheProfiles != null)
            {
                foreach (var p in cacheProfiles)
                {
                    optionsAccessor.Value.CacheProfiles.Add(p.Key, p.Value);
                }
            }

            serviceProvider
            .Setup(s => s.GetService(typeof(IOptions <MvcOptions>)))
            .Returns(optionsAccessor);

            return(serviceProvider.Object);
        }
Пример #3
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);

            var services = new ServiceCollection();

            services.AddSingleton(viewExecutor);

            var httpContext = new DefaultHttpContext();

            httpContext.RequestServices = services.BuildServiceProvider();
            return(httpContext);
        }