// // CommandEvent.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; using System.Threading; using System.Threading.Tasks; using NosSmooth.Core.Client; using NosSmooth.Core.Commands; using Remora.Results; namespace NosSmooth.Core.Tests.Fakes.Commands.Events; /// public class CommandEvent : IPreCommandExecutionEvent, IPostCommandExecutionEvent where TInCommand : ICommand { private readonly Func _preExecutionHandler; private readonly Func _postExecutionHandler; /// /// Initializes a new instance of the class. /// /// The pre execution handler. /// The post execution handler. public CommandEvent(Func preExecutionHandler, Func postExecutionHandler) { _preExecutionHandler = preExecutionHandler; _postExecutionHandler = postExecutionHandler; } /// public Task ExecuteBeforeCommandAsync (INostaleClient client, TCommand command, CancellationToken ct = default) where TCommand : ICommand { return Task.FromResult(_preExecutionHandler((TInCommand)(object)command)); } /// public Task ExecuteAfterCommandAsync ( INostaleClient client, TCommand command, Result handlerResult, CancellationToken ct = default ) where TCommand : ICommand { return Task.FromResult(_postExecutionHandler((TInCommand)(object)command, handlerResult)); } }