Skip to content

Commit

Permalink
Merge pull request #955 from jbogard/net8
Browse files Browse the repository at this point in the history
Adding tests and upgrading to .NET 8
  • Loading branch information
jbogard authored Nov 16, 2023
2 parents c295291 + fcb6f96 commit 89262b8
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
- name: Setup dotnet 8.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0.100-rc.2.23502.2'
- name: Build and Test
run: ./Build.ps1
shell: pwsh
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -10,9 +10,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.5.0" />
<PackageReference Include="Autofac" Version="7.1.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -10,8 +10,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DryIoc.Microsoft.DependencyInjection" Version="6.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="DryIoc.Microsoft.DependencyInjection" Version="6.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

</Project>
7 changes: 4 additions & 3 deletions samples/MediatR.Examples.Lamar/MediatR.Examples.Lamar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lamar" Version="8.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Lamar" Version="12.1.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -10,9 +10,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="LightInject" Version="6.6.1" />
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="3.6.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="LightInject" Version="6.6.4" />
<PackageReference Include="LightInject.Microsoft.DependencyInjection" Version="3.7.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand All @@ -10,9 +10,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SimpleInjector" Version="5.4.1" />
<PackageReference Include="SimpleInjector.Integration.ServiceCollection" Version="5.4.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="SimpleInjector" Version="5.4.2" />
<PackageReference Include="SimpleInjector.Integration.ServiceCollection" Version="5.5.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Stashbox" Version="5.5.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Stashbox" Version="5.12.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/MediatR.Contracts/MediatR.Contracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/MediatR/MediatR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MediatR.Contracts" Version="[2.0.1, 3.0.0)" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="All" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/MediatR/Registration/ServiceRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public static void AddRequiredServices(IServiceCollection services, MediatRServi
private static void RegisterBehaviorIfImplementationsExist(IServiceCollection services, Type behaviorType, Type subBehaviorType)
{
var hasAnyRegistrationsOfSubBehaviorType = services
.Where(service => !service.IsKeyedService)
.Select(service => service.ImplementationType)
.OfType<Type>()
.SelectMany(type => type.GetInterfaces())
Expand Down
6 changes: 3 additions & 3 deletions test/MediatR.Benchmarks/MediatR.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<Configuration>Release</Configuration>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.10" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.10" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MediatR\MediatR.csproj" />
Expand Down
15 changes: 8 additions & 7 deletions test/MediatR.Tests/MediatR.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -10,13 +10,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Lamar" Version="8.1.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="Lamar" Version="12.1.0" />
<PackageReference Include="xunit" Version="2.6.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void ShouldResolveInternalHandler()
[Fact]
public void ShouldResolveNotificationHandlers()
{
_provider.GetServices<INotificationHandler<Pinged>>().Count().ShouldBe(3);
_provider.GetServices<INotificationHandler<Pinged>>().Count().ShouldBe(4);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void ShouldResolveRequestHandler()
[Fact]
public void ShouldResolveNotificationHandlers()
{
_provider.GetServices<INotificationHandler<Pinged>>().Count().ShouldBe(3);
_provider.GetServices<INotificationHandler<Pinged>>().Count().ShouldBe(4);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public DuplicateAssemblyResolutionTests()
[Fact]
public void ShouldResolveNotificationHandlersOnlyOnce()
{
_provider.GetServices<INotificationHandler<Pinged>>().Count().ShouldBe(3);
_provider.GetServices<INotificationHandler<Pinged>>().Count().ShouldBe(4);
}
}
6 changes: 6 additions & 0 deletions test/MediatR.Tests/MicrosoftExtensionsDI/Handlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ public Task Handle(Pinged notification, CancellationToken cancellationToken)
}
}

public class PingedAlsoOpenHandler<TNotification> : INotificationHandler<TNotification>
where TNotification : Pinged
{
public Task Handle(TNotification notification, CancellationToken cancellationToken) => Task.CompletedTask;
}

public class Logger
{
public IList<string> Messages { get; } = new List<string>();
Expand Down
96 changes: 96 additions & 0 deletions test/MediatR.Tests/MicrosoftExtensionsDI/PipelineTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Runtime.CompilerServices;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
using Xunit.Abstractions;

namespace MediatR.Extensions.Microsoft.DependencyInjection.Tests;

Expand Down Expand Up @@ -843,4 +845,98 @@ public void Should_handle_open_behaviors_registration_from_a_single_type()
services.BuildServiceProvider();
});
}

public sealed record FooRequest : IRequest;

public interface IBlogger<T>
{
IList<string> Messages { get; }
}

public class Blogger<T> : IBlogger<T>
{
private readonly Logger _logger;

public Blogger(Logger logger)
{
_logger = logger;
}

public IList<string> Messages => _logger.Messages;
}

public sealed class FooRequestHandler : IRequestHandler<FooRequest> {
public FooRequestHandler(IBlogger<FooRequestHandler> logger)
{
this.logger = logger;
}

readonly IBlogger<FooRequestHandler> logger;

public Task Handle(FooRequest request, CancellationToken cancellationToken) {
logger.Messages.Add("Invoked Handler");
return Task.CompletedTask;
}
}

sealed class ClosedBehavior : IPipelineBehavior<FooRequest, Unit> {
public ClosedBehavior(IBlogger<ClosedBehavior> logger)
{
this.logger = logger;
}

readonly IBlogger<ClosedBehavior> logger;

public Task<Unit> Handle(FooRequest request, RequestHandlerDelegate<Unit> next, CancellationToken cancellationToken) {
logger.Messages.Add("Invoked Closed Behavior");
return next();
}
}

sealed class Open2Behavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : notnull {
public Open2Behavior(IBlogger<Open2Behavior<TRequest, TResponse>> logger) {
this.logger = logger;
}

readonly IBlogger<Open2Behavior<TRequest, TResponse>> logger;

public Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken) {
logger.Messages.Add("Invoked Open Behavior");
return next();
}
}
[Fact]
public async Task Should_register_correctly()
{
var services = new ServiceCollection();
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssemblyContaining<FooRequest>();
cfg.AddBehavior<ClosedBehavior>();
cfg.AddOpenBehavior(typeof(Open2Behavior<,>));
});
var logger = new Logger();
services.AddSingleton(logger);
services.AddSingleton(new MediatR.Tests.PipelineTests.Logger());
services.AddSingleton(new MediatR.Tests.StreamPipelineTests.Logger());
services.AddSingleton(new MediatR.Tests.SendTests.Dependency());
services.AddSingleton<System.IO.TextWriter>(new System.IO.StringWriter());
services.AddTransient(typeof(IBlogger<>), typeof(Blogger<>));
var provider = services.BuildServiceProvider(new ServiceProviderOptions
{
ValidateOnBuild = true
});

var mediator = provider.GetRequiredService<IMediator>();
var request = new FooRequest();
await mediator.Send(request);

logger.Messages.ShouldBe(new []
{
"Invoked Closed Behavior",
"Invoked Open Behavior",
"Invoked Handler",
});
}
}
Loading

0 comments on commit 89262b8

Please sign in to comment.