Skip to content

Commit b25d183

Browse files
committed
Simplify inclusion of ValueTuple reference for C# 7 testing
1 parent 7611192 commit b25d183

9 files changed

Lines changed: 30 additions & 92 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1000CSharp7UnitTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
55
{
6-
using System;
7-
using System.Linq;
8-
using System.Reflection;
96
using System.Threading.Tasks;
10-
using Microsoft.CodeAnalysis;
117
using StyleCop.Analyzers.Test.SpacingRules;
128
using TestHelper;
139
using Xunit;
@@ -75,14 +71,5 @@ ref @Int32 Call(ref @Int32 p)
7571

7672
await this.TestKeywordStatementAsync(statementWithoutSpace, expected, statementWithSpace).ConfigureAwait(false);
7773
}
78-
79-
protected override Solution CreateSolution(ProjectId projectId, string language)
80-
{
81-
Solution solution = base.CreateSolution(projectId, language);
82-
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime");
83-
return solution
84-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location))
85-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location));
86-
}
8774
}
8875
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1001CSharp7UnitTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
55
{
6-
using System;
7-
using System.Linq;
8-
using System.Reflection;
96
using System.Threading;
107
using System.Threading.Tasks;
11-
using Microsoft.CodeAnalysis;
128
using StyleCop.Analyzers.Test.SpacingRules;
139
using TestHelper;
1410
using Xunit;
@@ -92,14 +88,5 @@ public void TestMethod()
9288
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
9389
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
9490
}
95-
96-
protected override Solution CreateSolution(ProjectId projectId, string language)
97-
{
98-
Solution solution = base.CreateSolution(projectId, language);
99-
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime");
100-
return solution
101-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location))
102-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location));
103-
}
10491
}
10592
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1009CSharp7UnitTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
55
{
6-
using System;
7-
using System.Linq;
8-
using System.Reflection;
96
using System.Threading;
107
using System.Threading.Tasks;
11-
using Microsoft.CodeAnalysis;
128
using StyleCop.Analyzers.Test.SpacingRules;
139
using TestHelper;
1410
using Xunit;
@@ -92,14 +88,5 @@ public void TestMethod()
9288
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
9389
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
9490
}
95-
96-
protected override Solution CreateSolution(ProjectId projectId, string language)
97-
{
98-
Solution solution = base.CreateSolution(projectId, language);
99-
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime");
100-
return solution
101-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location))
102-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location));
103-
}
10491
}
10592
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1011CSharp7UnitTests.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
55
{
6-
using System;
7-
using System.Linq;
8-
using System.Reflection;
96
using System.Threading;
107
using System.Threading.Tasks;
11-
using Microsoft.CodeAnalysis;
128
using StyleCop.Analyzers.Test.SpacingRules;
13-
using TestHelper;
149
using Xunit;
1510

1611
public class SA1011CSharp7UnitTests : SA1011UnitTests
@@ -39,14 +34,5 @@ public class Foo
3934

4035
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
4136
}
42-
43-
protected override Solution CreateSolution(ProjectId projectId, string language)
44-
{
45-
Solution solution = base.CreateSolution(projectId, language);
46-
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime");
47-
return solution
48-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location))
49-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location));
50-
}
5137
}
5238
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1015CSharp7UnitTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
55
{
6-
using System;
7-
using System.Linq;
8-
using System.Reflection;
96
using System.Threading;
107
using System.Threading.Tasks;
11-
using Microsoft.CodeAnalysis;
128
using StyleCop.Analyzers.Test.SpacingRules;
139
using TestHelper;
1410
using Xunit;
@@ -54,14 +50,5 @@ public void TestMethod()
5450
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
5551
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
5652
}
57-
58-
protected override Solution CreateSolution(ProjectId projectId, string language)
59-
{
60-
Solution solution = base.CreateSolution(projectId, language);
61-
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime");
62-
return solution
63-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location))
64-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location));
65-
}
6653
}
6754
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1018CSharp7UnitTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
55
{
6-
using System;
7-
using System.Linq;
8-
using System.Reflection;
96
using System.Threading;
107
using System.Threading.Tasks;
11-
using Microsoft.CodeAnalysis;
128
using StyleCop.Analyzers.Test.SpacingRules;
139
using TestHelper;
1410
using Xunit;
@@ -107,14 +103,5 @@ public void TestMethod()
107103
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, fixedExpectedResults, CancellationToken.None).ConfigureAwait(false);
108104
await this.VerifyCSharpFixAsync(testCode, fixedTestCode, numberOfFixAllIterations: 2, cancellationToken: CancellationToken.None).ConfigureAwait(false);
109105
}
110-
111-
protected override Solution CreateSolution(ProjectId projectId, string language)
112-
{
113-
Solution solution = base.CreateSolution(projectId, language);
114-
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime");
115-
return solution
116-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location))
117-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location));
118-
}
119106
}
120107
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp7/SpacingRules/SA1024CSharp7UnitTests.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp7.SpacingRules
55
{
6-
using System;
7-
using System.Linq;
8-
using System.Reflection;
96
using System.Threading;
107
using System.Threading.Tasks;
11-
using Microsoft.CodeAnalysis;
128
using StyleCop.Analyzers.Test.SpacingRules;
139
using TestHelper;
1410
using Xunit;
@@ -53,14 +49,5 @@ public void TestMethod()
5349
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
5450
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
5551
}
56-
57-
protected override Solution CreateSolution(ProjectId projectId, string language)
58-
{
59-
Solution solution = base.CreateSolution(projectId, language);
60-
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().Single(x => x.GetName().Name == "System.Runtime");
61-
return solution
62-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(systemRuntime.Location))
63-
.AddMetadataReference(projectId, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location));
64-
}
6552
}
6653
}

StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ protected virtual Solution CreateSolution(ProjectId projectId, string language)
125125
.AddMetadataReference(projectId, MetadataReferences.CSharpSymbolsReference)
126126
.AddMetadataReference(projectId, MetadataReferences.CodeAnalysisReference);
127127

128+
if (MetadataReferences.SystemRuntimeReference != null)
129+
{
130+
solution = solution.AddMetadataReference(projectId, MetadataReferences.SystemRuntimeReference);
131+
}
132+
133+
if (MetadataReferences.SystemValueTupleReference != null)
134+
{
135+
solution = solution.AddMetadataReference(projectId, MetadataReferences.SystemValueTupleReference);
136+
}
137+
128138
solution.Workspace.Options =
129139
solution.Workspace.Options
130140
.WithChangedOption(FormattingOptions.IndentationSize, language, this.IndentationSize)

StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/MetadataReferences.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
namespace StyleCop.Analyzers.Test.Helpers
55
{
6+
using System;
67
using System.Collections.Immutable;
78
using System.Linq;
9+
using System.Reflection;
810
using Microsoft.CodeAnalysis;
911
using Microsoft.CodeAnalysis.CSharp;
1012

@@ -18,5 +20,23 @@ internal static class MetadataReferences
1820
internal static readonly MetadataReference SystemCoreReference = MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location);
1921
internal static readonly MetadataReference CSharpSymbolsReference = MetadataReference.CreateFromFile(typeof(CSharpCompilation).Assembly.Location);
2022
internal static readonly MetadataReference CodeAnalysisReference = MetadataReference.CreateFromFile(typeof(Compilation).Assembly.Location);
23+
24+
internal static readonly MetadataReference SystemRuntimeReference;
25+
internal static readonly MetadataReference SystemValueTupleReference;
26+
27+
static MetadataReferences()
28+
{
29+
Assembly systemRuntime = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(x => x.GetName().Name == "System.Runtime");
30+
if (systemRuntime != null)
31+
{
32+
SystemRuntimeReference = MetadataReference.CreateFromFile(systemRuntime.Location);
33+
}
34+
35+
Assembly systemValueTuple = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(x => x.GetName().Name == "System.ValueTuple");
36+
if (systemValueTuple != null)
37+
{
38+
SystemValueTupleReference = MetadataReference.CreateFromFile(systemValueTuple.Location);
39+
}
40+
}
2141
}
2242
}

0 commit comments

Comments
 (0)