示例#1
0
        public async Task Middleware_can_be_used_to_emit_events_after_the_command_has_been_handled()
        {
            using var kernel = new CompositeKernel
                  {
                      new CSharpKernel()
                  };

            using var kernelEvents = kernel.KernelEvents.ToSubscribedList();

            kernel.AddMiddleware(async(command, context, next) =>
            {
                context.Publish(new DisplayedValueProduced(1, command));

                await next(command, context);

                context.Publish(new DisplayedValueProduced(3, command));
            });

            var result = await kernel.SendAsync(new SubmitCode("2"));

            var events = new List <KernelEvent>();

            result.KernelEvents.Subscribe(e => events.Add(e));

            var values = events.OfType <DisplayEvent>()
                         .Where(x => x is ReturnValueProduced || x is DisplayedValueProduced)
                         .Select(v => v.Value);

            values
            .Should()
            .BeEquivalentSequenceTo(1, 2, 3);
        }
示例#2
0
        public async Task When_a_command_spawns_another_command_then_parent_context_is_not_complete_until_child_context_is_complete()
        {
            using var kernel = new CompositeKernel
                  {
                      new CSharpKernel()
                  };

            using var kernelEvents = kernel.KernelEvents.ToSubscribedList();

            kernel.AddMiddleware(async(command, context, next) =>
            {
                context.Publish(new DisplayedValueProduced(1, command));

                await next(command, context);

                context.Publish(new DisplayedValueProduced(3, command));
            });

            var result = await kernel.SendAsync(new SubmitCode("2"));

            var events = new List <IKernelEvent>();

            result.KernelEvents.Subscribe(e => events.Add(e));

            var values = events.OfType <DisplayEventBase>()
                         .Select(v => v.Value);

            values
            .Should()
            .BeEquivalentSequenceTo(1, 2, 3);
        }
示例#3
0
        public async Task can_provide_access_to_fronted_capabilities()
        {
            var cSharpKernel = new CSharpKernel();

            using var kernel = new CompositeKernel
                  {
                      cSharpKernel
                  };

            kernel.UseFrontedEnvironment(_ => new TestFrontendEnvironment());

            using var kernelEvents = kernel.KernelEvents.ToSubscribedList();

            FrontendEnvironmentBase frontendEnvironment = null;

            kernel.AddMiddleware(async(command, context, next) =>
            {
                frontendEnvironment = context.FrontendEnvironment;
                await next(command, context);
            });

            await kernel.SendAsync(new SubmitCode("2"));

            frontendEnvironment
            .Should()
            .BeOfType <TestFrontendEnvironment>();
        }