public void Execute_Should_ApplyAction(string firstName, string setInitials, string expectedInitials) { var handler = new ActionHandler <PersonStub>(x => x.Initials = x.FirstName.Substring(0, 1)); var person = PersonFactory.Create(firstName, setInitials); person.Initials.Should().Be(setInitials); handler.Execute(person); person.Initials.Should().Be(expectedInitials); }
public async Task <TOutput> Dispatch <TInput, TOutput>(TInput input, string?userId = null) where TInput : class, IAction { ActionHandler <TInput, TOutput> handler = serviceProvider.GetRequiredService <ActionHandler <TInput, TOutput> >(); var user = userId != null ? await userResolver.Resolve(userId) : null; foreach (ActionMiddleware mw in middlewares) { await mw.Execute(serviceProvider, handler, input, user); } return(await handler.Execute(input, user)); }
public async Task Dispatch <TInput>(string?userId = null) where TInput : class, IAction, new() { ActionHandler <TInput> handler = serviceProvider.GetRequiredService <ActionHandler <TInput> >(); var user = userId != null ? await userResolver.Resolve(userId) : null; var input = new TInput(); foreach (ActionMiddleware mw in middlewares) { await mw.Execute(serviceProvider, handler, input, user); } await handler.Execute(input, user); }