public void ProjectSnapshot_CachesDocumentSnapshots()
        {
            // Arrange
            var state = ProjectState.Create(Workspace.Services, HostProject, ProjectWorkspaceState)
                        .WithAddedHostDocument(Documents[0], DocumentState.EmptyLoader)
                        .WithAddedHostDocument(Documents[1], DocumentState.EmptyLoader)
                        .WithAddedHostDocument(Documents[2], DocumentState.EmptyLoader);
            var snapshot = new DefaultProjectSnapshot(state);

            // Act
            var documents = snapshot.DocumentFilePaths.ToDictionary(f => f, f => snapshot.GetDocument(f));

            // Assert
            Assert.Collection(
                documents,
                d => Assert.Same(d.Value, snapshot.GetDocument(d.Key)),
                d => Assert.Same(d.Value, snapshot.GetDocument(d.Key)),
                d => Assert.Same(d.Value, snapshot.GetDocument(d.Key)));
        }
예제 #2
0
        public void ProjectSnapshot_CachesDocumentSnapshots()
        {
            // Arrange
            var state = new ProjectState(Workspace.Services, HostProject, WorkspaceProject)
                        .AddHostDocument(Documents[0])
                        .AddHostDocument(Documents[1])
                        .AddHostDocument(Documents[2]);
            var snapshot = new DefaultProjectSnapshot(state);

            // Act
            var documents = snapshot.DocumentFilePaths.ToDictionary(f => f, f => snapshot.GetDocument(f));

            // Assert
            Assert.Collection(
                documents,
                d => Assert.Same(d.Value, snapshot.GetDocument(d.Key)),
                d => Assert.Same(d.Value, snapshot.GetDocument(d.Key)),
                d => Assert.Same(d.Value, snapshot.GetDocument(d.Key)));
        }
        public async Task LoadAsync_SpecifiesEncoding()
        {
            // Arrange
            var project = new DefaultProjectSnapshot(
                ProjectState.Create(Workspace.Services, HostProject)
                .WithAddedHostDocument(HostDocument, () => Task.FromResult(TextAndVersion.Create(SourceText.From(""), VersionStamp.Create()))));

            var document = project.GetDocument(HostDocument.FilePath);

            var loader = new GeneratedDocumentTextLoader(document, "file.cshtml");

            // Act
            var textAndVersion = await loader.LoadTextAndVersionAsync(default, default, default);
        public void IsImportDocument_NonImportDocument_ReturnsFalse()
        {
            // Arrange
            var state = ProjectState.Create(Workspace.Services, HostProject, ProjectWorkspaceState)
                        .WithAddedHostDocument(Documents[0], DocumentState.EmptyLoader);
            var snapshot = new DefaultProjectSnapshot(state);

            var document = snapshot.GetDocument(Documents[0].FilePath);

            // Act
            var result = snapshot.IsImportDocument(document);

            // Assert
            Assert.False(result);
        }
        public void GetRelatedDocuments_NonImportDocument_ReturnsEmpty()
        {
            // Arrange
            var state = ProjectState.Create(Workspace.Services, HostProject, WorkspaceProject)
                        .WithAddedHostDocument(Documents[0], DocumentState.EmptyLoader);
            var snapshot = new DefaultProjectSnapshot(state);

            var document = snapshot.GetDocument(Documents[0].FilePath);

            // Act
            var documents = snapshot.GetRelatedDocuments(document);

            // Assert
            Assert.Empty(documents);
        }
        public void IsImportDocument_ImportDocument_ReturnsTrue()
        {
            // Arrange
            var state = ProjectState.Create(Workspace.Services, HostProject, WorkspaceProject)
                        .WithAddedHostDocument(Documents[0], DocumentState.EmptyLoader)
                        .WithAddedHostDocument(TestProjectData.SomeProjectImportFile, DocumentState.EmptyLoader);
            var snapshot = new DefaultProjectSnapshot(state);

            var document = snapshot.GetDocument(TestProjectData.SomeProjectImportFile.FilePath);

            // Act
            var result = snapshot.IsImportDocument(document);

            // Assert
            Assert.True(result);
        }
        public void GetRelatedDocuments_ImportDocument_ReturnsRelated()
        {
            // Arrange
            var state = ProjectState.Create(Workspace.Services, HostProject, ProjectWorkspaceState)
                        .WithAddedHostDocument(Documents[0], DocumentState.EmptyLoader)
                        .WithAddedHostDocument(Documents[1], DocumentState.EmptyLoader)
                        .WithAddedHostDocument(TestProjectData.SomeProjectImportFile, DocumentState.EmptyLoader);
            var snapshot = new DefaultProjectSnapshot(state);

            var document = snapshot.GetDocument(TestProjectData.SomeProjectImportFile.FilePath);

            // Act
            var documents = snapshot.GetRelatedDocuments(document);

            // Assert
            Assert.Collection(
                documents.OrderBy(d => d.FilePath),
                d => Assert.Equal(Documents[0].FilePath, d.FilePath),
                d => Assert.Equal(Documents[1].FilePath, d.FilePath));
        }
예제 #8
0
        private IReadOnlyList <DocumentSnapshot> GetImportsCore(DefaultProjectSnapshot project)
        {
            var projectEngine  = project.GetProjectEngine();
            var importFeatures = projectEngine.ProjectFeatures.OfType <IImportProjectFeature>();
            var projectItem    = projectEngine.FileSystem.GetItem(HostDocument.FilePath, HostDocument.FileKind);
            var importItems    = importFeatures.SelectMany(f => f.GetImports(projectItem));

            if (importItems == null)
            {
                return(Array.Empty <DocumentSnapshot>());
            }

            var imports = new List <DocumentSnapshot>();

            foreach (var item in importItems)
            {
                if (item.PhysicalPath == null)
                {
                    // This is a default import.
                    var defaultImport = new DefaultImportDocumentSnapshot(project, item);
                    imports.Add(defaultImport);
                }
                else
                {
                    var import = project.GetDocument(item.PhysicalPath);
                    if (import == null)
                    {
                        // We are not tracking this document in this project. So do nothing.
                        continue;
                    }

                    imports.Add(import);
                }
            }

            return(imports);
        }