提交 2d86a7b6 编写于 作者: J Jason Malinowski

Fix up some more tests, and delete some that are now redundant

We had separate tests for P2P conversion for both legacy shims and
through the CPS APIs. Now tha the code is identical, we'll keep just
the CPS ones.
上级 fe7c8359
......@@ -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()
</Rules>
</RuleSet>
";
string ruleSetSource2 = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""12.0"">
<IncludeAll Action=""Warning"" />
<Rules AnalyzerId=""Microsoft.Analyzers.ManagedCodeAnalysis"" RuleNamespace=""Microsoft.Rules.Managed"">
<Rule Id=""CA1012"" Action=""Warning"" />
</Rules>
</RuleSet>
";
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);
}
}
*/
}
}
// 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<ProjectReference> GetProject3ProjectReferences()
{
return environment.Workspace
.CurrentSolution.GetProject(project3.Id).ProjectReferences;
}
IEnumerable<PortableExecutableReference> GetProject3MetadataReferences()
{
return environment.Workspace.CurrentSolution.GetProject(project3.Id)
.MetadataReferences
.Cast<PortableExecutableReference>();
}
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<AnalyzerReference>()
.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());
}
}
*/
}
}
// 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();
}
}
*/
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册