Esempio n. 1
0
        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");
        }
Esempio n. 2
0
        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.");
        }
Esempio n. 3
0
        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.");
        }
Esempio n. 4
0
        public void ProcessTest()
        {
            var testProcess    = new TestProcess();
            var commandHandler = new CommandsHandler();

            using (var engine = new InMemoryCqrsEngine(
                       _logFactory,
                       Register.BoundedContext("local")
                       .ListeningCommands(typeof(string)).On("commands1").WithLoopback()
                       .PublishingEvents(typeof(int)).With("events")
                       .WithCommandsHandler(commandHandler)
                       .WithProcess(testProcess)
                       ))
            {
                engine.StartAll();
                Assert.True(testProcess.Started.WaitOne(1000), "process was not started");
                Thread.Sleep(1000);
            }

            Assert.True(testProcess.Disposed.WaitOne(1000), "process was not disposed on engine dispose");
            Assert.True(commandHandler.HandledCommands.Count > 0, "commands sent by process were not processed");
        }
Esempio n. 5
0
        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.");
        }