public void SetUp()
        {
            _commandHandlerFactory = Substitute.For <ICommandHandlerFactory>();
            var testCommandHandler1 = Substitute.For <ICommandHandler <TestCommand> >();

            testCommandHandler1.CanHandle(Arg.Any <TestCommand>()).Returns(true);
            var testCommandHandler2 = Substitute.For <ICommandHandler <TestCommand> >();

            testCommandHandler2.CanHandle(Arg.Any <TestCommand>()).Returns(true);
            _test2CommandHandler = Substitute.For <ICommandHandler <Test2Command> >();
            _test2CommandHandler.CanHandle(Arg.Any <Test2Command>()).Returns(true);
            _test2Command = new Test2Command
            {
                Id = Guid.NewGuid()
            };
            _events = new[] { new Test2Event() };
            _test2CommandHandler.Handle(_test2Command).Returns(_events);
            var commandHandlerProvider = new CommandHandlerProvider(_commandHandlerFactory);

            commandHandlerProvider.RegisterCommandHandler(testCommandHandler1);
            commandHandlerProvider.RegisterCommandHandler(testCommandHandler2);
            commandHandlerProvider.RegisterCommandHandler(_test2CommandHandler);
            _eventHandler  = Substitute.For <IEventHandler>();
            _commandRouter = new CommandRouter(_eventHandler, commandHandlerProvider);
        }
Example #2
0
        public void SetUp()
        {
            var commandHandlerFactory = Substitute.For <ICommandHandlerFactory>();

            _commandHandlerProvider = new CommandHandlerProvider(commandHandlerFactory);
            _openTabCommandHandler  = new OpenTabCommandHandler();
            _commandHandlerProvider.RegisterCommandHandler(_openTabCommandHandler);
            CommandHandler = new TCommandHandler
            {
                Id = AggregateId
            };
            CommandHandler2 = new TCommandHandler
            {
                Id = _aggregateId2
            };

            if (!CanUsePreregisteredCommandHandlersToHandleCommand())
            {
                ConfigureCommandHandlerFactory(commandHandlerFactory);
            }

            _eventHandler  = Substitute.For <IEventHandler>();
            _commandRouter = new CommandRouter(_eventHandler, _commandHandlerProvider);
            _eventApplier  = new EventApplier(new TypeInspector());
        }
        public void Initialize(ConsumerSettings consumerSettings, string topic, int queueCount, bool continueWhenHandleFail, int retryIntervalSeconds, IInterceptor[] interceptors, params Assembly[] assemblies)
        {
            _consumer = new Consumer(consumerSettings);
            _consumer.Subscribe(topic, queueCount);

            _commandHandlerProvider = new CommandHandlerProvider();
            _commandHandlerProvider.Initialize(interceptors, assemblies);
            _commandProcessor = new DefaultMessageProcessor(string.Empty, _commandHandlerProvider, _mailboxProvider, continueWhenHandleFail, retryIntervalSeconds);
        }
        public static IMessageConsumer CreateCommandConsumer(string commandQueue, string consumerId, params string[] handlerProvierNames)
        {
            var container          = IoCFactory.Instance.CurrentContainer;
            var messagePublisher   = container.Resolve <IMessagePublisher>();
            var handlerProvider    = new CommandHandlerProvider(handlerProvierNames);
            var messageQueueClient = IoCFactory.Resolve <IMessageQueueClient>();
            var commandConsumer    = new CommandConsumer(messageQueueClient, messagePublisher, handlerProvider, commandQueue, consumerId);

            return(commandConsumer);
        }
Example #5
0
        public static IMessageProcessor CreateCommandConsumer(string commandQueue,
                                                              string consumerId,
                                                              string[] handlerProvierNames,
                                                              ConsumerConfig consumerConfig = null)
        {
            var container          = ObjectProviderFactory.Instance.ObjectProvider;
            var messagePublisher   = container.GetService <IMessagePublisher>();
            var handlerProvider    = new CommandHandlerProvider(handlerProvierNames);
            var messageQueueClient = ObjectProviderFactory.GetService <IMessageQueueClient>();
            var commandConsumer    = new CommandProcessor(messageQueueClient,
                                                          messagePublisher,
                                                          handlerProvider,
                                                          commandQueue,
                                                          consumerId,
                                                          consumerConfig);

            return(commandConsumer);
        }
 public void SetUp()
 {
     _commandHandlerFactory  = Substitute.For <ICommandHandlerFactory>();
     _commandHandlerProvider = new CommandHandlerProvider(_commandHandlerFactory);
 }
Example #7
0
 public void Setup()
 {
     _commandHandlerFinder = MockRepository.GenerateMock <ICommandHandlerFinder>();
     _cache    = MockRepository.GenerateMock <IObjectLookupCache>();
     _provider = new CommandHandlerProvider(_commandHandlerFinder, _cache);
 }
Example #8
0
 public CommandHandlerProviderTests()
 {
     _commandHandlerFinderMock = new Mock <ICommandHandlerFinder>();
     _serviceProvider          = new Mock <IServiceProvider>();
     _provider = new CommandHandlerProvider(_commandHandlerFinderMock.Object, _serviceProvider.Object);
 }
Example #9
0
 public void Install(IWindsorContainer container, IConfigurationStore store)
 {
     container.Register(
         Classes
         .FromAssembly(Assembly.GetExecutingAssembly())
         .InSameNamespaceAs <WaiterCommandServiceWindsorInstaller>()
         .WithServiceSelf()
         .WithServiceAllInterfaces(),
         Classes
         .FromAssembly(Assembly.GetExecutingAssembly())
         .InSameNamespaceAs <OpenTabConsumer>()
         .WithServiceSelf()
         .WithServiceAllInterfaces(),
         Classes
         .FromAssemblyContaining <IMessageBusFactory>()
         .InSameNamespaceAs <IMessageBusFactory>()
         .Unless(IsMessagingTypeNotRequiredInCommandService)
         .WithServiceSelf()
         .WithServiceAllInterfaces(),
         Classes
         .FromAssemblyContaining <RabbitMqMessageBusFactory>()
         .InSameNamespaceAs <RabbitMqMessageBusFactory>()
         .Unless(IsMessagingRabbitMqTypeNotRequiredInCommandService)
         .WithServiceSelf()
         .WithServiceAllInterfaces(),
         Component
         .For <Assembly>()
         .Instance(typeof(TabOpened).Assembly)
         .Named("assemblyForEventMapper"),
         Component
         .For <EventSerializer>()
         .DependsOn(Dependency.OnComponent("assemblyContainingEvents", "assemblyForEventMapper")),
         Classes
         .FromAssemblyContaining <EventToPublishSerializer>()
         .InSameNamespaceAs <EventToPublishSerializer>()
         .Unless(type => type == typeof(CompositeEventStore) || type == typeof(EventHandler))
         .WithServiceSelf()
         .WithServiceAllInterfaces(),
         Classes
         .FromAssemblyContaining <EventRepository>()
         .InSameNamespaceAs <EventRepository>()
         .Unless(type => type == typeof(EventStoreUnitOfWork))
         .WithServiceSelf()
         .WithServiceAllInterfaces(),
         Component
         .For <IUnitOfWork>()
         .UsingFactoryMethod(kernel => new EventStoreUnitOfWork(ConnectionStringProvider.ConnectionString))
         .LifestyleSingleton(),
         Component
         .For <ICommandRouter>()
         .ImplementedBy <CommandRouter>(),
         Component
         .For <ICommandHandlerProvider>()
         .UsingFactoryMethod(kernel =>
     {
         var commandHandlerProvider = new CommandHandlerProvider(kernel.Resolve <ICommandHandlerFactory>());
         commandHandlerProvider.RegisterCommandHandler(new OpenTabCommandHandler());
         return(commandHandlerProvider);
     }),
         Component
         .For <TypeInspector>()
         .ImplementedBy <TypeInspector>(),
         Component
         .For <IEventApplier>()
         .ImplementedBy <EventApplier>(),
         Component
         .For <IEnumerable <IEventStore> >()
         .UsingFactoryMethod(GetEventStores)
         .Named("eventStores"),
         Component
         .For <CompositeEventStore>()
         .DependsOn(Dependency.OnComponent("eventStores", "eventStores"))
         .Named("compositeEventStore"),
         Component
         .For <EventHandler>()
         .DependsOn(Dependency.OnComponent("eventStore", "compositeEventStore")),
         Component
         .For <OutboxToMessageBusEventHandler>(),
         Classes
         .FromAssemblyContaining <OutboxToMessageBusPublisher>()
         .InSameNamespaceAs <OutboxToMessageBusPublisher>()
         .WithServiceSelf()
         .WithServiceAllInterfaces(),
         Component
         .For <IBusControl>()
         .UsingFactoryMethod(GetBus)
         .LifestyleSingleton(),
         Component
         .For <IEnumerable <IEventHandler> >()
         .UsingFactoryMethod(GetEventHandlers)
         .Named("eventHandlers"),
         Component
         .For <IEventHandler>()
         .ImplementedBy <CompositeEventHandler>()
         .DependsOn(Dependency.OnComponent("eventHandlers", "eventHandlers")),
         Component
         .For <IConfigurationRoot>()
         .Instance(ConfigurationRoot.Instance)
         );
 }
Example #10
0
 public RunEnvironment(CommandHandlerProvider commandHandlerProvider, ITransaction transaction)
 {
     _commandHandlerProvider = commandHandlerProvider;
     _transaction            = transaction;
 }
 public void Setup()
 {
     _commandHandlerFinder = MockRepository.GenerateMock<ICommandHandlerFinder>();
     _cache = MockRepository.GenerateMock<IObjectLookupCache>();
     _provider = new CommandHandlerProvider( _commandHandlerFinder, _cache );
 }