diff --git a/src/VisualStudio/CSharp/Test/ProjectSystemShim/CPS/AnalyzersTests.cs b/src/VisualStudio/CSharp/Test/ProjectSystemShim/CPS/AnalyzersTests.cs index a0013a90e4ec4d4e21057883c18c40cdcd3e2feb..1830a6acb3885330d003c1af9d10f134d39e7c8c 100644 --- a/src/VisualStudio/CSharp/Test/ProjectSystemShim/CPS/AnalyzersTests.cs +++ b/src/VisualStudio/CSharp/Test/ProjectSystemShim/CPS/AnalyzersTests.cs @@ -16,7 +16,6 @@ namespace Roslyn.VisualStudio.CSharp.UnitTests.ProjectSystemShim.CPS [UseExportProvider] public class AnalyzersTests { - /* [WpfFact] [Trait(Traits.Feature, Traits.Features.ProjectSystemShims)] public void RuleSet_GeneralOption_CPS() @@ -37,7 +36,6 @@ public void RuleSet_GeneralOption_CPS() Assert.Equal(expected: ReportDiagnostic.Default, actual: options.GeneralDiagnosticOption); - project.SetRuleSetFile(ruleSetFile.Path); project.SetOptions($"/ruleset:{ruleSetFile.Path}"); workspaceProject = environment.Workspace.CurrentSolution.Projects.Single(); @@ -59,38 +57,20 @@ public void RuleSet_SpecificOptions_CPS() "; - string ruleSetSource2 = @" - - - - - - -"; + using (var ruleSetFile = new DisposableFile()) using (var environment = new TestEnvironment()) using (var project = CSharpHelpers.CreateCSharpCPSProject(environment, "Test")) { - Assert.Null(project.RuleSetFile); - // Verify SetRuleSetFile updates the ruleset. File.WriteAllText(ruleSetFile.Path, ruleSetSource); - project.SetRuleSetFile(ruleSetFile.Path); - Assert.Equal(ruleSetFile.Path, project.RuleSetFile.Target.FilePath); + project.SetOptions($"/ruleset:{ruleSetFile.Path}"); // We need to explicitly update the command line arguments so the new ruleset is used to update options. project.SetOptions($"/ruleset:{ruleSetFile.Path}"); - var ca1012DiagnosticOption = project.CurrentCompilationOptions.SpecificDiagnosticOptions["CA1012"]; + var ca1012DiagnosticOption = environment.Workspace.CurrentSolution.Projects.Single().CompilationOptions.SpecificDiagnosticOptions["CA1012"]; Assert.Equal(expected: ReportDiagnostic.Error, actual: ca1012DiagnosticOption); - - // Verify edits to the ruleset file updates options. - var lastOptions = project.CurrentCompilationOptions; - File.WriteAllText(ruleSetFile.Path, ruleSetSource2); - project.OnRuleSetFileUpdateOnDisk(this, EventArgs.Empty); - ca1012DiagnosticOption = project.CurrentCompilationOptions.SpecificDiagnosticOptions["CA1012"]; - Assert.Equal(expected: ReportDiagnostic.Warn, actual: ca1012DiagnosticOption); } } - */ } } diff --git a/src/VisualStudio/CSharp/Test/ProjectSystemShim/CPS/CSharpReferencesTests.cs b/src/VisualStudio/CSharp/Test/ProjectSystemShim/CPS/CSharpReferencesTests.cs index 5decf0b3af49be4d95f32bf660f82546cc59a7e4..e0c8b558118bcf36153d67ff30e9d11807e93ee3 100644 --- a/src/VisualStudio/CSharp/Test/ProjectSystemShim/CPS/CSharpReferencesTests.cs +++ b/src/VisualStudio/CSharp/Test/ProjectSystemShim/CPS/CSharpReferencesTests.cs @@ -1,21 +1,22 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System.Collections.Generic; using System.Linq; using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Test.Utilities; +using Microsoft.VisualStudio.LanguageServices.ProjectSystem; using Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Framework; using Roslyn.Test.Utilities; using Xunit; namespace Roslyn.VisualStudio.CSharp.UnitTests.ProjectSystemShim.CPS { - using Microsoft.VisualStudio.LanguageServices.ProjectSystem; using static CSharpHelpers; [UseExportProvider] public class CSharpReferenceTests { - /* [WpfFact] [Trait(Traits.Feature, Traits.Features.ProjectSystemShims)] public void AddRemoveProjectAndMetadataReference_CPS() @@ -40,16 +41,29 @@ public void AddRemoveProjectAndMetadataReference_CPS() var metadaRefFilePath = @"c:\someAssembly.dll"; project3.AddMetadataReference(metadaRefFilePath, new MetadataReferenceProperties(embedInteropTypes: true)); - Assert.True(project3.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project1.Id)); - Assert.True(project3.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project2.Id)); - Assert.True(project3.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project4.Id)); - Assert.True(project3.GetCurrentMetadataReferences().Any(mr => mr.FilePath == metadaRefFilePath)); + IEnumerable GetProject3ProjectReferences() + { + return environment.Workspace + .CurrentSolution.GetProject(project3.Id).ProjectReferences; + } + + IEnumerable GetProject3MetadataReferences() + { + return environment.Workspace.CurrentSolution.GetProject(project3.Id) + .MetadataReferences + .Cast(); + } + + Assert.True(GetProject3ProjectReferences().Any(pr => pr.ProjectId == project1.Id)); + Assert.True(GetProject3ProjectReferences().Any(pr => pr.ProjectId == project2.Id)); + Assert.True(GetProject3ProjectReferences().Any(pr => pr.ProjectId == project4.Id)); + Assert.True(GetProject3MetadataReferences().Any(mr => mr.FilePath == metadaRefFilePath)); // Change output path for project reference and verify the reference. ((IWorkspaceProjectContext)project4).BinOutputPath = @"C:\project4.dll"; Assert.Equal(@"C:\project4.dll", project4.BinOutputPath); - Assert.True(project3.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project4.Id)); + Assert.True(GetProject3ProjectReferences().Any(pr => pr.ProjectId == project4.Id)); // Remove project reference project3.RemoveProjectReference(project1); @@ -60,9 +74,9 @@ public void AddRemoveProjectAndMetadataReference_CPS() // Remove metadata reference project3.RemoveMetadataReference(metadaRefFilePath); - Assert.False(project3.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project1.Id)); - Assert.False(project3.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project2.Id)); - Assert.False(project3.GetCurrentMetadataReferences().Any(mr => mr.FilePath == metadaRefFilePath)); + Assert.False(GetProject3ProjectReferences().Any(pr => pr.ProjectId == project1.Id)); + Assert.False(GetProject3ProjectReferences().Any(pr => pr.ProjectId == project2.Id)); + Assert.False(GetProject3MetadataReferences().Any(mr => mr.FilePath == metadaRefFilePath)); project1.Dispose(); project2.Dispose(); @@ -80,14 +94,21 @@ public void AddRemoveAnalyzerReference_CPS() { // Add analyzer reference var analyzerAssemblyFullPath = @"c:\someAssembly.dll"; + + bool AnalyzersContainsAnalyzer() + { + return environment.Workspace.CurrentSolution.Projects.Single() + .AnalyzerReferences.Cast() + .Any(a => a.FullPath == analyzerAssemblyFullPath); + } + project.AddAnalyzerReference(analyzerAssemblyFullPath); - Assert.True(project.CurrentProjectAnalyzersContains(analyzerAssemblyFullPath)); + Assert.True(AnalyzersContainsAnalyzer()); // Remove analyzer reference project.RemoveAnalyzerReference(analyzerAssemblyFullPath); - Assert.False(project.CurrentProjectAnalyzersContains(analyzerAssemblyFullPath)); + Assert.False(AnalyzersContainsAnalyzer()); } } - */ } } diff --git a/src/VisualStudio/CSharp/Test/ProjectSystemShim/LegacyProject/CSharpReferencesTests.cs b/src/VisualStudio/CSharp/Test/ProjectSystemShim/LegacyProject/CSharpReferencesTests.cs deleted file mode 100644 index 61cc28ce3bc20db8094f13934749ae2b0bd1d7ce..0000000000000000000000000000000000000000 --- a/src/VisualStudio/CSharp/Test/ProjectSystemShim/LegacyProject/CSharpReferencesTests.cs +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Test.Utilities; -using Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Framework; -using Roslyn.Test.Utilities; -using Xunit; - -namespace Roslyn.VisualStudio.CSharp.UnitTests.ProjectSystemShim.LegacyProject -{ - using static CSharpHelpers; - - [UseExportProvider] - public class CSharpReferenceTests - { - /* - [WpfFact] - [Trait(Traits.Feature, Traits.Features.ProjectSystemShims)] - public void AddingReferenceToProjectMetadataPromotesToProjectReference() - { - using (var environment = new TestEnvironment()) - { - var project1 = CreateCSharpProject(environment, "project1"); - project1.SetBinOutputPathAndRelatedData(@"c:\project1.dll"); - - var project2 = CreateCSharpProject(environment, "project2"); - project2.SetBinOutputPathAndRelatedData(@"c:\project2.dll"); - - // since this is known to be the output path of project1, the metadata reference is converted to a project reference - project2.OnImportAdded(@"c:\project1.dll", "project1"); - - Assert.Equal(true, project2.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project1.Id)); - - project2.Disconnect(); - project1.Disconnect(); - } - } - - [WpfFact] - [Trait(Traits.Feature, Traits.Features.ProjectSystemShims)] - public void AddCyclicProjectMetadataReferences() - { - using (var environment = new TestEnvironment()) - { - var project1 = CreateCSharpProject(environment, "project1"); - project1.SetBinOutputPathAndRelatedData(@"c:\project1.dll"); - - var project2 = CreateCSharpProject(environment, "project2"); - project2.SetBinOutputPathAndRelatedData(@"c:\project2.dll"); - - project1.AddProjectReference(new ProjectReference(project2.Id)); - - // normally this metadata reference would be elevated to a project reference, but fails because of cyclicness - project2.OnImportAdded(@"c:\project1.dll", "project1"); - - Assert.Equal(true, project1.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project2.Id)); - Assert.Equal(false, project2.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project1.Id)); - - project2.Disconnect(); - project1.Disconnect(); - } - } - - [WpfFact] - [Trait(Traits.Feature, Traits.Features.ProjectSystemShims)] - public void AddCyclicProjectReferences() - { - using (var environment = new TestEnvironment()) - { - var project1 = CreateCSharpProject(environment, "project1"); - var project2 = CreateCSharpProject(environment, "project2"); - - project1.AddProjectReference(new ProjectReference(project2.Id)); - project2.AddProjectReference(new ProjectReference(project1.Id)); - - Assert.Equal(true, project1.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project2.Id)); - Assert.Equal(false, project2.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project1.Id)); - - project2.Disconnect(); - project1.Disconnect(); - } - } - - [WpfFact] - [Trait(Traits.Feature, Traits.Features.ProjectSystemShims)] - public void AddCyclicProjectReferencesDeep() - { - using (var environment = new TestEnvironment()) - { - var project1 = CreateCSharpProject(environment, "project1"); - var project2 = CreateCSharpProject(environment, "project2"); - var project3 = CreateCSharpProject(environment, "project3"); - var project4 = CreateCSharpProject(environment, "project4"); - - project1.AddProjectReference(new ProjectReference(project2.Id)); - project2.AddProjectReference(new ProjectReference(project3.Id)); - project3.AddProjectReference(new ProjectReference(project4.Id)); - project4.AddProjectReference(new ProjectReference(project1.Id)); - - Assert.Equal(true, project1.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project2.Id)); - Assert.Equal(true, project2.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project3.Id)); - Assert.Equal(true, project3.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project4.Id)); - Assert.Equal(false, project4.GetCurrentProjectReferences().Any(pr => pr.ProjectId == project1.Id)); - - project4.Disconnect(); - project3.Disconnect(); - project2.Disconnect(); - project1.Disconnect(); - } - } - - [WorkItem(12707, "https://github.com/dotnet/roslyn/issues/12707")] - [WpfFact] - [Trait(Traits.Feature, Traits.Features.ProjectSystemShims)] - public void AddingProjectReferenceAndUpdateReferenceBinPath() - { - using (var environment = new TestEnvironment()) - { - var project1 = CreateCSharpProject(environment, "project1"); - project1.SetBinOutputPathAndRelatedData(@"c:\project1.dll"); - - var project2 = CreateCSharpProject(environment, "project2"); - project2.SetBinOutputPathAndRelatedData(@"c:\project2.dll"); - - // since this is known to be the output path of project1, the metadata reference is converted to a project reference - project2.OnImportAdded(@"c:\project1.dll", "project1"); - - Assert.Single(project2.GetCurrentProjectReferences().Where(pr => pr.ProjectId == project1.Id)); - - // update bin bath for project1. - project1.SetBinOutputPathAndRelatedData(@"c:\new_project1.dll"); - - // Verify project reference updated after bin path change. - Assert.Empty(project2.GetCurrentProjectReferences()); - - // This is a metadata reference to the original path - var metadataReference = Assert.Single(project2.GetCurrentMetadataReferences()); - Assert.Equal(@"c:\project1.dll", metadataReference.FilePath); - - project2.Disconnect(); - project1.Disconnect(); - } - } - - [WorkItem(12707, "https://github.com/dotnet/roslyn/issues/12707")] - [WpfFact] - [Trait(Traits.Feature, Traits.Features.ProjectSystemShims)] - public void DisconnectingProjectShouldConvertConvertedReferencesBack() - { - using (var environment = new TestEnvironment()) - { - var project1 = CreateCSharpProject(environment, "project1"); - project1.SetBinOutputPathAndRelatedData(@"c:\project1.dll"); - - var project2 = CreateCSharpProject(environment, "project2"); - project2.SetBinOutputPathAndRelatedData(@"c:\project2.dll"); - - // since this is known to be the output path of project1, the metadata reference is converted to a project reference - project2.OnImportAdded(@"c:\project1.dll", "project1"); - - Assert.Single(project2.GetCurrentProjectReferences().Where(pr => pr.ProjectId == project1.Id)); - - project1.Disconnect(); - - // Verify project reference updated after bin path change. - Assert.Empty(project2.GetCurrentProjectReferences()); - Assert.Single(project2.GetCurrentMetadataReferences().Where(r => r.FilePath == @"c:\project1.dll")); - - project2.Disconnect(); - } - } - - [WorkItem(461967, "https://devdiv.visualstudio.com/DevDiv/_workitems/edit/461967")] - [WpfFact()] - [Trait(Traits.Feature, Traits.Features.ProjectSystemShims)] - public void AddingMetadataReferenceToProjectThatCannotCompileInTheIdeKeepsMetadataReference() - { - using (var environment = new TestEnvironment()) - { - var project1 = CreateCSharpProject(environment, "project1"); - project1.SetBinOutputPathAndRelatedData(@"c:\project1.dll"); - - var project2 = CreateNonCompilableProject(environment, "project2", @"C:\project2.fsproj"); - project2.SetBinOutputPathAndRelatedData(@"c:\project2.dll"); - - project1.OnImportAdded(@"c:\project2.dll", "project2"); - - // We shoudl not have converted that to a project reference, because we would have no way to produce the compilation - Assert.Empty(project1.GetCurrentProjectReferences()); - - project2.Disconnect(); - project1.Disconnect(); - } - } - */ - } -}