public virtual void BeforeCompile(IBeforeCompileContext context)
        {
            var appEnv = _appServices.GetRequiredService <IApplicationEnvironment>();

            var setup = new RazorViewEngineOptionsSetup(appEnv);
            var sc    = new ServiceCollection();

            sc.ConfigureOptions(setup);
            sc.AddMvc();

            var viewCompiler = new RazorPreCompiler(BuildFallbackServiceProvider(sc, _appServices));

            viewCompiler.CompileViews(context);
        }
Example #2
0
        public virtual void BeforeCompile(IBeforeCompileContext context)
        {
            var sc     = new ServiceCollection();
            var appEnv = _appServices.GetRequiredService <IApplicationEnvironment>();

            var setup    = new RazorViewEngineOptionsSetup(appEnv);
            var accessor = new OptionsManager <RazorViewEngineOptions>(new[] { setup });

            sc.AddInstance <IOptions <RazorViewEngineOptions> >(accessor);
            sc.Add(MvcServices.GetDefaultServices());
            var sp = sc.BuildServiceProvider(_appServices);

            var viewCompiler = new RazorPreCompiler(sp);

            viewCompiler.CompileViews(context);
        }
Example #3
0
        public void RazorViewEngineOptionsSetup_SetsUpFileProvider()
        {
            // Arrange
            var options = new RazorViewEngineOptions();
            var appEnv  = new Mock <IApplicationEnvironment>();

            appEnv.SetupGet(e => e.ApplicationBasePath)
            .Returns(Directory.GetCurrentDirectory());
            var optionsSetup = new RazorViewEngineOptionsSetup(appEnv.Object);

            // Act
            optionsSetup.Configure(options);

            // Assert
            Assert.NotNull(options.FileProvider);
            Assert.IsType <PhysicalFileProvider>(options.FileProvider);
        }
Example #4
0
        public virtual void BeforeCompile(IBeforeCompileContext context)
        {
            var applicationEnvironment  = _appServices.GetRequiredService <IApplicationEnvironment>();
            var compilerOptionsProvider = _appServices.GetRequiredService <ICompilerOptionsProvider>();
            var compilationSettings     = compilerOptionsProvider.GetCompilationSettings(applicationEnvironment);

            var setup = new RazorViewEngineOptionsSetup(applicationEnvironment);
            var sc    = new ServiceCollection();

            sc.ConfigureOptions(setup);
            sc.AddMvc();

            var serviceProvider = BuildFallbackServiceProvider(sc, _appServices);
            var viewCompiler    = new RazorPreCompiler(serviceProvider, _memoryCache, compilationSettings);

            viewCompiler.CompileViews(context);
        }
Example #5
0
        public void RazorViewEngineOptionsSetup_SetsPreprocessorSymbols(string environment, string expectedConfiguration)
        {
            // Arrange
            var options = new RazorViewEngineOptions();
            var appEnv  = new Mock <IApplicationEnvironment>();

            appEnv.SetupGet(e => e.ApplicationBasePath)
            .Returns(Directory.GetCurrentDirectory());
            var hostingEnv = new Mock <IHostingEnvironment>();

            hostingEnv.SetupGet(e => e.EnvironmentName)
            .Returns(environment);
            var optionsSetup = new RazorViewEngineOptionsSetup(appEnv.Object, hostingEnv.Object);

            // Act
            optionsSetup.Configure(options);

            // Assert
            Assert.Equal(new[] { expectedConfiguration }, options.ParseOptions.PreprocessorSymbolNames);
        }
Example #6
0
        public void RazorViewEngineOptionsSetup_SetsOptimizationLevel(
            string environment,
            OptimizationLevel expectedOptimizationLevel)
        {
            // Arrange
            var options = new RazorViewEngineOptions();
            var appEnv  = new Mock <IApplicationEnvironment>();

            appEnv.SetupGet(e => e.ApplicationBasePath)
            .Returns(Directory.GetCurrentDirectory());
            var hostingEnv = new Mock <IHostingEnvironment>();

            hostingEnv.SetupGet(e => e.EnvironmentName)
            .Returns(environment);
            var optionsSetup = new RazorViewEngineOptionsSetup(appEnv.Object, hostingEnv.Object);

            // Act
            optionsSetup.Configure(options);

            // Assert
            Assert.Equal(expectedOptimizationLevel, options.CompilationOptions.OptimizationLevel);
        }
Example #7
0
        public void RazorViewEngineOptionsSetup_SetsUpFileProvider()
        {
            // Arrange
            var options = new RazorViewEngineOptions();
            var appEnv  = new Mock <IApplicationEnvironment>();

            appEnv.SetupGet(e => e.ApplicationBasePath)
            .Returns(Directory.GetCurrentDirectory());
            var hostingEnv = new Mock <IHostingEnvironment>();

            hostingEnv.SetupGet(e => e.EnvironmentName)
            .Returns("Development");
            var optionsSetup = new RazorViewEngineOptionsSetup(appEnv.Object, hostingEnv.Object);

            // Act
            optionsSetup.Configure(options);

            // Assert
            var fileProvider = Assert.Single(options.FileProviders);

            Assert.IsType <PhysicalFileProvider>(fileProvider);
        }