Example #1
0
        private static TestRazorViewCompiler GetViewCompiler(
            TestFileProvider fileProvider                   = null,
            RazorReferenceManager referenceManager          = null,
            IList <CompiledViewDescriptor> precompiledViews = null,
            CSharpCompiler csharpCompiler                   = null)
        {
            fileProvider = fileProvider ?? new TestFileProvider();
            var options = Options.Create(new MvcRazorRuntimeCompilationOptions
            {
                FileProviders = { fileProvider }
            });
            var compilationFileProvider = new RuntimeCompilationFileProvider(options);


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

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

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

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

            options.AdditionalReferencePaths.Add(additionalReferencePath);

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

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

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

            // Assert
            Assert.Equal(expected, references);
        }
Example #4
0
 public LazyMetadataReferenceFeature(RazorReferenceManager referenceManager)
 {
     _referenceManager = referenceManager;
 }
Example #5
0
 public CSharpCompiler(RazorReferenceManager manager, IWebHostEnvironment hostingEnvironment)
 {
     _referenceManager   = manager ?? throw new ArgumentNullException(nameof(manager));
     _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
 }
Example #6
0
 public TestCSharpCompiler(RazorReferenceManager manager, IWebHostEnvironment hostingEnvironment)
     : base(manager, hostingEnvironment)
 {
 }