cezarypiatek / RoslynTestKit

A lightweight framework for writing unit tests for Roslyn diagnostic analyzers, code fixes, refactorings and completion providers.
Other
24 stars 7 forks source link

Support AdditionalFiles in WithAnalyzers #24

Closed jerone closed 8 months ago

jerone commented 9 months ago

For testing purposes I want to define my own AdditionalFiles and AdditionalDocuments.

It appears to be possible via DiagnosticAnalyzerExtensions.WithAnalyzers method, third parameter analysisOptions, property AnalyzerOptions.AdditionalFiles. See https://stackoverflow.com/a/34052279/108448

Would it be possible to support this feature...

cezarypiatek commented 9 months ago

The API has been extended to allow for providing additional files https://github.com/cezarypiatek/RoslynTestKit/blob/master/src/RoslynTestKit/BaseTestFixture.cs#L19

sample usage

[Test]
public void should_verify_analyzer()
{
    var fixture = RoslynFixtureFactory.Create<SampleAnalyzer>(new () {
        AdditionalFiles= new []{
            new AnalyzerAdditionalFile("my_settings_file.json")
        };
    });

    //TODO: test your analyzer
}
jerone commented 8 months ago

This looks like exactly what was needed. Thanks.