Neon.Roslyn.Xunit 4.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package Neon.Roslyn.Xunit --version 4.0.5                
NuGet\Install-Package Neon.Roslyn.Xunit -Version 4.0.5                
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="Neon.Roslyn.Xunit" Version="4.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Neon.Roslyn.Xunit --version 4.0.5                
#r "nuget: Neon.Roslyn.Xunit, 4.0.5"                
#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.
// Install Neon.Roslyn.Xunit as a Cake Addin
#addin nuget:?package=Neon.Roslyn.Xunit&version=4.0.5

// Install Neon.Roslyn.Xunit as a Cake Tool
#tool nuget:?package=Neon.Roslyn.Xunit&version=4.0.5                

Neon.Roslyn.Xunit

This package provides some utilities to test Roslyn analyzers, code fix providers, and source generators using FluentAssertions.

Install

dotnet add package Neon.Roslyn.Xunit

Testing an analyzer

Verify generated source code

var inputSource = @"
namespace MyNamespace
{
    public partial class MyClass
    {
        public void MyMethod()
        {
            Console.WriteLine(""Hello, World!"");
        }
    }
}";

var expectedSource = @"
namespace MyNamespace
{
    public partial class MyClass
    {
        public void MyGeneratedMethod()
        {
            Console.WriteLine(""Hello, Roslyn!"");
        }
    }
}";

var testCompilation = new TestCompilationBuilder()
    .AddSourceGenerator<MySourceGenerator>()
    .AddSource(source)
    .Build();

// verify that the expected source code was generated
testCompilation.Should().ContainSource(expectedSource);

// verify the number of generated source files
testCompilation.Sources.Should().HaveCount(1);

Verify diagnostics

var testCompilation = new TestCompilationBuilder()
    .AddSourceGenerator<MySourceGenerator>()
    .AddSource(mySource)
    .Build();

// verify the number of diagnostics
testCompilation.Diagnostics.Should().HaveCount(2);

// verify the specific diagnostics using the diagnostic code
testCompilation.Should().HaveDiagnostics(["D1001", "D1002"]);

// verify the specific diagnostics using the diagnostic descriptor
testCompilation.Should().HaveDiagnostic(
    diagnostic: Diagnostic.Create(
        descriptor:  MyDiagnosticDescriptor,
        location:    Location.None,
        messageArgs: ["foo", 123]));

Adding assemblies to the compilation

var testCompilation = new TestCompilationBuilder()
    .AddSourceGenerator<MySourceGenerator>()
    .AddAssembly(typeof(MyType).Assembly)
    .Build();

Adding MSBuild options to the compilation

var testCompilation = new TestCompilationBuilder()
    .AddSourceGenerator<MySourceGenerator>()
    .AddOption("build_property.TargetFramework", "net8.0")
    .Build();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.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.

Version Downloads Last updated
4.0.11-preview.4 41 7/3/2024
4.0.11-preview.3 46 6/15/2024
4.0.11-preview.2 45 6/7/2024
4.0.11-preview.1 50 6/6/2024
4.0.11-preview.0 43 6/3/2024
4.0.10 96 4/25/2024
4.0.10-preview.0 51 4/25/2024
4.0.9 103 4/25/2024
4.0.8 177 3/29/2024
4.0.7 103 3/22/2024
4.0.6 112 3/19/2024
4.0.5 97 3/17/2024
4.0.4 153 2/24/2024
4.0.4-rc.12 65 2/24/2024
4.0.4-rc.11 52 2/23/2024
4.0.4-rc.10 62 2/22/2024
4.0.4-rc.8 64 2/21/2024
4.0.4-rc.7 53 2/21/2024
4.0.4-rc.6 57 2/21/2024
4.0.4-rc.5 51 2/21/2024
4.0.4-rc.4 54 2/21/2024
4.0.4-rc.2 46 2/20/2024
4.0.4-rc.1 53 2/16/2024
4.0.3 112 2/15/2024
4.0.3-rc.2 49 2/15/2024
4.0.3-rc.1 47 2/15/2024
4.0.2 77 2/15/2024
4.0.1 94 2/14/2024