public Save ( IEventSource eventSource ) : void | ||
eventSource | IEventSource | |
Résultat | void |
public void Retrieving_all_events_should_return_the_same_as_added() { var targetStore = new MsSqlServerEventStore(DEFAULT_CONNECTION); var id = Guid.NewGuid(); int sequenceCounter = 1; 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); }
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); }
public void Saving_event_source_while_there_is_a_newer_event_source_should_throw_concurency_exception() { var targetStore = new MsSqlServerEventStore(connectionString); 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) }; var eventSource = MockRepository.GenerateMock<IEventSource>(); eventSource.Stub(e => e.EventSourceId).Return(id).Repeat.Any(); eventSource.Stub(e => e.InitialVersion).Return(0).Repeat.Any(); eventSource.Stub(e => e.Version).Return(events.Length).Repeat.Any(); eventSource.Stub(e => e.GetUncommittedEvents()).Return(events).Repeat.Any(); targetStore.Save(eventSource); Action act = () => targetStore.Save(eventSource); act.ShouldThrow<ConcurrencyException>(); }
public void Saving_event_source_should_succeed() { var targetStore = new MsSqlServerEventStore(connectionString); 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); }