Пример #1
0
        public async Task ProjectAdded_PublishesToCorrectFilePath()
        {
            // Arrange
            var snapshotManager         = CreateProjectSnapshotManager(allowNotifyListeners: true);
            var serializationSuccessful = false;
            var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestProjectChangePublisher(
                LoggerFactory,
                onSerializeToFile: (snapshot, publishFilePath) =>
            {
                Assert.Equal(expectedPublishFilePath, publishFilePath);
                serializationSuccessful = true;
            });

            publisher.Initialize(snapshotManager);
            var hostProject = new OmniSharpHostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            publisher.SetPublishFilePath(hostProject.FilePath, expectedPublishFilePath);

            // Act
            await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject));

            // Assert
            Assert.True(serializationSuccessful);
        }
        public async Task ProjectRemoved_DeletesPublishFile()
        {
            // Arrange
            var attemptedToDelete       = false;
            var snapshotManager         = CreateProjectSnapshotManager(allowNotifyListeners: true);
            var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestProjectChangePublisher(LoggerFactory,
                                                           onSerializeToFile: (_, __) => { },
                                                           onDeleteFile: (publishFilePath) =>
            {
                attemptedToDelete = true;
                Assert.Equal(expectedPublishFilePath, publishFilePath);
            });

            publisher.Initialize(snapshotManager);
            var hostProject = new OmniSharpHostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            publisher.SetPublishFilePath(hostProject.FilePath, expectedPublishFilePath);
            await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject));

            // Act
            await RunOnForegroundAsync(() => snapshotManager.ProjectRemoved(hostProject));

            // Assert
            Assert.True(attemptedToDelete);
        }
Пример #3
0
        public async Task RazorDocumentChangedAsync_Changed_PerformsProjectEvaluation()
        {
            // Arrange
            var projectRootElement       = ProjectRootElement.Create("/path/to/project.csproj");
            var projectInstance          = new ProjectInstance(projectRootElement);
            var projectInstanceEvaluator = new Mock <ProjectInstanceEvaluator>();

            projectInstanceEvaluator.Setup(evaluator => evaluator.Evaluate(It.IsAny <ProjectInstance>()))
            .Verifiable();
            var projectManager         = CreateProjectSnapshotManager();
            var updateBufferDispatcher = Mock.Of <UpdateBufferDispatcher>(dispatcher => dispatcher.UpdateBufferAsync(It.IsAny <Request>()) == Task.CompletedTask);
            var refreshTrigger         = new ComponentRefreshTrigger(Dispatcher, new FilePathNormalizer(), projectInstanceEvaluator.Object, updateBufferDispatcher, LoggerFactory);

            refreshTrigger.Initialize(projectManager);
            await RunOnForegroundAsync(() =>
            {
                var hostProject = new OmniSharpHostProject(projectInstance.ProjectFileLocation.File, RazorConfiguration.Default, "TestRootNamespace");
                projectManager.ProjectAdded(hostProject);
                var hostDocument = new OmniSharpHostDocument("file.cshtml", "file.cshtml", FileKinds.Component);
                projectManager.DocumentAdded(hostProject, hostDocument);
            });

            var args = new RazorFileChangeEventArgs("file.cshtml", "file.cshtml", projectInstance, RazorFileChangeKind.Changed);

            // Act
            await refreshTrigger.RazorDocumentChangedAsync(args);

            // Assert
            projectInstanceEvaluator.VerifyAll();
        }
Пример #4
0
        public async Task PSM_DocumentRemoved_RemovesAssociatedBackgroundDocument()
        {
            // Arrange
            var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
            var hostProject            = new OmniSharpHostProject(Project.FilePath, RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
            var hostDocument           = new OmniSharpHostDocument("/path/to/Counter.razor", "/path/to/Counter.razor", FileKinds.Component);

            await RunOnForegroundAsync(() =>
            {
                projectSnapshotManager.ProjectAdded(hostProject);
                projectSnapshotManager.DocumentAdded(hostProject, hostDocument);
            });

            var backgroundDocumentFilePath = hostDocument.FilePath + BackgroundDocumentProcessedPublisher.BackgroundVirtualDocumentSuffix;

            AddRoslynDocument(backgroundDocumentFilePath);
            var processedPublisher = new BackgroundDocumentProcessedPublisher(Dispatcher, Workspace, LoggerFactory);

            processedPublisher.Initialize(projectSnapshotManager);

            // Act
            await RunOnForegroundAsync(() => projectSnapshotManager.DocumentRemoved(hostProject, hostDocument));

            // Assert
            var project = Assert.Single(Workspace.CurrentSolution.Projects);

            Assert.Empty(project.Documents);
        }
Пример #5
0
        public async Task ProjectRemoved_UnSetPublishFilePath_Noops()
        {
            // Arrange
            var snapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
            var publisher       = new TestProjectChangePublisher(LoggerFactory);

            publisher.Initialize(snapshotManager);
            var hostProject = new OmniSharpHostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject));

            // Act & Assert
            await RunOnForegroundAsync(() => snapshotManager.ProjectRemoved(hostProject));
        }
Пример #6
0
        public async Task IsComponentFile_UnknownDocument_ReturnsFalse()
        {
            // Arrange
            var projectManager = CreateProjectSnapshotManager();
            var refreshTrigger = CreateRefreshTrigger();

            refreshTrigger.Initialize(projectManager);
            var hostProject = new OmniSharpHostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");

            await RunOnForegroundAsync(() => projectManager.ProjectAdded(hostProject));

            // Act
            var result = await RunOnForegroundAsync(() => refreshTrigger.IsComponentFile("file.razor", hostProject.FilePath));

            // Assert
            Assert.False(result);
        }
Пример #7
0
        public TagHelperRefreshTriggerTest()
        {
            Workspace = TestWorkspace.Create();
            var projectRoot1 = ProjectRootElement.Create("/path/to/project.csproj");

            Project1Instance = new ProjectInstance(projectRoot1);
            ProjectManager   = CreateProjectSnapshotManager();
            Project1         = new OmniSharpHostProject(projectRoot1.ProjectFileLocation.File, RazorConfiguration.Default, "TestRootNamespace");

            var solution = Workspace.CurrentSolution.AddProject(
                ProjectInfo.Create(
                    ProjectId.CreateNewId(),
                    VersionStamp.Default,
                    "Project1",
                    "Project1",
                    LanguageNames.CSharp,
                    filePath: Project1.FilePath));

            Workspace.TryApplyChanges(solution);
        }
Пример #8
0
        public async Task RazorDocumentChangedAsync_Changed_NotComponent_Noops()
        {
            // Arrange
            var projectManager = CreateProjectSnapshotManager();
            var refreshTrigger = CreateTestComponentRefreshTrigger();

            refreshTrigger.Initialize(projectManager);

            await RunOnForegroundAsync(() =>
            {
                var hostProject = new OmniSharpHostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");
                projectManager.ProjectAdded(hostProject);
                var hostDocument = new OmniSharpHostDocument("file.cshtml", "file.cshtml", FileKinds.Legacy);
                projectManager.DocumentAdded(hostProject, hostDocument);
            });

            var args = new RazorFileChangeEventArgs("file.cshtml", "file.cshtml", ProjectInstance, RazorFileChangeKind.Changed);

            // Act & Assert
            await refreshTrigger.RazorDocumentChangedAsync(args);
        }
Пример #9
0
        public async Task IsComponentFile_Component_ReturnsTrue()
        {
            // Arrange
            var projectManager = CreateProjectSnapshotManager();
            var refreshTrigger = CreateRefreshTrigger();

            refreshTrigger.Initialize(projectManager);
            var hostProject  = new OmniSharpHostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace");
            var hostDocument = new OmniSharpHostDocument("file.cshtml", "file.cshtml", FileKinds.Component);

            await RunOnForegroundAsync(() =>
            {
                projectManager.ProjectAdded(hostProject);
                projectManager.DocumentAdded(hostProject, hostDocument);
            });

            // Act
            var result = await RunOnForegroundAsync(() => refreshTrigger.IsComponentFile(hostDocument.FilePath, hostProject.FilePath));

            // Assert
            Assert.True(result);
        }
Пример #10
0
        public async Task PSM_DocumentRemoved_NoBackgroundDocument_Noops()
        {
            // Arrange
            var projectSnapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
            var hostProject            = new OmniSharpHostProject(Project.FilePath, RazorConfiguration.Default, rootNamespace: "TestRootNamespace");
            var hostDocument           = new OmniSharpHostDocument("/path/to/Counter.razor", "/path/to/Counter.razor", FileKinds.Component);

            await RunOnForegroundAsync(() =>
            {
                projectSnapshotManager.ProjectAdded(hostProject);
                projectSnapshotManager.DocumentAdded(hostProject, hostDocument);
            });

            var originalSolution   = Workspace.CurrentSolution;
            var processedPublisher = new BackgroundDocumentProcessedPublisher(Dispatcher, Workspace, LoggerFactory);

            processedPublisher.Initialize(projectSnapshotManager);

            // Act
            await RunOnForegroundAsync(() => projectSnapshotManager.DocumentRemoved(hostProject, hostDocument));

            // Assert
            Assert.Same(originalSolution, Workspace.CurrentSolution);
        }
 public abstract void ProjectConfigurationChanged(OmniSharpHostProject hostProject);
 public abstract void ProjectRemoved(OmniSharpHostProject hostProject);
 public abstract void DocumentRemoved(OmniSharpHostProject hostProject, OmniSharpHostDocument hostDocument);
 public abstract void ProjectAdded(OmniSharpHostProject hostProject);
Пример #15
0
        public override void DocumentAdded(OmniSharpHostProject hostProject, OmniSharpHostDocument hostDocument)
        {
            var textLoader = _remoteTextLoaderFactory.Create(hostDocument.FilePath);

            InternalProjectSnapshotManager.DocumentAdded(hostProject.InternalHostProject, hostDocument.InternalHostDocument, textLoader);
        }
Пример #16
0
 public override void ProjectRemoved(OmniSharpHostProject hostProject)
 {
     InternalProjectSnapshotManager.ProjectRemoved(hostProject.InternalHostProject);
 }
Пример #17
0
 public override void ProjectConfigurationChanged(OmniSharpHostProject hostProject)
 {
     InternalProjectSnapshotManager.ProjectConfigurationChanged(hostProject.InternalHostProject);
 }
Пример #18
0
 public override void DocumentRemoved(OmniSharpHostProject hostProject, OmniSharpHostDocument hostDocument)
 {
     InternalProjectSnapshotManager.DocumentRemoved(hostProject.InternalHostProject, hostDocument.InternalHostDocument);
 }
Пример #19
0
 public override void DocumentAdded(OmniSharpHostProject hostProject, OmniSharpHostDocument hostDocument)
 {
     InternalProjectSnapshotManager.DocumentAdded(hostProject.InternalHostProject, hostDocument.InternalHostDocument, textLoader: null);
 }