Skip to content

Commit 25d4560

Browse files
committed
Add support for Additional Files to GenericAnalyzerTest
1 parent f74a693 commit 25d4560

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/Verifiers/GenericAnalyzerTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace StyleCop.Analyzers.Test.Verifiers
2929
using StyleCop.Analyzers.Test.Helpers;
3030
using TestHelper;
3131
using Xunit;
32+
using Path = System.IO.Path;
3233

3334
internal abstract class GenericAnalyzerTest
3435
{
@@ -91,6 +92,8 @@ public string TestCode
9192

9293
public SourceFileList TestSources { get; }
9394

95+
public List<(string filename, string content)> AdditionalFiles { get; } = new List<(string filename, string content)>();
96+
9497
public Dictionary<string, string> XmlReferences { get; } = new Dictionary<string, string>();
9598

9699
public List<DiagnosticResult> ExpectedDiagnostics { get; } = new List<DiagnosticResult>();
@@ -485,6 +488,12 @@ protected virtual Solution CreateSolution(ProjectId projectId, string language)
485488
.AddMetadataReference(projectId, MetadataReferences.CSharpSymbolsReference)
486489
.AddMetadataReference(projectId, MetadataReferences.CodeAnalysisReference);
487490

491+
foreach (var (fileName, content) in this.AdditionalFiles)
492+
{
493+
var documentId = DocumentId.CreateNewId(projectId, fileName);
494+
solution = solution.AddAdditionalDocument(documentId, Path.GetFileName(fileName), content, filePath: fileName);
495+
}
496+
488497
if (MetadataReferences.SystemRuntimeReference != null)
489498
{
490499
solution = solution.AddMetadataReference(projectId, MetadataReferences.SystemRuntimeReference);

0 commit comments

Comments
 (0)