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 void TryResolveConfigurationOutputPath_NoIntermediateOutputPath_ReturnsFalse() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); // Act var result = MSBuildProjectManager.TryResolveConfigurationOutputPath(projectInstance, out var path); // Assert Assert.False(result); Assert.Null(path); }
public void GetProjectConfiguration_NoProviders_ReturnsNull() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem(MSBuildProjectManager.ProjectCapabilityItemType, CoreProjectConfigurationProvider.DotNetCoreRazorCapability); // Act var result = MSBuildProjectManager.GetProjectConfiguration(projectInstance, Enumerable.Empty<ProjectConfigurationProvider>()); // Assert Assert.Null(result); }
public void GetProjectConfiguration_SingleProviderReturnsFalse_ReturnsNull() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem(MSBuildProjectManager.ProjectCapabilityItemType, CoreProjectConfigurationProvider.DotNetCoreRazorCapability); var provider = new Mock<ProjectConfigurationProvider>(); var configuration = new ProjectConfiguration(RazorConfiguration.Default, Array.Empty<OmniSharpHostDocument>(), "TestRootNamespace"); // Setting to non-null to ensure the listener doesn't return the config verbatim. provider.Setup(p => p.TryResolveConfiguration(It.IsAny<ProjectConfigurationProviderContext>(), out configuration)) .Returns(false); // Act var result = MSBuildProjectManager.GetProjectConfiguration(projectInstance, Enumerable.Empty<ProjectConfigurationProvider>()); // Assert Assert.Null(result); }
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 void TryResolveConfigurationOutputPath_MSBuildIntermediateOutputPath_Normalizes() { // Arrange var projectRootElement = ProjectRootElement.Create(); // Note the ending \ here that gets normalized away. var intermediateOutputPath = "C:/project\\obj"; projectRootElement.AddProperty(MSBuildProjectManager.IntermediateOutputPathPropertyName, intermediateOutputPath); var projectInstance = new ProjectInstance(projectRootElement); var expectedPath = string.Format("C:{0}project{0}obj{0}{1}", Path.DirectorySeparatorChar, MSBuildProjectManager.RazorConfigurationFileName); // Act var result = MSBuildProjectManager.TryResolveConfigurationOutputPath(projectInstance, out var path); // Assert Assert.True(result); Assert.Equal(expectedPath, path); }
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 void GetProjectConfiguration_ProvidersReturnsTrue_ReturnsConfig() { // Arrange var projectInstance = new ProjectInstance(ProjectRootElement.Create()); projectInstance.AddItem(MSBuildProjectManager.ProjectCapabilityItemType, CoreProjectConfigurationProvider.DotNetCoreRazorCapability); var provider1 = new Mock <ProjectConfigurationProvider>(MockBehavior.Strict); var configuration = new ProjectConfiguration(RazorConfiguration.Default, Array.Empty <OmniSharpHostDocument>(), "TestRootNamespace"); // Setting to non-null to ensure the listener doesn't return the config verbatim. provider1.Setup(p => p.TryResolveConfiguration(It.IsAny <ProjectConfigurationProviderContext>(), out configuration)) .Returns(false); var provider2 = new Mock <ProjectConfigurationProvider>(MockBehavior.Strict); provider2.Setup(p => p.TryResolveConfiguration(It.IsAny <ProjectConfigurationProviderContext>(), out configuration)) .Returns(true); // Act var result = MSBuildProjectManager.GetProjectConfiguration(projectInstance, new[] { provider1.Object, provider2.Object }); // Assert Assert.Same(configuration, result); }
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);