public CSharpCompiler(RazorReferenceManager manager, IHostingEnvironment hostingEnvironment)
        {
            _referenceManager   = manager ?? throw new ArgumentNullException(nameof(manager));
            _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));

            EmitOptions = new EmitOptions(debugInformationFormat: _pdbFormat);
        }
 public TestCSharpCompiler(
     RazorReferenceManager referenceManager,
     IHostingEnvironment hostingEnvironment,
     DependencyContextCompilationOptions options)
     : base(referenceManager, hostingEnvironment)
 {
     _options = options;
 }
            public TestCSharpCompiler(
#pragma warning disable CS0618 // Type or member is obsolete
                RazorReferenceManager referenceManager,
#pragma warning restore CS0618 // Type or member is obsolete
                IHostingEnvironment hostingEnvironment,
                DependencyContextCompilationOptions options)
                : base(referenceManager, hostingEnvironment)
            {
                _options = options;
            }
Exemple #4
0
        private static DefaultRoslynCompilationService GetRoslynCompilationService(
            ApplicationPartManager partManager = null,
            RazorViewEngineOptions options     = null,
            IFileProvider fileProvider         = null)
        {
            partManager = partManager ?? GetApplicationPartManager();
            options     = options ?? GetOptions();
            var optionsAccessor  = GetAccessor(options);
            var referenceManager = new RazorReferenceManager(partManager, optionsAccessor);
            var compiler         = new CSharpCompiler(referenceManager, optionsAccessor);

            return(new DefaultRoslynCompilationService(
                       compiler,
                       GetFileProviderAccessor(fileProvider),
                       optionsAccessor,
                       NullLoggerFactory.Instance));
        }
        private static TestRazorViewCompiler GetViewCompiler(
            TestFileProvider fileProvider = null,
            Action <RoslynCompilationContext> compilationCallback = null,
            RazorReferenceManager referenceManager          = null,
            IList <CompiledViewDescriptor> precompiledViews = null)
        {
            fileProvider = fileProvider ?? new TestFileProvider();
            var accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);

            compilationCallback = compilationCallback ?? (_ => { });
            var options = Options.Create(new RazorViewEngineOptions());

            if (referenceManager == null)
            {
                var applicationPartManager = new ApplicationPartManager();
                var assembly = typeof(RazorViewCompilerTest).Assembly;
                applicationPartManager.ApplicationParts.Add(new AssemblyPart(assembly));
                applicationPartManager.FeatureProviders.Add(new MetadataReferenceFeatureProvider());

                referenceManager = new DefaultRazorReferenceManager(applicationPartManager, options);
            }

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

            var hostingEnvironment = Mock.Of <IHostingEnvironment>(e => e.ContentRootPath == "BasePath");
            var projectSystem      = new FileProviderRazorProject(accessor, hostingEnvironment);
            var templateEngine     = new RazorTemplateEngine(RazorEngine.Create(), projectSystem)
            {
                Options =
                {
                    ImportsFileName = "_ViewImports.cshtml",
                }
            };
            var viewCompiler = new TestRazorViewCompiler(
                fileProvider,
                templateEngine,
                new CSharpCompiler(referenceManager, hostingEnvironment),
                compilationCallback,
                precompiledViews);

            return(viewCompiler);
        }
        private static TestRazorViewCompiler GetViewCompiler(
            TestFileProvider fileProvider = null,
            Action <RoslynCompilationContext> compilationCallback = null,
#pragma warning disable CS0618 // Type or member is obsolete
            RazorReferenceManager referenceManager = null,
#pragma warning restore CS0618 // Type or member is obsolete
            IList <CompiledViewDescriptor> precompiledViews = null,
            CSharpCompiler csharpCompiler = null)
        {
            fileProvider = fileProvider ?? new TestFileProvider();
            var accessor = Mock.Of <IRazorViewEngineFileProviderAccessor>(a => a.FileProvider == fileProvider);

            compilationCallback = compilationCallback ?? (_ => { });
            var options = Options.Create(new RazorViewEngineOptions());

            if (referenceManager == null)
            {
                referenceManager = CreateReferenceManager(options);
            }

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

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

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

            var viewCompiler = new TestRazorViewCompiler(
                fileProvider,
                projectEngine,
                csharpCompiler,
                compilationCallback,
                precompiledViews);

            return(viewCompiler);
        }
Exemple #7
0
 public LazyMetadataReferenceFeature(RazorReferenceManager referenceManager)
 {
     _referenceManager = referenceManager;
 }
#pragma warning disable CS0618 // Type or member is obsolete
            public TestCSharpCompiler(RazorReferenceManager manager, IHostingEnvironment hostingEnvironment)
#pragma warning restore CS0618 // Type or member is obsolete
                : base(manager, hostingEnvironment)
            {
            }
#pragma warning disable CS0618 // Type or member is obsolete
        public CSharpCompiler(RazorReferenceManager manager, IHostingEnvironment hostingEnvironment)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            _referenceManager   = manager ?? throw new ArgumentNullException(nameof(manager));
            _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
        }
 public TestCSharpCompiler(RazorReferenceManager manager, IHostingEnvironment hostingEnvironment)
     : base(manager, hostingEnvironment)
 {
 }
Exemple #11
0
 public CSharpCompiler(RazorReferenceManager manager, IHostingEnvironment hostingEnvironment)
 {
     _referenceManager   = manager ?? throw new ArgumentNullException(nameof(manager));
     _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
 }
Exemple #12
0
#pragma warning restore CS0618 // Type or member is obsolete

#pragma warning disable CS0618 // Type or member is obsolete
        public LazyMetadataReferenceFeature(RazorReferenceManager referenceManager)
#pragma warning restore CS0618 // Type or member is obsolete
        {
            _referenceManager = referenceManager;
        }