Exemple #1
0
        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);
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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);
        }