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 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 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 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."); }