public PipelineGlobalInboxTestsAsync()
        {
            _inbox = new InMemoryInbox();
            var handler = new MyCommandHandlerAsync(new Dictionary <string, Guid>());

            var registry = new SubscriberRegistry();

            registry.RegisterAsync <MyCommand, MyCommandHandlerAsync>();

            var container = new ServiceCollection();

            container.AddSingleton <MyCommandHandlerAsync>(handler);
            container.AddSingleton <IAmAnInboxAsync>(_inbox);
            container.AddTransient <UseInboxHandlerAsync <MyCommand> >();
            container.AddSingleton <IBrighterOptions>(new BrighterOptions()
            {
                HandlerLifetime = ServiceLifetime.Transient
            });

            var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider());


            _requestContext = new RequestContext();

            _inboxConfiguration = new InboxConfiguration();

            _chainBuilder = new PipelineBuilder <MyCommand>(registry, (IAmAHandlerFactoryAsync)handlerFactory, _inboxConfiguration);
        }
Example #2
0
        public void When_Sending_A_Command_To_The_Processor_Async()
        {
            AsyncContext.Run(async() => await _commandProcessor.SendAsync(_myCommand));

            // _should_send_the_command_to_the_command_handler
            Assert.True(MyCommandHandlerAsync.ShouldReceive(_myCommand));
        }
        public CommandProcessorBuildDefaultInboxSendAsyncTests()
        {
            var handler = new MyCommandHandlerAsync(new Dictionary <string, Guid>());

            var subscriberRegistry = new SubscriberRegistry();

            //This handler has no Inbox attribute
            subscriberRegistry.RegisterAsync <MyCommand, MyCommandHandlerAsync>();

            var container = new ServiceCollection();

            container.AddSingleton <MyCommandHandlerAsync>(handler);
            container.AddSingleton <IAmAnInboxAsync>(_inbox);
            container.AddTransient <UseInboxHandlerAsync <MyCommand> >();
            container.AddSingleton <IBrighterOptions>(new BrighterOptions()
            {
                HandlerLifetime = ServiceLifetime.Transient
            });

            var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider());

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .RetryAsync();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(1));

            var inboxConfiguration = new InboxConfiguration(
                InboxScope.All,                      //grab all the events
                onceOnly: true,                      //only allow once
                actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should  be the only entry after)
                );

            _commandProcessor = new CommandProcessor(
                subscriberRegistry,
                handlerFactory,
                new InMemoryRequestContextFactory(),
                new PolicyRegistry
            {
                { CommandProcessor.RETRYPOLICYASYNC, retryPolicy },
                { CommandProcessor.CIRCUITBREAKERASYNC, circuitBreakerPolicy }
            },
                inboxConfiguration: inboxConfiguration
                );
        }
        public PipelineGlobalInboxTestsAsync()
        {
            _inbox = new InMemoryInbox();
            var handler = new MyCommandHandlerAsync(new Dictionary <string, Guid>());

            var registry = new SubscriberRegistry();

            registry.RegisterAsync <MyCommand, MyCommandHandlerAsync>();

            var container      = new TinyIoCContainer();
            var handlerFactory = new TinyIocHandlerFactoryAsync(container);

            container.Register <MyCommandHandlerAsync>(handler);
            container.Register <IAmAnInboxAsync>(_inbox);

            _requestContext = new RequestContext();

            _inboxConfiguration = new InboxConfiguration();

            _chainBuilder = new PipelineBuilder <MyCommand>(registry, handlerFactory, _inboxConfiguration);
        }