| | | 1 | | using ArturRios.Mediator; |
| | | 2 | | using ArturRios.Mediator.Command; |
| | | 3 | | using ArturRios.Mediator.Query; |
| | | 4 | | |
| | | 5 | | namespace ArturRios.Util.Test.Mock; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Test helper that simulates a delayed (scheduled) dispatch of a command or query through a |
| | | 9 | | /// <see cref="CommandQueryMediator"/>. Use a small <paramref name="waitTimeInSeconds"/> to keep tests fast. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <param name="mediator">The mediator used to dispatch the command or query.</param> |
| | | 12 | | /// <param name="waitTimeInSeconds">The delay, in seconds, applied before dispatching. Defaults to 60.</param> |
| | 3 | 13 | | public class FakeScheduler(CommandQueryMediator mediator, int waitTimeInSeconds = 60) |
| | | 14 | | { |
| | | 15 | | /// <summary>Waits for the configured delay and then dispatches <paramref name="command"/>.</summary> |
| | | 16 | | /// <typeparam name="TCommand">The command type.</typeparam> |
| | | 17 | | /// <typeparam name="TCommandOutput">The command output type.</typeparam> |
| | | 18 | | /// <param name="command">The command to dispatch.</param> |
| | | 19 | | public async Task CreateCommandSchedule<TCommand, TCommandOutput>(TCommand command) |
| | | 20 | | where TCommand : BaseCommand |
| | | 21 | | where TCommandOutput : CommandOutput |
| | 2 | 22 | | { |
| | 2 | 23 | | await Task.Delay(TimeSpan.FromSeconds(waitTimeInSeconds)); |
| | | 24 | | |
| | 2 | 25 | | await mediator.ExecuteCommandAsync<TCommand, TCommandOutput>(command); |
| | 2 | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary>Waits for the configured delay and then dispatches <paramref name="query"/>.</summary> |
| | | 29 | | /// <typeparam name="TQuery">The query type.</typeparam> |
| | | 30 | | /// <typeparam name="TQueryOutput">The query output type.</typeparam> |
| | | 31 | | /// <param name="query">The query to dispatch.</param> |
| | | 32 | | public async Task CreateQuerySchedule<TQuery, TQueryOutput>(TQuery query) |
| | | 33 | | where TQuery : BaseQuery |
| | | 34 | | where TQueryOutput : QueryOutput |
| | 1 | 35 | | { |
| | 1 | 36 | | await Task.Delay(TimeSpan.FromSeconds(waitTimeInSeconds)); |
| | | 37 | | |
| | 1 | 38 | | await mediator.ExecuteQueryAsync<TQuery, TQueryOutput>(query); |
| | 1 | 39 | | } |
| | | 40 | | } |