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); }); }
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 ProjectLoadedAsync_AddsNewProjectWithDocument() { // Arrange var projectRootElement = ProjectRootElement.Create("/project/project.csproj"); var intermediateOutputPath = "/project/obj"; projectRootElement.AddProperty(MSBuildProjectManager.IntermediateOutputPathPropertyName, intermediateOutputPath); var projectInstance = new ProjectInstance(projectRootElement); var hostDocument = new OmniSharpHostDocument("file.razor", "file.razor", FileKinds.Component); var projectConfiguration = new ProjectConfiguration(CustomConfiguration, new[] { hostDocument }, "TestRootNamespace"); var configurationProvider = new Mock <ProjectConfigurationProvider>(MockBehavior.Strict); configurationProvider.Setup(provider => provider.TryResolveConfiguration(It.IsAny <ProjectConfigurationProviderContext>(), out projectConfiguration)) .Returns(true); var projectChangePublisher = new Mock <ProjectChangePublisher>(MockBehavior.Strict); projectChangePublisher.Setup(p => p.SetPublishFilePath(It.IsAny <string>(), It.IsAny <string>())).Verifiable(); var msbuildProjectManager = new MSBuildProjectManager( new[] { configurationProvider.Object }, CreateProjectInstanceEvaluator(), projectChangePublisher.Object, Dispatcher, LoggerFactory); var projectManager = CreateProjectSnapshotManager(); msbuildProjectManager.Initialize(projectManager); var args = new ProjectLoadedEventArgs( ProjectId.CreateNewId(), projectInstance, diagnostics: Enumerable.Empty <MSBuildDiagnostic>().ToImmutableArray(), isReload: false, projectIdIsDefinedInSolution: false, sourceFiles: Enumerable.Empty <string>().ToImmutableArray()); // Act await msbuildProjectManager.ProjectLoadedAsync(args); // Assert var project = await RunOnForegroundAsync(() => Assert.Single(projectManager.Projects)); Assert.Equal(projectInstance.ProjectFileLocation.File, project.FilePath); Assert.Same(CustomConfiguration, project.Configuration); var document = project.GetDocument(hostDocument.FilePath); Assert.NotNull(document); }
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); }
public async Task ProjectLoadedAsync_AddsNewProjectWithDocument() { // Arrange var projectRootElement = ProjectRootElement.Create("/project/project.csproj"); var intermediateOutputPath = "/project/obj"; projectRootElement.AddProperty(MSBuildProjectManager.IntermediateOutputPathPropertyName, intermediateOutputPath); var projectInstance = new ProjectInstance(projectRootElement); var hostDocument = new OmniSharpHostDocument("file.razor", "file.razor", FileKinds.Component); var projectConfiguration = new ProjectConfiguration(CustomConfiguration, new[] { hostDocument }, "TestRootNamespace"); var configurationProvider = new Mock <ProjectConfigurationProvider>(MockBehavior.Strict); configurationProvider.Setup(provider => provider.TryResolveConfiguration(It.IsAny <ProjectConfigurationProviderContext>(), out projectConfiguration)) .Returns(true); var projectChangePublisher = new Mock <ProjectChangePublisher>(MockBehavior.Strict); projectChangePublisher.Setup(p => p.SetPublishFilePath(It.IsAny <string>(), It.IsAny <string>())).Verifiable(); var msbuildProjectManager = new MSBuildProjectManager( new[] { configurationProvider.Object }, CreateProjectInstanceEvaluator(), projectChangePublisher.Object, Dispatcher, LoggerFactory); var projectManager = CreateProjectSnapshotManager(); msbuildProjectManager.Initialize(projectManager); var args = new ProjectLoadedEventArgs( id: null, project: null, sessionId: Guid.NewGuid(), projectInstance, diagnostics: Enumerable.Empty <MSBuildDiagnostic>().ToImmutableArray(), isReload: false, projectIdIsDefinedInSolution: false, sourceFiles: Enumerable.Empty <string>().ToImmutableArray(), sdkVersion: default);