-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Shuttle/async
Async
- Loading branch information
Showing
26 changed files
with
480 additions
and
124 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Shuttle.Core.Mediator.Tests; | ||
|
||
public interface IMessageTracker | ||
{ | ||
void Received(object message); | ||
int MessageTypeCount<T>(); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Shuttle.Core.Contract; | ||
|
||
namespace Shuttle.Core.Mediator.Tests; | ||
|
||
public class MessageTracker : IMessageTracker | ||
{ | ||
private readonly List<object> _messagesReceived = new(); | ||
|
||
public void Received(object message) | ||
{ | ||
_messagesReceived.Add(Guard.AgainstNull(message, nameof(message))); | ||
} | ||
|
||
public int MessageTypeCount<T>() | ||
{ | ||
return _messagesReceived.Count(item => item.GetType() == typeof(T)); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Shuttle.Core.Mediator.Tests; | ||
|
||
public class MultipleParticipantMessageA | ||
{ | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace Shuttle.Core.Mediator.Tests; | ||
|
||
public class MultipleParticipantMessageB | ||
{ | ||
} |
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,36 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Shuttle.Core.Contract; | ||
|
||
namespace Shuttle.Core.Mediator.Tests | ||
namespace Shuttle.Core.Mediator.Tests; | ||
|
||
public class MultipleParticipants : | ||
IParticipant<MultipleParticipantMessageA>, | ||
IParticipant<MultipleParticipantMessageB>, | ||
IAsyncParticipant<MultipleParticipantMessageA>, | ||
IAsyncParticipant<MultipleParticipantMessageB> | ||
{ | ||
public class MultipleParticipants : | ||
IParticipant<MultipleParticipantMessageA>, | ||
IParticipant<MultipleParticipantMessageB> | ||
private readonly IMessageTracker _messageTracker; | ||
|
||
public MultipleParticipants(IMessageTracker messageTracker) | ||
{ | ||
_messageTracker = Guard.AgainstNull(messageTracker, nameof(messageTracker)); | ||
} | ||
|
||
public async Task ProcessMessageAsync(IParticipantContext<MultipleParticipantMessageA> context) | ||
{ | ||
private static readonly List<object> _messagesReceived = new List<object>(); | ||
|
||
public int MessageTypeCount(Type type) | ||
{ | ||
return _messagesReceived.Count(item => item.GetType() == type); | ||
} | ||
|
||
public void ProcessMessage(IParticipantContext<MultipleParticipantMessageA> context) | ||
{ | ||
_messagesReceived.Add(context.Message); | ||
} | ||
|
||
public void ProcessMessage(IParticipantContext<MultipleParticipantMessageB> context) | ||
{ | ||
_messagesReceived.Add(context.Message); | ||
} | ||
_messageTracker.Received(context.Message); | ||
|
||
await Task.CompletedTask.ConfigureAwait(false); | ||
} | ||
|
||
public async Task ProcessMessageAsync(IParticipantContext<MultipleParticipantMessageB> context) | ||
{ | ||
_messageTracker.Received(context.Message); | ||
|
||
await Task.CompletedTask.ConfigureAwait(false); | ||
} | ||
|
||
public class MultipleParticipantMessageB | ||
public void ProcessMessage(IParticipantContext<MultipleParticipantMessageA> context) | ||
{ | ||
_messageTracker.Received(context.Message); | ||
} | ||
|
||
public class MultipleParticipantMessageA | ||
public void ProcessMessage(IParticipantContext<MultipleParticipantMessageB> context) | ||
{ | ||
_messageTracker.Received(context.Message); | ||
} | ||
} |
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
Oops, something went wrong.