private Configuration() { /* bus intialisation */ _bus = new MessageBus(); //var eventStore = new SqlServerEventStore(_bus); //var eventStore = new SqlLiteEventStore(_bus); var eventStore = new InMemoryEventStore(_bus, inMemDict ); var repository = new DomainRepository(eventStore); /* Account Domain */ var commandService = new AccountApplicationService(repository); _bus.RegisterHandler<RegisterAccountCommand>(commandService.Handle); _bus.RegisterHandler<DebitAccountCommand>(commandService.Handle); _bus.RegisterHandler<UnlockAccountCommand>(commandService.Handle); var infoProjection = new AccountInfoProjection(); _bus.RegisterHandler<AccountRegisteredEvent>(infoProjection.Handle); _bus.RegisterHandler<AccountLockedEvent>(infoProjection.Handle); _bus.RegisterHandler<AccountUnlockedEvent>(infoProjection.Handle); var balanceProjection = new AccountBalanceProjection(); _bus.RegisterHandler<AccountRegisteredEvent>(balanceProjection.Handle); _bus.RegisterHandler<AccountDebitedEvent>(balanceProjection.Handle); var notification = new NotificationProjection(); _bus.RegisterHandler<AccountRegisteredEvent>(notification.Handle); _bus.RegisterHandler<AccountDebitedEvent>(notification.Handle); _bus.RegisterHandler<AccountLockedEvent>(notification.Handle); _bus.RegisterHandler<AccountUnlockedEvent>(notification.Handle); _bus.RegisterHandler<AccountOverdrawAttemptedEvent>(notification.Handle); _AccountReadModel = new AccountReadModelFacade(balanceProjection, infoProjection, notification); /* News Domain*/ //var newsEventStore = new SqlServerEventStore(_bus); //var newsEventStore = new SqlLiteEventStore(_bus); var newsEventStore = new InMemoryEventStore(_bus, inMemDict); var newsRepository = new DomainRepository(eventStore); /* Register command on the News bounded context */ var newsCommandService = new AccountManager.Models.News.Domain.NewsApplicationService(newsRepository); _bus.RegisterHandler<AccountManager.Models.News.Commands.CreateNewsCommand>(newsCommandService.Handle); _bus.RegisterHandler<AccountManager.Models.News.Commands.PublishNewsCommand>(newsCommandService.Handle); _bus.RegisterHandler<AccountManager.Models.News.Commands.UnpublishNewsCommand>(newsCommandService.Handle); _bus.RegisterHandler<AccountManager.Models.News.Commands.UpdateNewsCommand>(newsCommandService.Handle); _bus.RegisterHandler<AccountManager.Models.News.Commands.DeleteNewsCommand>(newsCommandService.Handle); var _newsProjection = new AccountManager.Models.News.ReadModel.NewsProjection(); _bus.RegisterHandler<AccountManager.Models.News.Events.NewsCreatedEvent>(_newsProjection.Handle); _bus.RegisterHandler<AccountManager.Models.News.Events.NewsPublishedEvent>(_newsProjection.Handle); _bus.RegisterHandler<AccountManager.Models.News.Events.NewsUnpublishedEvent>(_newsProjection.Handle); _bus.RegisterHandler<AccountManager.Models.News.Events.NewsUpdatedEvent>(_newsProjection.Handle); _bus.RegisterHandler<AccountManager.Models.News.Events.NewsDeletedEvent>(_newsProjection.Handle); _NewsReadModel = new NewsReadModelFacade(_newsProjection); /* rehydrate */ var events = eventStore.GetAllEventsEver(); _bus.Publish(events); }
public void Test() { var newMessages = new List<object>(); var bus = new MessageBus(); bus.RegisterHandler<object>(newMessages.Add); var eventStore = new InMemoryEventStore(bus, GivenTheseEvents()); var repository = new DomainRepository(eventStore); RegisterHandler(bus, repository); try { bus.Handle(WhenThisHappens()); } catch(Exception e) { var expectedException = ThisExceptionShouldOccur(); if(expectedException == null) Assert.Fail(e.Message); if(expectedException.GetType().IsAssignableFrom(e.GetType())) { Assert.AreEqual(expectedException.Message, e.Message); return; } Assert.Fail("Expected exception of type {0} with message {1} but got exception of type {2} with message {3}", expectedException.GetType(), expectedException.Message, e.GetType(), e.Message); } var expectedEvents = TheseEventsShouldOccur().ToList(); var comparer = new CompareObjects(); if(!comparer.Compare(expectedEvents, newMessages)) { Assert.Fail(comparer.DifferencesString); } }
int Run() { var testTypes = typeof(AccountShouldBeLockedAfterThreeOverdraws).Assembly.GetTypes().Where(x => typeof(TestBase).IsAssignableFrom(x) && x.IsAbstract == false); foreach (var type in testTypes) { var test = Activator.CreateInstance(type) as TestBase; var newMessages = new List<object>(); var bus = new MessageBus(); bus.RegisterHandler<object>(newMessages.Add); var eventStore = new InMemoryEventStore(bus, test.GivenTheseEvents()); var repository = new DomainRepository(eventStore); test.RegisterHandler(bus, repository); printGivens(type, test); var command = test.WhenThisHappens(); Exception exception = null; var expectedException = test.ThisExceptionShouldOccur(); try { bus.Handle(command); } catch(Exception e) { exception = e; } var foundException = printException(expectedException, exception, command); if(foundException) continue; ; printThens(test.TheseEventsShouldOccur().ToList(), newMessages, command); Console.WriteLine(); Console.WriteLine(new string('=', 40)); Console.WriteLine(); } return _suuccess ? 0 : -1; }