Esempio n. 1
0
        public void Retrieving_all_events_should_return_the_same_as_added()
        {
            var targetStore = new RavenDBEventStore(_documentStore);
            var id          = Guid.NewGuid();

            int sequenceCounter = 0;

            var events = new SourcedEvent[]
            {
                new CustomerCreatedEvent(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow, "Foo",
                                         35),
                new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                        "Name" + sequenceCounter),
                new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                        "Name" + sequenceCounter),
                new CustomerNameChanged(Guid.NewGuid(), id, sequenceCounter++, DateTime.UtcNow,
                                        "Name" + sequenceCounter)
            };

            var eventSource = MockRepository.GenerateMock <IEventSource>();

            eventSource.Stub(e => e.EventSourceId).Return(id);
            eventSource.Stub(e => e.InitialVersion).Return(0);
            eventSource.Stub(e => e.Version).Return(events.Length);
            eventSource.Stub(e => e.GetUncommittedEvents()).Return(events);

            targetStore.Save(eventSource);

            var result = targetStore.GetAllEvents(id);

            result.Count().Should().Be(events.Length);
            result.First().EventIdentifier.Should().Be(events.First().EventIdentifier);
            Assert.IsTrue(result.SequenceEqual(events));
        }
        public void Retrieving_all_events_should_return_the_same_as_added()
        {
            var targetStore = new MsSqlServerEventStore(connectionString);
            var aggregateId = Guid.NewGuid();
            var entityId    = Guid.NewGuid();

            int sequenceCounter = 1;
            var events          = new SourcedEvent[]
            {
                new CustomerCreatedEvent(Guid.NewGuid(), aggregateId, sequenceCounter++, DateTime.UtcNow, "Foo",
                                         35),
                new CustomerNameChanged(Guid.NewGuid(), aggregateId, sequenceCounter++, DateTime.UtcNow,
                                        "Name" + sequenceCounter),
                new CustomerNameChanged(Guid.NewGuid(), aggregateId, sequenceCounter++, DateTime.UtcNow,
                                        "Name" + sequenceCounter),
                new CustomerNameChanged(Guid.NewGuid(), aggregateId, sequenceCounter++, DateTime.UtcNow,
                                        "Name" + sequenceCounter),
                new AccountNameChangedEvent(Guid.NewGuid(), aggregateId, entityId, sequenceCounter++, DateTime.UtcNow, "New Account Title" + sequenceCounter)
            };

            var eventSource = MockRepository.GenerateMock <IEventSource>();

            eventSource.Stub(e => e.EventSourceId).Return(aggregateId);
            eventSource.Stub(e => e.InitialVersion).Return(0);
            eventSource.Stub(e => e.Version).Return(events.Length);
            eventSource.Stub(e => e.GetUncommittedEvents()).Return(events);

            targetStore.Save(eventSource);

            var result = targetStore.GetAllEvents(aggregateId);

            result.Count().Should().Be(events.Length);
            result.First().EventIdentifier.Should().Be(events.First().EventIdentifier);

            var foundEntityId = result.ElementAt(4).As <SourcedEntityEvent>().EntityId;

            foundEntityId.Should().Be(entityId);
        }