Example #1
0
        public void be_reidrated_from_database()
        {
            var eventStore       = new SqlEventStore(new DomainEventJsonEventSerializer(), new FakeEventStamping());
            var eventBus         = new EventBus(new EventDispatcher(), eventStore);
            var createdStagiaire = Student.Create("BOUDOUX", "Aurelien");

            eventBus.Publish(createdStagiaire.UncommitedEvents);

            var studentId = createdStagiaire.AggregateId;
            var events    = eventStore.GetEvents(studentId);
            var student   = new Student(new History(events));

            student.Update("BOUDOUX", "Aurélien");
            eventBus.Publish(student.UncommitedEvents);

            var student1 = new Student(new History(eventStore.GetEvents(studentId)));

            student1.Update("BOUDOUX", "Aurélien");
            student1.UncommitedEvents.GetStream().Should().BeEmpty();
        }
Example #2
0
        public void retrieve_events_for_registered_aggregate()
        {
            var id    = Guid.NewGuid();
            var store = new SqlEventStore(new DomainEventJsonEventSerializer(new DomainEventTypeBinder(Assembly.GetExecutingAssembly())), new FakeEventStamping());

            store.Save(new SqlTestEvent(id, 1, "test"));
            store.Save(new SqlTestEvent(id, 2, "test2"));
            store.Save(new SqlTestEvent(id, 3, "test3"));

            var events = store.GetEvents(id);

            events.Should().HaveCount(3);
            events.Should().Contain(new SqlTestEvent(id, 1, "test"));
        }
Example #3
0
        public void SqlEventStore_Deserializes_Events()
        {
            var id     = Guid.NewGuid();
            var events = new List <EventStream>
            {
                new EventStream
                {
                    AggregateRootId = id,
                    DateCreated     = DateTime.Now,
                    EventData       = Resources.JsonSerializedDebitEvent,
                    Id            = 1,
                    SequenceStart = 2,
                    SequenceEnd   = 2
                },
                new EventStream
                {
                    AggregateRootId = id,
                    DateCreated     = DateTime.Now,
                    EventData       = Resources.JsonSerializedNewAccountEvent,
                    Id            = 1,
                    SequenceStart = 1,
                    SequenceEnd   = 1
                }
            };

            var database = new Mock <ISqlRepository>();

            database.Setup(db => db.GetEventStream(It.IsAny <Guid>(), It.IsAny <long>())).Returns(events);

            var store = new SqlEventStore
            {
                GetRepository = () => database.Object
            };

            var eventStream = store.GetEvents(id, 1).ToList();

            Assert.AreEqual(2, eventStream.Count());
            Assert.AreEqual(1, eventStream[0].Sequence);
            Assert.AreEqual(2, eventStream[1].Sequence);
            Assert.IsInstanceOf <AccountCreatedEvent>(eventStream[0]);
            Assert.IsInstanceOf <AccountDebitedEvent>(eventStream[1]);
        }