private static TestRazorViewCompiler GetViewCompiler(IList <CompiledViewDescriptor> compiledViews = null)
        {
            compiledViews = compiledViews ?? Array.Empty <CompiledViewDescriptor>();

            var viewCompiler = new TestRazorViewCompiler(compiledViews);

            return(viewCompiler);
        }
        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);
        }