public void CommandsHandlerWithResultWiringTest() { using (var container = new WindsorContainer()) { container .Register(Component.For <IMessagingEngine>().Instance(MockRepository.GenerateMock <IMessagingEngine>())) .AddFacility <CqrsFacility>(f => f.RunInMemory().BoundedContexts(LocalBoundedContext.Named("bc"))) .Register(Component.For <CommandsHandler>().AsCommandsHandler("bc")) .Resolve <ICqrsEngineBootstrapper>().Start(); var cqrsEngine = (CqrsEngine)container.Resolve <ICqrsEngine>(); var commandsHandler = container.Resolve <CommandsHandler>(); bool acknowledged = false; long retrydelay = 0; cqrsEngine.BoundedContexts.First(c => c.Name == "bc").CommandDispatcher.Dispatch(1, CommandPriority.Low, (delay, acknowledge) => { retrydelay = delay; acknowledged = acknowledge; }, new Endpoint(), "route"); Thread.Sleep(200); Assert.That(commandsHandler.HandledCommands, Is.EqualTo(new[] { 1 }), "Command was not dispatched"); Assert.That(retrydelay, Is.EqualTo(100)); Assert.That(acknowledged, Is.EqualTo(false)); } }
public void EventStoreTest() { var log = MockRepository.GenerateMock <ILog>(); var eventStoreConnection = EventStoreConnection.Create(ConnectionSettings.Default, new IPEndPoint(IPAddress.Loopback, 1113)); eventStoreConnection.Connect(); using (var engine = new InMemoryCqrsEngine( LocalBoundedContext.Named("local") .PublishingEvents(typeof(int), typeof(TestAggregateRootNameChangedEvent), typeof(TestAggregateRootCreatedEvent)) .To("events") .RoutedTo("events") .ListeningCommands(typeof(string)).On("commands1").RoutedFromSameEndpoint() .WithCommandsHandler <CommandHandler>() .WithProcess <TestProcess>() .WithEventStore(dispatchCommits => Wireup.Init() .LogTo(type => log) .UsingInMemoryPersistence() .InitializeStorageEngine() .UsingJsonSerialization() .UsingSynchronousDispatchScheduler() .DispatchTo(dispatchCommits)) )) { engine.SendCommand("test", "local"); Thread.Sleep(500); Console.WriteLine("Disposing..."); } Console.WriteLine("Dispose completed."); }
public void CommandsHandlerWithResultAndCommandOriginEndpointWiringTest() { using (var container = new WindsorContainer()) { container .Register(Component.For <IMessagingEngine>().Instance(MockRepository.GenerateMock <IMessagingEngine>())) .AddFacility <CqrsFacility>(f => f.RunInMemory().BoundedContexts(LocalBoundedContext.Named("bc"))) .Register(Component.For <CommandsHandler>().AsCommandsHandler("bc")) .Resolve <ICqrsEngineBootstrapper>().Start(); var cqrsEngine = (CqrsEngine)container.Resolve <ICqrsEngine>(); var commandsHandler = container.Resolve <CommandsHandler>(); bool acknowledged = false; long retrydelay = 0; var endpoint = new Endpoint(); var command = DateTime.Now; cqrsEngine.BoundedContexts.First(c => c.Name == "bc").CommandDispatcher.Dispatch(command, CommandPriority.Low, (delay, acknowledge) => { retrydelay = delay; acknowledged = acknowledge; }, endpoint, "route"); Thread.Sleep(200); Assert.That(commandsHandler.HandledCommands.Count, Is.EqualTo(1), "Command was not dispatched"); Assert.That(commandsHandler.HandledCommands[0], Is.TypeOf <RoutedCommand <DateTime> >(), "Command was not dispatched with wrong type"); Assert.That(((RoutedCommand <DateTime>)(commandsHandler.HandledCommands[0])).Command, Is.EqualTo(command), "Routed command was not dispatched with wrong command"); Assert.That(((RoutedCommand <DateTime>)(commandsHandler.HandledCommands[0])).OriginEndpoint, Is.EqualTo(endpoint), "Routed command was dispatched with wrong origin endpoint"); Assert.That(((RoutedCommand <DateTime>)(commandsHandler.HandledCommands[0])).OriginRoute, Is.EqualTo("route"), "Routed command was dispatched with wrong origin route"); Assert.That(retrydelay, Is.EqualTo(100)); Assert.That(acknowledged, Is.EqualTo(false)); } }
public void AllThreadsAreStoppedAfterCqrsDisposeTest() { var initialThreadCount = Process.GetCurrentProcess().Threads.Count; Console.WriteLine(initialThreadCount); using ( var messagingEngine = new MessagingEngine( new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null, "InMemory") } }))) { using (var engine = new CqrsEngine(messagingEngine, new InMemoryEndpointResolver(), LocalBoundedContext.Named("bc").ConcurrencyLevel(1) .PublishingEvents(typeof(int)) .To("eventExchange") .RoutedTo("eventQueue") .ListeningCommands(typeof(string)) .On("exchange1", CommandPriority.Low) .On("exchange2", CommandPriority.High) .RoutedFrom("commandQueue") .WithCommandsHandler(new CommandHandler(100))) ) { Console.WriteLine(Process.GetCurrentProcess().Threads.Count); } } Assert.That(Process.GetCurrentProcess().Threads.Count, Is.EqualTo(initialThreadCount), "Some threads were not stopped"); }
public void ListenSameCommandOnDifferentEndpointsTest() { using ( var messagingEngine = new MessagingEngine( new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null, "InMemory") } }))) { var commandHandler = new CommandHandler(); using (var engine = new CqrsEngine(messagingEngine, new InMemoryEndpointResolver(), LocalBoundedContext.Named("bc") .PublishingEvents(typeof(int)).To("eventExchange").RoutedTo("eventQueue") .ListeningCommands(typeof(string)).On("exchange1").On("exchange2").RoutedFrom("commandQueue") .WithCommandsHandler(commandHandler)) ) { messagingEngine.Send("test1", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("test2", new Endpoint("InMemory", "bc.exchange2", serializationFormat: "json")); messagingEngine.Send("test3", new Endpoint("InMemory", "bc.exchange3", serializationFormat: "json")); Thread.Sleep(2000); Assert.That(commandHandler.AcceptedCommands, Is.EquivalentTo(new[] { "test1", "test2" })); } } }
public void ReplayEventsTest(Type[] types, int expectedReplayCount) { var log = MockRepository.GenerateMock <ILog>(); var eventsListener = new EventsListener(); var localBoundedContext = LocalBoundedContext.Named("local") .PublishingEvents(typeof(TestAggregateRootNameChangedEvent), typeof(TestAggregateRootCreatedEvent)).To("events").RoutedTo("events") .ListeningCommands(typeof(string)).On("commands").RoutedFromSameEndpoint() .ListeningInfrastructureCommands().On("commands").RoutedFromSameEndpoint() .WithCommandsHandler <EsCommandHandler>() .WithEventStore(dispatchCommits => Wireup.Init() .LogTo(type => log) .UsingInMemoryPersistence() .InitializeStorageEngine() .UsingJsonSerialization() .UsingSynchronousDispatchScheduler() .DispatchTo(dispatchCommits)); using ( var engine = new InMemoryCqrsEngine(localBoundedContext, LocalBoundedContext.Named("projections").WithProjection(eventsListener, "local"))) { var guid = Guid.NewGuid(); engine.SendCommand(guid + ":create", "local"); engine.SendCommand(guid + ":changeName:newName", "local"); Thread.Sleep(2000); //engine.SendCommand(new ReplayEventsCommand { Destination = "events", From = DateTime.MinValue }, "local"); engine.ReplayEvents("local", types); Thread.Sleep(2000); Console.WriteLine("Disposing..."); } Assert.That(eventsListener.Handled.Count, Is.EqualTo(2 + expectedReplayCount), "Wrong number of events was replayed"); }
public void RemoteBoundedContextShouldHaveValidLocalOneAssignedType() { new InMemoryCqrsEngine( LocalBoundedContext.Named("bc"), RemoteBoundedContext.Named("remoteBc", "local1"), RemoteBoundedContext.Named("remote2", "remoteBc") ); }
public void RemoteBCsWithSameNameAndListeningInfrastructureCommandsTest() { new InMemoryCqrsEngine( LocalBoundedContext.Named("bc1").ListeningInfrastructureCommands().On("commands").RoutedFromSameEndpoint(), LocalBoundedContext.Named("bc2").ListeningInfrastructureCommands().On("commands").RoutedFromSameEndpoint(), RemoteBoundedContext.Named("remoteBc", "bc1").ListeningInfrastructureCommands().On("commands"), RemoteBoundedContext.Named("remoteBc", "bc2").ListeningInfrastructureCommands().On("commands") ); }
public void RemoteBCsWithSameNameTest() { new InMemoryCqrsEngine( LocalBoundedContext.Named("bc1"), LocalBoundedContext.Named("bc2"), RemoteBoundedContext.Named("remoteBc", "bc1"), RemoteBoundedContext.Named("remoteBc", "bc2") ); }
public void BoundedContextCanNotHaveEventAndCommandOfSameType() { new InMemoryCqrsEngine(LocalBoundedContext.Named("bc") .PublishingEvents(typeof(string)) .To("eventExchange") .RoutedTo("eventQueue") .ListeningCommands(typeof(string)) .On("commandQueue") .RoutedFrom("commandExchange")); }
public void CqrsEngineTest() { var serializationManager = new SerializationManager(); serializationManager.RegisterSerializerFactory(new JsonSerializerFactory()); var transportResolver = new TransportResolver(new Dictionary <string, TransportInfo> { { "test", new TransportInfo("localhost", "guest", "guest", null, "RabbitMq") } }); var messagingEngine = new MessagingEngine(transportResolver, new RabbitMqTransportFactory()); using (messagingEngine) { var cqrsEngine = new CqrsEngine(messagingEngine, new FakeEndpointResolver(), LocalBoundedContext.Named("integration") .PublishingEvents(typeof(int)).To("eventExchange").RoutedTo("eventQueue") .ListeningCommands(typeof(string)).On("commandExchange").RoutedFrom("commandQueue") .WithCommandsHandler <CommandsHandler>(), LocalBoundedContext.Named("bc").WithProjection <EventListener>("integration") ); /* var cqrsEngine = new CqrsEngine(messagingEngine, new RabbitMqConventionEndpointResolver("test","json",new EndpointResolver(new Dictionary<string, Endpoint>())), * LocalBoundedContext.Named("integration") * .PublishingEvents(typeof (int)).To("events").RoutedToSameEndpoint() * .ListeningCommands(typeof (string)).On("commands").RoutedFromSameEndpoint() * .WithCommandsHandler<CommandsHandler>(), * LocalBoundedContext.Named("bc").WithProjection<EventListener>("integration") * );*/ /* var c=new commandSender(messagingEngine, RemoteBoundedContext.Named("integration") * .ListeningCommands(typeof(TestCommand)).On(new Endpoint()) * .PublishingEvents(typeof(TransferCreatedEvent)).To(new Endpoint()), * LocalBoundedContext.Named("testBC") * .ListeningCommands(typeof(TestCommand)).On(new Endpoint("test", "unistream.u1.commands", true)) * .ListeningCommands(typeof(int)).On(new Endpoint("test", "unistream.u1.commands", true)) * .PublishingEvents(typeof (int)).To(new Endpoint()).RoutedTo(new Endpoint()) * .PublishingEvents(typeof (string)).To(new Endpoint()) * .WithEventStore(dispatchCommits => Wireup.Init() * .LogToOutputWindow() * .UsingInMemoryPersistence() * .InitializeStorageEngine() * .UsingJsonSerialization() * .UsingSynchronousDispatchScheduler() * .DispatchTo(dispatchCommits)) * ); */ // messagingEngine.Send("test", new Endpoint("test", "unistream.u1.commands", true,"json")); cqrsEngine.SendCommand("test", "integration"); Thread.Sleep(3000); } }
public void ReplayEventsRmqTest() { var endpointResolver = MockRepository.GenerateMock <IEndpointResolver>(); endpointResolver.Expect(r => r.Resolve("local", "local", "commands", typeof(string), RouteType.Commands)).Return(new Endpoint("rmq", "commandsExchange", "commands", true, "json")); endpointResolver.Expect(r => r.Resolve("local", "local", "events", typeof(TestAggregateRootNameChangedEvent), RouteType.Events)).Return(new Endpoint("rmq", "eventsExchange", "events", true, "json")); endpointResolver.Expect(r => r.Resolve("local", "local", "events", typeof(TestAggregateRootCreatedEvent), RouteType.Events)).Return(new Endpoint("rmq", "eventsExchange", "events", true, "json")); var transports = new Dictionary <string, TransportInfo> { { "rmq", new TransportInfo("localhost", "guest", "guest", null, "RabbitMq") } }; var messagingEngine = new MessagingEngine(new TransportResolver(transports), new RabbitMqTransportFactory()); var eventsListener = new EventsListener(); var localBoundedContext = LocalBoundedContext.Named("local") .PublishingEvents(typeof(TestAggregateRootNameChangedEvent), typeof(TestAggregateRootCreatedEvent)).To("events").RoutedTo("events") .ListeningCommands(typeof(string)).On("commands").RoutedFromSameEndpoint() .ListeningInfrastructureCommands().On("commands").RoutedFromSameEndpoint() .WithCommandsHandler <EsCommandHandler>() .WithEventStore(dispatchCommits => Wireup.Init() .LogToOutputWindow() .UsingInMemoryPersistence() .InitializeStorageEngine() .UsingJsonSerialization() .UsingSynchronousDispatchScheduler() .DispatchTo(dispatchCommits)); using (messagingEngine) { using ( var engine = new CqrsEngine(messagingEngine, endpointResolver, localBoundedContext, LocalBoundedContext.Named("projections").WithProjection(eventsListener, "local"))) { var guid = Guid.NewGuid(); engine.SendCommand(guid + ":create", "local"); engine.SendCommand(guid + ":changeName:newName", "local"); Thread.Sleep(2000); //engine.SendCommand(new ReplayEventsCommand { Destination = "events", From = DateTime.MinValue }, "local"); engine.ReplayEvents("local"); Thread.Sleep(2000); Console.WriteLine("Disposing..."); } } Assert.That(eventsListener.Handled.Count, Is.EqualTo(4), "Events were not redelivered"); }
public void ProjectionWiringTest() { using (var container = new WindsorContainer()) { container.Register(Component.For <IMessagingEngine>().Instance(MockRepository.GenerateMock <IMessagingEngine>())) .AddFacility <CqrsFacility>(f => f.RunInMemory().BoundedContexts(LocalBoundedContext.Named("local"), RemoteBoundedContext.Named("remote", "local"))) .Register(Component.For <EventListener>().AsProjection("local", "remote")) .Resolve <ICqrsEngineBootstrapper>().Start(); var cqrsEngine = (CqrsEngine)container.Resolve <ICqrsEngine>(); var eventListener = container.Resolve <EventListener>(); cqrsEngine.BoundedContexts.First(c => c.Name == "remote").EventDispatcher.Dispacth("test", (delay, acknowledge) => {}); Assert.That(eventListener.EventsWithBoundedContext, Is.EquivalentTo(new[] { Tuple.Create("test", "remote") }), "Event was not dispatched"); Assert.That(eventListener.Events, Is.EquivalentTo(new[] { "test" }), "Event was not dispatched"); } }
public void NEventSToreInvestigationTest() { var log = MockRepository.GenerateMock <ILog>(); using (var engine = new InMemoryCqrsEngine( LocalBoundedContext.Named("local") .PublishingEvents(typeof(int)).To("events").RoutedTo("events") .ListeningCommands(typeof(string)).On("commands1").RoutedFromSameEndpoint() .ListeningCommands(typeof(DateTime)).On("commands2").RoutedFromSameEndpoint() .WithCommandsHandler <CommandHandler>() .WithProcess <TestProcess>() .WithEventStore(dispatchCommits => Wireup.Init() .LogTo(type => log) .UsingInMemoryPersistence() .InitializeStorageEngine() .UsingJsonSerialization() .UsingSynchronousDispatchScheduler() .DispatchTo(dispatchCommits)) , LocalBoundedContext.Named("projections") .WithProjection <EventsListener>("local"), RemoteBoundedContext.Named("remote", "projections") .ListeningCommands(typeof(object)).On("remoteCommands") .PublishingEvents(typeof(int)).To("remoteEvents"), Saga <TestSaga> .Listening("local", "projections"), Saga.Instance(new TestSaga()).Listening("local", "projections") )) { /* * .WithEventSource() * .WithAggregates() * .WithDocumentStore()); * */ engine.SendCommand("test", "local"); engine.SendCommand(DateTime.Now, "local"); Thread.Sleep(500); Console.WriteLine("Disposing..."); } Console.WriteLine("Dispose completed."); }
public void SyntaxTest() { using (var container = new WindsorContainer()) { container.Register(Component.For <IMessagingEngine>().Instance(MockRepository.GenerateMock <IMessagingEngine>())); container.AddFacility <CqrsFacility>(f => f.RunInMemory().BoundedContexts( LocalBoundedContext.Named("local") .PublishingEvents(typeof(int)).To("events").RoutedTo("events") .ListeningCommands(typeof(string)).On("commands1").RoutedFromSameEndpoint() .ListeningCommands(typeof(DateTime)).On("commands2").RoutedFromSameEndpoint() .WithCommandsHandler <CommandHandler>(), LocalBoundedContext.Named("projections"))); container.Register( Component.For <TestSaga>().AsSaga("local", "projections"), Component.For <CommandHandler>().AsCommandsHandler("local"), Component.For <EventsListener>().AsProjection("projections", "local") ); } }
public void GetEventStoreTest(bool getES) { var log = MockRepository.GenerateMock <ILog>(); var eventsListener = new EventsListener(); var localBoundedContext = LocalBoundedContext.Named("local") .PublishingEvents(typeof(TestAggregateRootNameChangedEvent), typeof(TestAggregateRootCreatedEvent)).To("events").RoutedTo("events") .ListeningCommands(typeof(string)).On("commands1").RoutedFromSameEndpoint() .WithCommandsHandler <EsCommandHandler>(); if (getES) { var eventStoreConnection = EventStoreConnection.Create(ConnectionSettings.Default, new IPEndPoint(IPAddress.Loopback, 1113)); eventStoreConnection.Connect(); localBoundedContext.WithEventStore(eventStoreConnection); } else { localBoundedContext.WithEventStore(dispatchCommits => Wireup.Init() .LogTo(type => log) .UsingInMemoryPersistence() .InitializeStorageEngine() .UsingJsonSerialization() .UsingSynchronousDispatchScheduler() .DispatchTo(dispatchCommits)); } using (var engine = new InMemoryCqrsEngine(localBoundedContext, LocalBoundedContext.Named("projections").WithProjection(eventsListener, "local"))) { var guid = Guid.NewGuid(); engine.SendCommand(guid + ":create", "local"); engine.SendCommand(guid + ":changeName:newName", "local"); Thread.Sleep(5000); Console.WriteLine("Disposing..."); } Assert.That(eventsListener.Handled.Select(e => e.GetType()).ToArray(), Is.EqualTo(new[] { typeof(TestAggregateRootCreatedEvent), typeof(TestAggregateRootNameChangedEvent) }), "Events were not stored or published"); Console.WriteLine("Dispose completed."); }
public void DependencyOnICommandSenderTest() { using (var container = new WindsorContainer()) { var messagingEngine = MockRepository.GenerateMock <IMessagingEngine>(); container .Register(Component.For <IMessagingEngine>().Instance(messagingEngine)) .AddFacility <CqrsFacility>(f => f.RunInMemory().BoundedContexts( LocalBoundedContext.Named("bc").ListeningCommands(typeof(string)).On("cmd").RoutedFromSameEndpoint()) ) .Register(Component.For <EventListenerWithICommandSenderDependency>().AsSaga("bc")) .Register(Component.For <CommandsHandler>().AsCommandsHandler("bc")) .Resolve <ICqrsEngineBootstrapper>().Start(); var listener = container.Resolve <EventListenerWithICommandSenderDependency>(); var commandsHandler = container.Resolve <CommandsHandler>(); Assert.That(listener.Sender, Is.Not.Null); listener.Sender.SendCommand("test", "bc"); Thread.Sleep(200); Assert.That(commandsHandler.HandledCommands, Is.EqualTo(new[] { "test" }), "Command was not dispatched"); } }
public void WithRepositoryAccessTest() { var log = MockRepository.GenerateMock <ILog>(); using (var container = new WindsorContainer()) { container .Register(Component.For <IMessagingEngine>().Instance(MockRepository.GenerateMock <IMessagingEngine>())) .AddFacility <CqrsFacility>(f => f.RunInMemory().BoundedContexts(LocalBoundedContext.Named("bc") .WithEventStore(dispatchCommits => Wireup.Init() .LogTo(type => log) .UsingInMemoryPersistence() .InitializeStorageEngine() .UsingJsonSerialization() .UsingSynchronousDispatchScheduler() .DispatchTo(dispatchCommits)))) .Register(Component.For <RepositoryDependentComponent>().WithRepositoryAccess("bc")) .Resolve <ICqrsEngineBootstrapper>().Start(); var cqrsEngine = (CqrsEngine)container.Resolve <ICqrsEngine>(); var repositoryDependentComponent = container.Resolve <RepositoryDependentComponent>(); Assert.That(repositoryDependentComponent.Repository, Is.Not.Null, "Repository was not injected"); } }
public void PrioritizedCommandsProcessingTest() { using ( var messagingEngine = new MessagingEngine( new TransportResolver(new Dictionary <string, TransportInfo> { { "InMemory", new TransportInfo("none", "none", "none", null, "InMemory") } }))) { var commandHandler = new CommandHandler(100); using (var engine = new CqrsEngine(messagingEngine, new InMemoryEndpointResolver(), LocalBoundedContext.Named("bc").ConcurrencyLevel(1) .PublishingEvents(typeof(int)).To("eventExchange").RoutedTo("eventQueue") .ListeningCommands(typeof(string)).On("exchange1", CommandPriority.Low).On("exchange2", CommandPriority.High).RoutedFrom("commandQueue") .WithCommandsHandler(commandHandler)) ) { messagingEngine.Send("low1", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("low2", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("low3", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("low4", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("low5", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("low6", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("low7", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("low8", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("low9", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("low10", new Endpoint("InMemory", "bc.exchange1", serializationFormat: "json")); messagingEngine.Send("high", new Endpoint("InMemory", "bc.exchange2", serializationFormat: "json")); Thread.Sleep(2000); Console.WriteLine(string.Join("\n", commandHandler.AcceptedCommands)); Assert.That(commandHandler.AcceptedCommands.Take(2).Any(c => (string)c == "high"), Is.True); } } }
public void Test() { var endpointProvider = MockRepository.GenerateMock <IEndpointProvider>(); endpointProvider.Expect(p => p.Contains(null)).IgnoreArguments().Return(false); var messagingEngine = MockRepository.GenerateStrictMock <IMessagingEngine>(); string error; messagingEngine.Expect(e => e.VerifyEndpoint(new Endpoint(), EndpointUsage.None, false, out error)).IgnoreArguments().Return(true).Repeat.Times(12); //subscription for remote events messagingEngine.Expect(e => e.Subscribe( Arg <Endpoint> .Is.Anything, Arg <CallbackDelegate <object> > .Is.Anything, Arg <Action <string, AcknowledgeDelegate> > .Is.Anything, Arg <string> .Is.Equal("remoteEvents"), Arg <int> .Is.Equal(0), Arg <Type[]> .List.Equal(new [] { typeof(int), typeof(long) }))).Return(Disposable.Empty); //subscription for local events messagingEngine.Expect(e => e.Subscribe( Arg <Endpoint> .Is.Anything, Arg <CallbackDelegate <object> > .Is.Anything, Arg <Action <string, AcknowledgeDelegate> > .Is.Anything, Arg <string> .Is.Equal("localEvents"), Arg <int> .Is.Equal(0), Arg <Type[]> .List.Equal(new [] { typeof(bool) }))).Return(Disposable.Empty); //subscription for localCommands messagingEngine.Expect(e => e.Subscribe( Arg <Endpoint> .Is.Anything, Arg <CallbackDelegate <object> > .Is.Anything, Arg <Action <string, AcknowledgeDelegate> > .Is.Anything, Arg <string> .Is.Equal("localCommands"), Arg <int> .Is.Equal(0), Arg <Type[]> .List.Equal(new[] { typeof(string), typeof(DateTime) }))).Return(Disposable.Empty); //send command to remote BC messagingEngine.Expect(e => e.Send( Arg <object> .Is.Equal("testCommand"), Arg <Endpoint> .Is.Anything, Arg <string> .Is.Equal("remoteCommands") )); //publish event from local BC messagingEngine.Expect(e => e.Send( Arg <object> .Is.Equal(true), Arg <Endpoint> .Is.Anything, Arg <string> .Is.Equal("localEvents") )); using (var ce = new CqrsEngine(messagingEngine, new RabbitMqConventionEndpointResolver("tr1", "protobuf", endpointProvider), LocalBoundedContext.Named("operations") .PublishingEvents(typeof(bool)).To("localEvents").RoutedToSameEndpoint() .ListeningCommands(typeof(string), typeof(DateTime)).On("localCommands").RoutedFromSameEndpoint(), RemoteBoundedContext.Named("integration", "operations") .PublishingEvents(typeof(int), typeof(long)).To("remoteEvents") .ListeningCommands(typeof(string)).On("remoteCommands")) ) { ce.SendCommand("testCommand", "integration"); ce.BoundedContexts.Find(bc => bc.Name == "operations").EventsPublisher.PublishEvent(true); } }
public void ComponentCanNotBeProjectionAndCommandsHandlerSimultaneousely() { using (var container = new WindsorContainer()) { container.AddFacility <CqrsFacility>(f => f.RunInMemory().BoundedContexts(LocalBoundedContext.Named("bc"))); container.Register(Component.For <CommandsHandler>().AsCommandsHandler("bc").AsProjection("bc", "remote")); } }