public async Task SynchronizeDocuments_IgnoresTrackedDocuments()
        {
            // Arrange
            var hostDocument = new OmniSharpHostDocument("file.razor", "file.razor", FileKinds.Component);
            var configuredHostDocuments = new[] { hostDocument };
            var msbuildProjectManager = new MSBuildProjectManager(
                Enumerable.Empty<ProjectConfigurationProvider>(),
                ProjectInstanceEvaluator,
                Mock.Of<ProjectChangePublisher>(),
                Dispatcher,
                LoggerFactory);
            var projectManager = CreateProjectSnapshotManager(allowNotifyListeners: true);
            msbuildProjectManager.Initialize(projectManager);
            var hostProject = new OmniSharpHostProject("/path/to/project.csproj", CustomConfiguration, "TestRootNamespace");
            var projectSnapshot = await RunOnForegroundAsync(() =>
            {
                projectManager.ProjectAdded(hostProject);
                projectManager.DocumentAdded(hostProject, hostDocument);
                return projectManager.GetLoadedProject(hostProject.FilePath);
            });
            projectManager.Changed += (sender, args) => throw new XunitException("Should not have been notified");

            // Act & Assert
            await RunOnForegroundAsync(() =>
                msbuildProjectManager.SynchronizeDocuments(
                    configuredHostDocuments,
                    projectSnapshot,
                    hostProject));
        }
        public async Task SynchronizeDocuments_RemovesTrackedDocuments()
        {
            // Arrange
            var msbuildProjectManager = new MSBuildProjectManager(
                Enumerable.Empty<ProjectConfigurationProvider>(),
                ProjectInstanceEvaluator,
                Mock.Of<ProjectChangePublisher>(),
                Dispatcher,
                LoggerFactory);
            var projectManager = CreateProjectSnapshotManager();
            msbuildProjectManager.Initialize(projectManager);
            var hostProject = new OmniSharpHostProject("/path/to/project.csproj", CustomConfiguration, "TestRootNamespace");
            var projectSnapshot = await RunOnForegroundAsync(() =>
            {
                projectManager.ProjectAdded(hostProject);
                var hostDocument = new OmniSharpHostDocument("file.razor", "file.razor", FileKinds.Component);
                projectManager.DocumentAdded(hostProject, hostDocument);
                return projectManager.GetLoadedProject(hostProject.FilePath);
            });

            // Act
            await RunOnForegroundAsync(() =>
                msbuildProjectManager.SynchronizeDocuments(
                    configuredHostDocuments: Array.Empty<OmniSharpHostDocument>(),
                    projectSnapshot,
                    hostProject));

            // Assert
            await RunOnForegroundAsync(() =>
            {
                var refreshedProject = projectManager.GetLoadedProject(hostProject.FilePath);
                Assert.Empty(refreshedProject.DocumentFilePaths);
            });
        }
Exemple #3
0
        public async Task SynchronizeDocuments_UpdatesDocumentKinds()
        {
            // Arrange
            var msbuildProjectManager = new MSBuildProjectManager(
                Enumerable.Empty <ProjectConfigurationProvider>(),
                CreateProjectInstanceEvaluator(),
                Mock.Of <ProjectChangePublisher>(MockBehavior.Strict),
                Dispatcher,
                LoggerFactory);
            var projectManager = CreateProjectSnapshotManager();

            msbuildProjectManager.Initialize(projectManager);
            var hostProject             = new OmniSharpHostProject("/path/to/project.csproj", CustomConfiguration, "TestRootNamespace");
            var configuredHostDocuments = new[]
            {
                new OmniSharpHostDocument("file.cshtml", "file.cshtml", FileKinds.Component),
            };
            var projectSnapshot = await RunOnDispatcherThreadAsync(() =>
            {
                projectManager.ProjectAdded(hostProject);
                var hostDocument = new OmniSharpHostDocument("file.cshtml", "file.cshtml", FileKinds.Legacy);
                projectManager.DocumentAdded(hostProject, hostDocument);
                return(projectManager.GetLoadedProject(hostProject.FilePath));
            }).ConfigureAwait(false);

            // Act
            await RunOnDispatcherThreadAsync(() =>
                                             msbuildProjectManager.SynchronizeDocuments(
                                                 configuredHostDocuments,
                                                 projectSnapshot,
                                                 hostProject)).ConfigureAwait(false);

            // Assert
            await RunOnDispatcherThreadAsync(() =>
            {
                var refreshedProject = projectManager.GetLoadedProject(hostProject.FilePath);
                var documentFilePath = Assert.Single(refreshedProject.DocumentFilePaths);
                var document         = refreshedProject.GetDocument(documentFilePath);
                Assert.Equal("file.cshtml", document.FilePath);
                Assert.Equal("file.cshtml", document.TargetPath);
                Assert.Equal(FileKinds.Component, document.FileKind);
            }).ConfigureAwait(false);
        }