コード例 #1
0
        private static TestRazorViewCompiler GetViewCompiler(
            TestFileProvider fileProvider = null,
            PublicRazorReferenceManager referenceManager    = null,
            IList <CompiledViewDescriptor> precompiledViews = null,
            PublicCSharpCompiler csharpCompiler             = null)
        {
            fileProvider = fileProvider ?? new TestFileProvider();
            var options = Options.Create(new MvcRazorRuntimeCompilationOptions {
                FileProviders = { fileProvider }
            });
            var compilationFileProvider = new PublicRuntimeCompilationFileProvider(options);


            referenceManager = referenceManager ?? CreateReferenceManager();
            precompiledViews = precompiledViews ?? Array.Empty <CompiledViewDescriptor>();

            var hostingEnvironment = Mock.Of <IWebHostEnvironment>(e => e.ContentRootPath == "BasePath");
            var fileSystem         = new PublicFileProviderRazorProjectFileSystem(compilationFileProvider);
            var projectEngine      = RazorProjectEngine.Create(RazorConfiguration.Default, fileSystem, builder => {
                RazorExtensions.Register(builder);
            });

            csharpCompiler = csharpCompiler ?? new PublicCSharpCompiler(referenceManager, hostingEnvironment);

            return(new TestRazorViewCompiler(
                       projectEngine,
                       csharpCompiler,
                       precompiledViews));
        }
コード例 #2
0
 public TestCSharpCompiler(
     PublicRazorReferenceManager referenceManager,
     IWebHostEnvironment hostingEnvironment,
     DependencyContextCompilationOptions options)
     : base(referenceManager, hostingEnvironment)
 {
     _options = options;
 }
コード例 #3
0
        public void GetCompilationReferences_CombinesApplicationPartAndOptionMetadataReferences()
        {
            // Arrange
            var options = new MvcRazorRuntimeCompilationOptions();
            var additionalReferencePath = "additional-path";

            options.AdditionalReferencePaths.Add(additionalReferencePath);

            var applicationPartManager = GetApplicationPartManager();
            var referenceManager       = new PublicRazorReferenceManager(
                applicationPartManager,
                Options.Create(options));

            var expected = new[] { ApplicationPartReferencePath, additionalReferencePath };

            // Act
            var references = referenceManager.GetReferencePaths();

            // Assert
            Assert.Equal(expected, references);
        }
コード例 #4
0
 public TestCSharpCompiler(PublicRazorReferenceManager manager, IWebHostEnvironment hostingEnvironment)
     : base(manager, hostingEnvironment)
 {
 }