-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
namespace Shiny.Mediator; | ||
|
||
public interface IRequestHandler<in TRequest> where TRequest : IRequest | ||
public interface IRequestHandler<in TRequest> where TRequest : notnull, IRequest | ||
{ | ||
Task Handle(TRequest request, CancellationToken cancellationToken); | ||
} | ||
|
||
|
||
public interface IRequestHandler<in TRequest, TResult> where TRequest : IRequest<TResult> | ||
public interface IRequestHandler<in TRequest, TResult> where TRequest : notnull, IRequest<TResult> | ||
{ | ||
Task<TResult> Handle(TRequest request, CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
// using FluentAssertions; | ||
// using Shiny.Mediator; | ||
// | ||
// namespace Shiny.Mediator.Tests; | ||
// | ||
// public class SourceGeneratorTests | ||
// { | ||
// [Fact] | ||
// public void DidRegister() | ||
// { | ||
// var services = new ServiceCollection(); | ||
// services.AddShinyMediator(); | ||
// // TODO: source gen call | ||
// var sp = services.BuildServiceProvider(); | ||
// | ||
// sp.GetService<IEventHandler<SourceGenEvent>>().Should().NotBeNull("Event Handler not found"); | ||
// sp.GetService<IRequestHandler<SourceGenRequest>>().Should().NotBeNull("Request Handler not found"); | ||
// sp.GetService<IRequestHandler<SourceGenResponseRequest, SourceGenResponse>>().Should().NotBeNull("Request/Response Handler not found"); | ||
// } | ||
// } | ||
// | ||
// public record SourceGenRequest : IRequest; | ||
// public record SourceGenResponseRequest : IRequest<SourceGenResponse>; | ||
// public record SourceGenResponse; | ||
// public record SourceGenEvent : IEvent; | ||
// | ||
// [RegisterHandler] | ||
// public class SourceGenRequestHandler : IRequestHandler<SourceGenRequest> | ||
// { | ||
// public Task Handle(SourceGenRequest request, CancellationToken cancellationToken) => Task.CompletedTask; | ||
// } | ||
// [RegisterHandler] | ||
// public class SourceGenResponseRequestHandler : IRequestHandler<SourceGenResponseRequest, SourceGenResponse> | ||
// { | ||
// public Task<SourceGenResponse> Handle(SourceGenResponseRequest request, CancellationToken cancellationToken) | ||
// => Task.FromResult(new SourceGenResponse()); | ||
// } | ||
// [RegisterHandler] | ||
// public class SourceGenEventHandler : IEventHandler<SourceGenEvent> | ||
// { | ||
// public Task Handle(SourceGenEvent @event, CancellationToken cancellationToken) => Task.CompletedTask; | ||
// } | ||
using FluentAssertions; | ||
using Shiny.Mediator; | ||
|
||
namespace Shiny.Mediator.Tests; | ||
|
||
public class SourceGeneratorTests | ||
{ | ||
[Fact] | ||
public void DidRegister() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddShinyMediator(); | ||
// TODO: source gen call | ||
// services.AddDiscoveredMediatorHandlers(); | ||
var sp = services.BuildServiceProvider(); | ||
|
||
sp.GetService<IEventHandler<SourceGenEvent>>().Should().NotBeNull("Event Handler not found"); | ||
sp.GetService<IRequestHandler<SourceGenRequest>>().Should().NotBeNull("Request Handler not found"); | ||
sp.GetService<IRequestHandler<SourceGenResponseRequest, SourceGenResponse>>().Should().NotBeNull("Request/Response Handler not found"); | ||
} | ||
} | ||
|
||
public record SourceGenRequest : IRequest; | ||
public record SourceGenResponseRequest : IRequest<SourceGenResponse>; | ||
public record SourceGenResponse; | ||
public record SourceGenEvent : IEvent; | ||
|
||
[RegisterHandler] | ||
public class SourceGenRequestHandler : IRequestHandler<SourceGenRequest> | ||
{ | ||
public Task Handle(SourceGenRequest request, CancellationToken cancellationToken) => Task.CompletedTask; | ||
} | ||
[RegisterHandler] | ||
public class SourceGenResponseRequestHandler : IRequestHandler<SourceGenResponseRequest, SourceGenResponse> | ||
{ | ||
public Task<SourceGenResponse> Handle(SourceGenResponseRequest request, CancellationToken cancellationToken) | ||
=> Task.FromResult(new SourceGenResponse()); | ||
} | ||
[RegisterHandler] | ||
public class SourceGenEventHandler : IEventHandler<SourceGenEvent> | ||
{ | ||
public Task Handle(SourceGenEvent @event, CancellationToken cancellationToken) => Task.CompletedTask; | ||
} |