예제 #1
0
        public static TestProjectSnapshot Create(
            string filePath,
            string[] documentFilePaths,
            RazorConfiguration configuration,
            ProjectWorkspaceState projectWorkspaceState)
        {
            var workspaceServices = new List <IWorkspaceService>()
            {
                new TestProjectSnapshotProjectEngineFactory(),
            };
            var languageServices = new List <ILanguageService>();

            var hostServices = TestServices.Create(workspaceServices, languageServices);
            var workspace    = TestWorkspace.Create(hostServices);
            var hostProject  = new HostProject(filePath, configuration, "TestRootNamespace");
            var state        = ProjectState.Create(workspace.Services, hostProject);

            foreach (var documentFilePath in documentFilePaths)
            {
                var hostDocument = new HostDocument(documentFilePath, documentFilePath);
                state = state.WithAddedHostDocument(hostDocument, () => Task.FromResult(TextAndVersion.Create(SourceText.From(string.Empty), VersionStamp.Default)));
            }

            if (projectWorkspaceState != null)
            {
                state = state.WithProjectWorkspaceState(projectWorkspaceState);
            }

            var testProject = new TestProjectSnapshot(state);

            return(testProject);
        }
예제 #2
0
        public static TestDocumentSnapshot Create(string filePath, string text, VersionStamp version)
        {
            var testProject   = TestProjectSnapshot.Create(filePath + ".csproj");
            var testWorkspace = TestWorkspace.Create();
            var hostDocument  = new HostDocument(filePath, filePath);
            var sourceText    = SourceText.From(text);
            var documentState = new DocumentState(
                testWorkspace.Services,
                hostDocument,
                SourceText.From(text),
                version,
                () => Task.FromResult(TextAndVersion.Create(sourceText, version)));
            var testDocument = new TestDocumentSnapshot(testProject, documentState);

            return(testDocument);
        }