Example #1
0
        public void Should_PublishAndApplyEvent_NonGeneric()
        {
            // Arrange
            var serializationStrategy = new JsonEventSerializationStrategy();

            // if you want to use real database like mongo, use next two lines to configure and then use it to configure event store
//            var mongoAggregateEventsRepository = new MongoRepository<AggregateEvent>("mongodb://localhost", "DDD_Light_Tests_EventStore", "EventStore");
//            mongoAggregateEventsRepository.DeleteAll();

            var inMemoryAggregateEventsRepository = new InMemoryRepository <Guid, AggregateEvent>();

            inMemoryAggregateEventsRepository.DeleteAll();

            EventStore.EventStore.Instance.Configure(inMemoryAggregateEventsRepository, serializationStrategy);
            EventBus.Instance.Configure(EventStore.EventStore.Instance, serializationStrategy, false);

            Func <Type, object> getInstance = type =>
            {
                if (type == typeof(SomeAggregateRootCreatedHandler))
                {
                    return(new SomeAggregateRootCreatedHandler());
                }
                if (type == typeof(MockHandler))
                {
                    return(new MockHandler());
                }
                if (type == typeof(IRepository <Guid, SomeAggregateRoot>))
                {
                    return(new InMemoryRepository <Guid, SomeAggregateRoot>());
                }
                throw new Exception("type " + type.ToString() + " could not be resolved");
            };

            HandlerSubscribtions.SubscribeAllHandlers(getInstance);

            AggregateCache.AggregateCache.Instance.Configure(EventStore.EventStore.Instance, getInstance);
            AggregateBus.InProcess.AggregateBus.Instance.Configure(EventBus.Instance, AggregateCache.AggregateCache.Instance);

            const string createdMessage = "hello, I am created!";

            var id = Guid.NewGuid();

            // Act
            var ar = new SomeAggregateRoot(id, createdMessage);

            // Assert
            Assert.AreEqual(1, EventStore.EventStore.Instance.Count());
            Assert.AreEqual(typeof(SomeAggregateRootCreated), Type.GetType(EventStore.EventStore.Instance.GetAll().First().EventType));
            Assert.AreEqual(createdMessage, ((SomeAggregateRootCreated)serializationStrategy.DeserializeEvent(EventStore.EventStore.Instance.GetAll().First().SerializedEvent, typeof(SomeAggregateRootCreated))).Message);
        }
Example #2
0
 private static void InitApp(IEventStore eventStore)
 {
     HandlerSubscribtions.SubscribeAllHandlers(ObjectFactory.GetInstance);
     CreateRealtorIfNoneExist(eventStore);
 }