ANcpLua.Roslyn.Utilities.Testing
1.2.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package ANcpLua.Roslyn.Utilities.Testing --version 1.2.2
NuGet\Install-Package ANcpLua.Roslyn.Utilities.Testing -Version 1.2.2
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="ANcpLua.Roslyn.Utilities.Testing" Version="1.2.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ANcpLua.Roslyn.Utilities.Testing" Version="1.2.2" />
<PackageReference Include="ANcpLua.Roslyn.Utilities.Testing" />
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 ANcpLua.Roslyn.Utilities.Testing --version 1.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ANcpLua.Roslyn.Utilities.Testing, 1.2.2"
#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 ANcpLua.Roslyn.Utilities.Testing@1.2.2
#: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=ANcpLua.Roslyn.Utilities.Testing&version=1.2.2
#tool nuget:?package=ANcpLua.Roslyn.Utilities.Testing&version=1.2.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ANcpLua.Roslyn.Utilities
Reusable utilities and fluent testing framework for Roslyn incremental source generators.
Packages
| Package | Description | Target |
|---|---|---|
ANcpLua.Roslyn.Utilities |
Core utilities for incremental generators | netstandard2.0 |
ANcpLua.Roslyn.Utilities.Testing |
Fluent testing framework | net10.0 |
Installation
# Core utilities for your generator project
dotnet add package ANcpLua.Roslyn.Utilities
# Testing framework for your test project
dotnet add package ANcpLua.Roslyn.Utilities.Testing
Core Utilities
EquatableArray<T>
A value-equal immutable array wrapper essential for incremental generator caching:
using ANcpLua.Roslyn.Utilities;
// Convert ImmutableArray to EquatableArray for proper caching
var items = myImmutableArray.AsEquatableArray();
// Use in pipeline outputs - enables proper caching
context.SyntaxProvider
.ForAttributeWithMetadataName("MyAttribute", ...)
.Select((ctx, _) => new MyModel { Items = GetItems(ctx).AsEquatableArray() });
Pipeline Extensions
using ANcpLua.Roslyn.Utilities;
// Simplified attribute filtering for classes and records
var provider = context.SyntaxProvider
.ForAttributeWithMetadataNameOfClassesAndRecords("MyNamespace.MyAttribute");
// Add generated sources with automatic file naming
provider.Select(GenerateFile).AddSource(context);
provider.Select(GenerateFiles).AddSources(context);
// Collect as EquatableArray for proper caching
var collected = provider.CollectAsEquatableArray();
// Exception handling with diagnostic reporting
provider.SelectAndReportExceptions(Transform, context);
String Extensions
using ANcpLua.Roslyn.Utilities;
// Convert to property/parameter names
"userName".ToPropertyName(); // "UserName"
"UserName".ToParameterName(); // "userName" (handles C# keywords)
// Text processing for generated code
source.TrimBlankLines(); // Remove whitespace-only lines
source.NormalizeLineEndings();
"MyNamespace.MyClass".ExtractNamespace(); // "MyNamespace"
"MyNamespace.MyClass".ExtractSimpleName(); // "MyClass"
"MyNamespace.MyClass".WithGlobalPrefix(); // "global::MyNamespace.MyClass"
Models
// Structured generator output
record struct FileWithName(string Name, string Text);
// Result with associated diagnostics
record struct ResultWithDiagnostics<T>(T Result, EquatableArray<Diagnostic> Diagnostics);
Testing Framework
Quick Start
using ANcpLua.Roslyn.Utilities.Testing;
[Fact]
public async Task Generator_ProducesExpectedOutput()
{
await """
[GenerateBuilder]
public class Person
{
public string Name { get; set; }
}
""".ShouldGenerate<MyGenerator>("Person.Builder.g.cs", """
public class PersonBuilder
{
public PersonBuilder WithName(string name) { ... }
}
""");
}
Testing Generated Output
// Verify exact content
await source.ShouldGenerate<MyGenerator>("Output.g.cs", expectedContent);
// Verify content contains substring
await source.ShouldGenerate<MyGenerator>("Output.g.cs", "public class Foo", exactMatch: false);
Testing Diagnostics
// Expect specific diagnostics
await "public class Invalid { }".ShouldHaveDiagnostics<MyGenerator>(
GeneratorTestExtensions.Diagnostic("GEN001", DiagnosticSeverity.Error)
.WithMessage("Missing required attribute")
);
// Expect no diagnostics
await "[Valid] public class Valid { }".ShouldHaveNoDiagnostics<MyGenerator>();
Testing Caching
Validate that your generator correctly caches intermediate results:
// Validate all observable pipeline steps are cached
await source.ShouldBeCached<MyGenerator>();
// Validate specific steps
await source.ShouldBeCached<MyGenerator>("TransformStep", "CollectStep");
The caching test validates:
- No forbidden types cached: ISymbol, Compilation, SyntaxNode, SemanticModel, SyntaxTree
- Proper caching: Pipeline steps produce Cached/Unchanged on second run
Configuration
// Configure language version and references
TestConfiguration.LanguageVersion = LanguageVersion.CSharp12;
TestConfiguration.ReferenceAssemblies = ReferenceAssemblies.Net.Net80;
// Add additional references for your generator's attributes
TestConfiguration.AdditionalReferences = [
MetadataReference.CreateFromFile(typeof(MyAttribute).Assembly.Location)
];
Direct Assertions
For more control, use the assertion API directly on run results:
// Assert on generator run results
result.Should().HaveGeneratedSource("Output.g.cs")
.Which.Should().HaveContent(expectedContent);
result.Should().HaveNoDiagnostics();
result.Should().NotHaveForbiddenTypes();
// Assert on caching report
report.Should().BeValidAndCached(["TransformStep"]);
License
MIT License - see LICENSE for details.
Contributing
Issues and pull requests welcome at GitHub.
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- ANcpLua.Roslyn.Utilities (>= 1.2.2)
- AwesomeAssertions (>= 9.3.0)
- Basic.Reference.Assemblies.Net100 (>= 1.8.4)
- Microsoft.CodeAnalysis.Analyzer.Testing (>= 1.1.3-beta1.24423.1)
- Microsoft.CodeAnalysis.CSharp (>= 5.0.0)
- Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing (>= 1.1.3-beta1.24423.1)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 5.0.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.13.0 | 0 | 1/18/2026 |
| 1.12.0 | 79 | 1/14/2026 |
| 1.11.0 | 37 | 1/14/2026 |
| 1.10.0 | 174 | 1/10/2026 |
| 1.9.0 | 43 | 1/10/2026 |
| 1.8.0 | 43 | 1/10/2026 |
| 1.7.0 | 86 | 1/10/2026 |
| 1.6.0 | 43 | 1/9/2026 |
| 1.5.1 | 44 | 1/9/2026 |
| 1.5.0 | 45 | 1/8/2026 |
| 1.3.1 | 55 | 12/30/2025 |
| 1.2.8 | 48 | 12/30/2025 |
| 1.2.7 | 48 | 12/30/2025 |
| 1.2.6 | 40 | 12/30/2025 |
| 1.2.4 | 43 | 12/30/2025 |
| 1.2.2 | 43 | 12/29/2025 |
| 1.2.1 | 45 | 12/29/2025 |
| 1.2.0 | 147 | 12/24/2025 |
| 1.0.0 | 102 | 12/20/2025 |