예제 #1
0
        public void SqlEventStore_Serialized_Events()
        {
            var database = new Mock<ISqlRepository>();
            database.Setup(db => db.InsertEvents(It.IsAny<EventStream>()));

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

            var events = new List<DomainEvent>
            {
                new AccountCreatedEvent(Guid.NewGuid(), 100),
                new AccountDebitedEvent(Guid.NewGuid(), 50)
            };

            store.Insert(Guid.NewGuid(), events);

            database.Verify(db => db.InsertEvents(It.IsAny<EventStream>()), Times.Once);
        }
예제 #2
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]);
        }