Deepstaging.Roslyn.Testing 1.0.0-dev-20260205052640

This is a prerelease version of Deepstaging.Roslyn.Testing.
dotnet add package Deepstaging.Roslyn.Testing --version 1.0.0-dev-20260205052640
                    
NuGet\Install-Package Deepstaging.Roslyn.Testing -Version 1.0.0-dev-20260205052640
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Deepstaging.Roslyn.Testing" Version="1.0.0-dev-20260205052640" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Deepstaging.Roslyn.Testing" Version="1.0.0-dev-20260205052640" />
                    
Directory.Packages.props
<PackageReference Include="Deepstaging.Roslyn.Testing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Deepstaging.Roslyn.Testing --version 1.0.0-dev-20260205052640
                    
#r "nuget: Deepstaging.Roslyn.Testing, 1.0.0-dev-20260205052640"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Deepstaging.Roslyn.Testing@1.0.0-dev-20260205052640
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Deepstaging.Roslyn.Testing&version=1.0.0-dev-20260205052640&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Deepstaging.Roslyn.Testing&version=1.0.0-dev-20260205052640&prerelease
                    
Install as a Cake Tool

Deepstaging.Roslyn.Testing

Test utilities for Roslyn analyzers, generators, and code fixes.

📚 Full Documentation

See also: RoslynTestBase | Reference Configuration | Roslyn Toolkit

Quick Start

All tests inherit from RoslynTestBase:

public class MyTests : RoslynTestBase
{
    [Test]
    public async Task TestSymbols()
    {
        var type = SymbolsFor("public class Foo { }").RequireNamedType("Foo");
        await Assert.That(type.Value.Name).IsEqualTo("Foo");
    }

    [Test]
    public async Task TestAnalyzer()
    {
        await AnalyzeWith<MyAnalyzer>(source)
            .ShouldReportDiagnostic("MY001");
    }

    [Test]
    public async Task TestGenerator()
    {
        await GenerateWith<MyGenerator>(source)
            .ShouldGenerate()
            .VerifySnapshot();
    }

    [Test]
    public async Task TestCodeFix()
    {
        await AnalyzeAndFixWith<MyAnalyzer, MyCodeFix>(source)
            .ForDiagnostic("MY001")
            .ShouldProduce(expectedSource);
    }
}

Reference Configuration

If tests need your own assemblies, configure once via ModuleInitializer:

[ModuleInitializer]
public static void Init() =>
    ReferenceConfiguration.AddReferencesFromTypes(typeof(MyAttribute));

Entry Points

Method Description
SymbolsFor(source) Create compilation and query symbols
CompilationFor(source) Get the raw compilation
AnalyzeWith<T>(source) Run analyzer and assert diagnostics
GenerateWith<T>(source) Run generator and assert output
FixWith<T>(source) Test code fix for compiler diagnostics
AnalyzeAndFixWith<TAnalyzer, TCodeFix>(source) Test code fix for analyzer diagnostics
RenderTemplateFrom<T>(source) Test Scriban template rendering

Documentation

Test Contexts

Each entry point returns a test context with fluent assertions:

Guides


Quick Examples

Symbol Testing

var ctx = SymbolsFor(source);

// Get types and members
var type = ctx.RequireNamedType("Customer");
var methods = ctx.Type("Customer").Methods().ThatArePublic().GetAll();

Analyzer Testing

await AnalyzeWith<MyAnalyzer>(source)
    .ShouldReportDiagnostic("MY001")
    .WithSeverity(DiagnosticSeverity.Error)
    .WithMessage("*must be partial*");

Generator Testing

await GenerateWith<MyGenerator>(source)
    .ShouldGenerate()
    .WithFileCount(2)
    .WithFileNamed("Customer.g.cs")
    .WithNoDiagnostics()
    .VerifySnapshot();

Code Fix Testing

await AnalyzeAndFixWith<MyAnalyzer, MyCodeFix>(source)
    .ForDiagnostic("MY001")
    .ShouldProduce(expectedSource);

Template Testing

await RenderTemplateFrom<MyGenerator>(source)
    .Render("MyTemplate.scriban-cs", ctx => new { Name = ctx.RequireNamedType("Foo").Value.Name })
    .ShouldRender()
    .VerifySnapshot();

License

RPL-1.5 (Reciprocal Public License) — Real reciprocity, no loopholes.

You can use this code, modify it, and share it freely. But when you deploy it — internally or externally, as a service or within your company — you share your improvements back under the same license.

Why? We believe if you benefit from this code, the community should benefit from your improvements. That's the deal we think is fair.

Personal research and experimentation? No obligations. Go learn, explore, and build.

See LICENSE for the full legal text.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.