Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,30 @@ jobs:
dotnet-version: |
11.0.x

- name: Restore tools
run: dotnet tool restore

- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build -c Release --no-restore
- name: Test
run: dotnet test -c Release --no-build -- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml
run: dotnet test -c Release --no-build -- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml --coverage-settings ./coverage-settings.xml

- name: Package
run: dotnet pack -c Release --no-build --property:PackageOutputPath=../../nupkgs
- name: Validate Package
run: dotnet tool run dotnet-validate -- package local ./nupkgs/*.nupkg

- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v6
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: >
tests/Immediate.Handlers.FunctionalTests/bin/Release/net8.0/TestResults/coverage.cobertura.xml
tests/Immediate.Handlers.FunctionalTests/bin/Release/net9.0/TestResults/coverage.cobertura.xml
tests/Immediate.Handlers.FunctionalTests/bin/Release/net10.0/TestResults/coverage.cobertura.xml
tests/Immediate.Handlers.FunctionalTests/bin/Release/net11.0/TestResults/coverage.cobertura.xml
tests/Immediate.Handlers.Tests/bin/Release/net8.0/TestResults/coverage.cobertura.xml
tests/Immediate.Handlers.Tests/bin/Release/net9.0/TestResults/coverage.cobertura.xml
tests/Immediate.Handlers.Tests/bin/Release/net10.0/TestResults/coverage.cobertura.xml
tests/Immediate.Handlers.Tests/bin/Release/net11.0/TestResults/coverage.cobertura.xml
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<LangVersion>latest</LangVersion>

<Nullable>enable</Nullable>
Expand All @@ -23,12 +24,12 @@
<Polyfill></Polyfill>
<Polyfill>$(Polyfill)|T:System.Index</Polyfill>
<Polyfill>$(Polyfill)|T:System.Range</Polyfill>
<Polyfill>$(Polyfill)|T:System.Diagnostics.CodeAnalysis</Polyfill>
<Polyfill>$(Polyfill)|T:System.Runtime.CompilerServices.CallerArgumentExpressionAttribute</Polyfill>
<Polyfill>$(Polyfill)|T:System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute</Polyfill>
<Polyfill>$(Polyfill)|T:System.Runtime.CompilerServices.IsExternalInit</Polyfill>
<Polyfill>$(Polyfill)|T:System.Runtime.CompilerServices.RequiredMemberAttribute</Polyfill>
<Polyfill>$(Polyfill)|T:System.Runtime.CompilerServices.SkipLocalsInitAttribute</Polyfill>
<Polyfill>$(Polyfill)|T:System.Diagnostics.CodeAnalysis</Polyfill>
<MeziantouPolyfill_IncludedPolyfills>$(Polyfill)</MeziantouPolyfill_IncludedPolyfills>
</PropertyGroup>

Expand Down
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing" Version="1.1.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.8.0" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.7.0" />
<PackageVersion Include="MinVer" Version="7.0.0" />
<PackageVersion Include="Scriban" Version="7.2.1" />
<!-- Locked until https://github.com/microsoft/codecoverage/issues/221 resolved -->
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="[18.4.1]" />
<PackageVersion Include="Scriban" Version="7.2.3" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="10.1.7" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.3" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.5.0" />
Expand Down Expand Up @@ -59,8 +59,8 @@

<ItemGroup>
<GlobalPackageReference Include="DotNet.ReproducibleBuilds" Version="2.0.2" PrivateAssets="All" />
<GlobalPackageReference Include="Meziantou.Analyzer" Version="3.0.94" PrivateAssets="All" />
<GlobalPackageReference Include="Meziantou.Polyfill" Version="1.0.135" PrivateAssets="All" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.300" PrivateAssets="All" />
<GlobalPackageReference Include="Meziantou.Analyzer" Version="3.0.98" PrivateAssets="All" />
<GlobalPackageReference Include="Meziantou.Polyfill" Version="1.0.140" PrivateAssets="All" />
<GlobalPackageReference Include="MinVer" Version="7.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions Immediate.Handlers.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<File Path=".editorconfig" />
<File Path=".github/dependabot.yml" />
<File Path=".gitignore" />
<File Path="coverage-settings.xml" />
<File Path="Directory.Build.props" />
<File Path="Directory.Packages.props" />
<File Path="dotnet-tools.json" />
<File Path="global.json" />
<File Path="readme.md" />
</Folder>
Expand Down
20 changes: 20 additions & 0 deletions coverage-settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<CodeCoverage>

<!-- Match attributes on any code element: -->
<Attributes>
<Exclude>
<!-- Don't forget "Attribute" at the end of the name -->
<Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
<Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>

<EnableStaticManagedInstrumentation>True</EnableStaticManagedInstrumentation>
<EnableDynamicManagedInstrumentation>True</EnableDynamicManagedInstrumentation>

</CodeCoverage>
</Configuration>
13 changes: 13 additions & 0 deletions dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-validate": {
"version": "0.0.1-preview.582",
"commands": [
"dotnet-validate"
],
"rollForward": true
}
}
}
9 changes: 1 addition & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![GitHub issues](https://img.shields.io/github/issues/ImmediatePlatform/Immediate.Handlers.svg)](https://GitHub.com/ImmediatePlatform/Immediate.Handlers/issues/)
[![GitHub issues-closed](https://img.shields.io/github/issues-closed/ImmediatePlatform/Immediate.Handlers.svg)](https://GitHub.com/ImmediatePlatform/Immediate.Handlers/issues?q=is%3Aissue+is%3Aclosed)
[![GitHub Actions](https://github.com/ImmediatePlatform/Immediate.Handlers/actions/workflows/build.yml/badge.svg)](https://github.com/ImmediatePlatform/Immediate.Handlers/actions)
[![Coverage Status](https://coveralls.io/repos/github/ImmediatePlatform/Immediate.Handlers/badge.svg)](https://coveralls.io/github/ImmediatePlatform/Immediate.Handlers)
---

Immediate.Handlers is an implementation of the mediator pattern in .NET using source-generation. All pipeline behaviors
Expand All @@ -17,16 +18,8 @@ safety checks. Behaviors and dependencies are obtained via DI at runtime based o

## Installing Immediate.Handlers

You can install [Immediate.Handlers with NuGet](https://www.nuget.org/packages/Immediate.Handlers):

Install-Package Immediate.Handlers

Or via the .NET Core command line interface:

dotnet add package Immediate.Handlers

Either commands, from Package Manager Console or .NET Core CLI, will download and install Immediate.Handlers.

## Using Immediate.Handlers
### Creating Handlers

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>
Expand All @@ -14,7 +14,6 @@
<PackageReference Include="Microsoft.Bcl.HashCode" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="MinVer" PrivateAssets="all" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>
Expand All @@ -19,7 +19,6 @@
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" />
<PackageReference Include="MinVer" PrivateAssets="all" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
<NoWarn>$(NoWarn);CA1716</NoWarn>
Expand All @@ -21,7 +21,6 @@
<PackageReference Include="Microsoft.Bcl.HashCode" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="MinVer" PrivateAssets="all" />
<PackageReference Include="Scriban" PrivateAssets="all" GeneratePathProperty="true" />
</ItemGroup>

Expand Down
12 changes: 5 additions & 7 deletions src/Immediate.Handlers/Immediate.Handlers.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>
Expand All @@ -11,7 +10,7 @@
<Description>An implementation of the mediator pattern in .NET using source-generation.</Description>

<Authors>Immediate.Handlers Developers</Authors>
<Copyright>© 2024-2025 Immediate.Handlers Developers</Copyright>
<Copyright>© 2024-2026 Immediate.Handlers Developers</Copyright>

<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>readme.md</PackageReadmeFile>
Expand All @@ -26,14 +25,14 @@
-->
<ItemGroup>
<None Include="../../readme.md" Pack="true" PackagePath="/" />
<None Include="../Immediate.Handlers.Analyzers/bin/$(Configuration)/netstandard2.0/Immediate.Handlers.Analyzers.dll" Pack="true" PackagePath="analyzers/roslyn4.8/dotnet/cs" Visible="true" />
<None Include="../Immediate.Handlers.CodeFixes/bin/$(Configuration)/netstandard2.0/Immediate.Handlers.CodeFixes.dll" Pack="true" PackagePath="analyzers/roslyn4.8/dotnet/cs" Visible="true" />
<None Include="../Immediate.Handlers.Generators/bin/$(Configuration)/netstandard2.0/Immediate.Handlers.Generators.dll" Pack="true" PackagePath="analyzers/roslyn4.8/dotnet/cs" Visible="true" />
<None Include="../Immediate.Handlers.Analyzers/bin/$(Configuration)/netstandard2.0/Immediate.Handlers.Analyzers.dll" Pack="true" PackagePath="analyzers/dotnet/roslyn4.8/cs" Visible="true" />
<None Include="../Immediate.Handlers.CodeFixes/bin/$(Configuration)/netstandard2.0/Immediate.Handlers.CodeFixes.dll" Pack="true" PackagePath="analyzers/dotnet/roslyn4.8/cs" Visible="true" />
<None Include="../Immediate.Handlers.Generators/bin/$(Configuration)/netstandard2.0/Immediate.Handlers.Generators.dll" Pack="true" PackagePath="analyzers/dotnet/roslyn4.8/cs" Visible="true" />

<TfmSpecificPackageFile
Include="$(PkgScriban)/lib/netstandard2.0/Scriban.dll"
Pack="true"
PackagePath="analyzers/roslyn4.8/dotnet/cs"
PackagePath="analyzers/dotnet/roslyn4.8/cs"
Condition=" '$(TargetFramework)' == 'net8.0' " />

<TfmSpecificPackageFile
Expand All @@ -49,7 +48,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="MinVer" PrivateAssets="all" />
<PackageReference Include="Scriban" PrivateAssets="all" GeneratePathProperty="true" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand Down
117 changes: 0 additions & 117 deletions tests/Immediate.Handlers.Tests/AnalyzerTests/AnalyzerTestHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Collections.Immutable;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Immediate.Handlers.Generators;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
Expand Down Expand Up @@ -38,118 +35,4 @@ private sealed class ImmediateHandlersGeneratorAnalyzerTest<TAnalyzer> : CSharpA
protected override IEnumerable<Type> GetSourceGenerators() =>
[typeof(ImmediateHandlersGenerator)];
}

public sealed class CSharpSuppressorTest<TSuppressor, TVerifier> : CSharpAnalyzerTest<TSuppressor, TVerifier>
where TSuppressor : DiagnosticSuppressor, new()
where TVerifier : IVerifier, new()
{
private readonly List<DiagnosticAnalyzer> _analyzers = [];

protected override IEnumerable<DiagnosticAnalyzer> GetDiagnosticAnalyzers() =>
base.GetDiagnosticAnalyzers().Concat(_analyzers);

public CSharpSuppressorTest<TSuppressor, TVerifier> WithAnalyzer<TAnalyzer>(bool enableDiagnostics = false)
where TAnalyzer : DiagnosticAnalyzer, new()
{
var analyzer = new TAnalyzer();
_analyzers.Add(analyzer);

if (enableDiagnostics)
{
var diagnosticOptions = analyzer.SupportedDiagnostics
.ToImmutableDictionary(
descriptor => descriptor.Id,
descriptor => descriptor.DefaultSeverity.ToReportDiagnostic()
);

SolutionTransforms.Clear();
SolutionTransforms.Add(EnableDiagnostics(diagnosticOptions));
}

return this;
}

public CSharpSuppressorTest<TSuppressor, TVerifier> WithSpecificDiagnostics(
params DiagnosticResult[] diagnostics
)
{
var diagnosticOptions = diagnostics
.ToImmutableDictionary(
descriptor => descriptor.Id,
descriptor => descriptor.Severity.ToReportDiagnostic()
);

SolutionTransforms.Clear();
SolutionTransforms.Add(EnableDiagnostics(diagnosticOptions));
return this;
}

private static Func<Solution, ProjectId, Solution> EnableDiagnostics(
ImmutableDictionary<string, ReportDiagnostic> diagnostics
) =>
(solution, id) =>
{
var options = solution.GetProject(id)?.CompilationOptions
?? throw new InvalidOperationException("Compilation options missing.");

return solution
.WithProjectCompilationOptions(
id,
options
.WithSpecificDiagnosticOptions(diagnostics)
);
};

public CSharpSuppressorTest<TSuppressor, TVerifier> WithExpectedDiagnosticsResults(
params DiagnosticResult[] diagnostics
)
{
ExpectedDiagnostics.AddRange(diagnostics);
return this;
}

public CSharpSuppressorTest<TSuppressor, TVerifier> WithEditorConfig(
string content
)
{
TestState.AnalyzerConfigFiles.Add(("/.editorconfig", content));
return this;
}
}

public static CSharpSuppressorTest<TSuppressor, DefaultVerifier> CreateSuppressorTest<TSuppressor>(
[StringSyntax("c#-test")] string inputSource
)
where TSuppressor : DiagnosticSuppressor, new()
{
var test = new CSharpSuppressorTest<TSuppressor, DefaultVerifier>
{
TestCode = inputSource,
ReferenceAssemblies = Utility.ReferenceAssemblies,
CompilerDiagnostics = CompilerDiagnostics.Warnings,
DisabledDiagnostics =
{
"CS1591",
"CS8767",
},
};

test.TestState.AdditionalReferences
.AddRange(Utility.GetAdditionalReferences());

return test;
}
}

file static class DiagnosticSeverityExtensions
{
public static ReportDiagnostic ToReportDiagnostic(this DiagnosticSeverity severity)
=> severity switch
{
DiagnosticSeverity.Hidden => ReportDiagnostic.Hidden,
DiagnosticSeverity.Info => ReportDiagnostic.Info,
DiagnosticSeverity.Warning => ReportDiagnostic.Warn,
DiagnosticSeverity.Error => ReportDiagnostic.Error,
_ => throw new InvalidEnumArgumentException(nameof(severity), (int)severity, typeof(DiagnosticSeverity)),
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<_SkipUpgradeNetAnalyzersNuGetWarning>true</_SkipUpgradeNetAnalyzersNuGetWarning>
</PropertyGroup>
Expand Down
Loading