Deepstaging.Roslyn.Testing
1.0.0-dev-20260205052640
dotnet add package Deepstaging.Roslyn.Testing --version 1.0.0-dev-20260205052640
NuGet\Install-Package Deepstaging.Roslyn.Testing -Version 1.0.0-dev-20260205052640
<PackageReference Include="Deepstaging.Roslyn.Testing" Version="1.0.0-dev-20260205052640" />
<PackageVersion Include="Deepstaging.Roslyn.Testing" Version="1.0.0-dev-20260205052640" />
<PackageReference Include="Deepstaging.Roslyn.Testing" />
paket add Deepstaging.Roslyn.Testing --version 1.0.0-dev-20260205052640
#r "nuget: Deepstaging.Roslyn.Testing, 1.0.0-dev-20260205052640"
#:package Deepstaging.Roslyn.Testing@1.0.0-dev-20260205052640
#addin nuget:?package=Deepstaging.Roslyn.Testing&version=1.0.0-dev-20260205052640&prerelease
#tool nuget:?package=Deepstaging.Roslyn.Testing&version=1.0.0-dev-20260205052640&prerelease
Deepstaging.Roslyn.Testing
Test utilities for Roslyn analyzers, generators, and code fixes.
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:
- SymbolTestContext — Query symbols from compiled source
- AnalyzerTestContext — Assert on analyzer diagnostics
- GeneratorTestContext — Assert on generator output
- CodeFixTestContext — Assert on code fix transformations
- TemplateTestContext — Assert on template rendering
Guides
- RoslynTestBase — Full API reference for the base class
- Reference Configuration — Configure assembly references for tests
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 | Versions 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. |
-
net10.0
- Basic.Reference.Assemblies.Net100 (>= 1.8.4)
- Deepstaging.Roslyn (>= 1.0.0-dev-20260205052640)
- Deepstaging.Roslyn.Scriban (>= 1.0.0-dev-20260205052640)
- Deepstaging.Roslyn.Workspace (>= 1.0.0-dev-20260205052640)
- LanguageExt.Core (>= 5.0.0-beta-77)
- Microsoft.CodeAnalysis.CSharp (>= 5.0.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 5.0.0)
- TUnit (>= 1.12.125)
- TUnit.Engine (>= 1.12.125)
- Verify (>= 31.10.0)
- Verify.TUnit (>= 31.10.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-dev-20260205052640 | 18 | 2/5/2026 |
| 1.0.0-dev-20260205050756 | 26 | 2/5/2026 |
| 1.0.0-dev-20260204225221 | 30 | 2/4/2026 |
| 1.0.0-dev-20260204225018 | 28 | 2/4/2026 |
| 1.0.0-dev-20260204223024 | 24 | 2/4/2026 |
| 1.0.0-dev-20260204222744 | 28 | 2/4/2026 |
| 1.0.0-dev-20260204221656 | 25 | 2/4/2026 |
| 1.0.0-dev-20260204221327 | 29 | 2/4/2026 |
| 1.0.0-dev-20260204221227 | 27 | 2/4/2026 |
| 1.0.0-dev-20260204221019 | 31 | 2/4/2026 |
| 1.0.0-dev-20260204220308 | 28 | 2/4/2026 |