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 Saving_event_source_should_succeed() { var targetStore = new MsSqlServerEventStore(DEFAULT_CONNECTION); 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); }
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); }
protected override void InitializeEnvironment() { var store = new MsSqlServerEventStore(GetConnectionString()); NcqrsEnvironment.SetDefault<ISnapshotStore>(store); NcqrsEnvironment.SetDefault<IEventStore>(store); NcqrsEnvironment.SetDefault<IUnitOfWorkFactory>(new UnitOfWorkFactory()); }
private static IEventStore InitializeEventStore() { var typeResolver = new AttributeEventTypeResolver(); typeResolver.AddAllEventsInAssembly(typeof(Program).Assembly); var eventStore = new MsSqlServerEventStore(ConfigurationManager.ConnectionStrings["EventStore"].ConnectionString, typeResolver, null); return eventStore; }
private static void GenerateEvents() { var eventStore = new MsSqlServerEventStore(ConfigurationManager.ConnectionStrings["Main"].ConnectionString); for (int i = 0; i < 1000; i++) { eventStore.SaveEvents(new[] { new RandomEvent(i) }); } }
private static IEventStore InitializeEventStore() { var typeResolver = new AttributeEventTypeResolver(); typeResolver.AddEvent(typeof(NameChangedEvent)); typeResolver.AddEvent(typeof(PersonCreatedEvent)); var eventStore = new MsSqlServerEventStore(ConfigurationManager.ConnectionStrings["EventStore"].ConnectionString, typeResolver, null); return eventStore; }
private static IEventStore InitializeEventStore() { var propertyBagConverter = new PropertyBagConverter(); // Register type converter. propertyBagConverter.TypeResolver = new AppV2EventsTypeResolver(); var eventStore = new MsSqlServerEventStore("Data Source=.\\sqlexpress; Initial Catalog=VersioningEventStore; Integrated Security=SSPI;", propertyBagConverter); return eventStore; }
private static void GenerateEvents() { var eventStore = new MsSqlServerEventStore(ConfigurationManager.ConnectionStrings["Main"].ConnectionString); for (int i = 0; i < 1000; i++) { var uncommittedEventStream = new UncommittedEventStream(Guid.NewGuid()); uncommittedEventStream.Append(new UncommittedEvent(Guid.NewGuid(), Guid.NewGuid(), i, i, DateTime.Now, new object(), new Version(1, 0))); eventStore.Store(uncommittedEventStream); } }
private static IEventStore InitializeEventStore() { var converter = new PropertyBagConverter(); converter.TypeResolver = new AppV2EventsTypeResolver(); converter.AddPostConversion(typeof(NameChangedEvent), new NameChangedEventPostConverter()); converter.AddPostConversion(typeof(PersonCreatedEvent), new PersonCreatedEventPostConverter()); var eventStore = new MsSqlServerEventStore("Data Source=.\\sqlexpress; Initial Catalog=VersioningEventStore; Integrated Security=SSPI;", converter); return eventStore; }
private static IEventStore InitializeEventStore() { var typeResolver = new AttributeEventTypeResolver(); typeResolver.AddAllEventsInAssembly(typeof(Program).Assembly); var converter = new EventConverter(typeResolver); converter.AddConverter(typeof(NameChangedEvent), new NameChangedEventPostConverter()); converter.AddConverter(typeof(PersonCreatedEvent), new PersonCreatedEventPostConverter()); var eventStore = new MsSqlServerEventStore(ConfigurationManager.ConnectionStrings["EventStore"].ConnectionString, typeResolver, converter); return eventStore; }
private static void GenerateEventsForAggregateRoots() { const int aggregateRootCount = 10; var aggregateRoots = Enumerable.Range(0, aggregateRootCount).Select(x => Guid.NewGuid()).ToList(); var random = new Random(); var eventStore = new MsSqlServerEventStore(ConfigurationManager.ConnectionStrings["Main"].ConnectionString); for (int i = 0; i < 1000; i++) { Guid rootId = aggregateRoots[random.Next(aggregateRootCount)]; eventStore.SaveEvents(new[] { new RandomEvent(rootId, i) }); } }
private static void GenerateEventsForAggregateRoots() { const int aggregateRootCount = 10; var aggregateRoots = Enumerable.Range(0, aggregateRootCount).Select(x => Guid.NewGuid()).ToList(); var random = new Random(); var eventStore = new MsSqlServerEventStore(ConfigurationManager.ConnectionStrings["Main"].ConnectionString); for (int i = 0; i < 1000; i++) { Guid rootId = aggregateRoots[random.Next(aggregateRootCount)]; var uncommittedEventStream = new UncommittedEventStream(Guid.NewGuid()); uncommittedEventStream.Append(new UncommittedEvent(Guid.NewGuid(), rootId, i, i, DateTime.Now, new object(), new Version(1, 0))); } }
private static void ConfigureNcqrsEnvironment(InMemoryBufferedBrowsableElementStore buffer) { var eventStoreConnectionString = ConfigurationManager.ConnectionStrings["MyNotes Event Store"].ConnectionString; var eventStore = new MsSqlServerEventStore(eventStoreConnectionString); Assembly domainAssembly = Assembly.LoadFrom("MyNotes.Domain.dll"); IWindsorContainer container = new WindsorContainer(); container.AddFacility("ncqrs.ds", new DynamicSnapshotFacility(domainAssembly)); container.Register( Component.For<ISnapshottingPolicy>().ImplementedBy<SimpleSnapshottingPolicy>(), Component.For<ICommandService>().Instance(InitializeCommandService()), Component.For<IEventBus>().Instance(InitializeEventBus(buffer)), Component.For<IEventStore>().Forward<ISnapshotStore>().Instance(eventStore), Component.For<IKnownCommandsEnumerator>().Instance(new AllCommandsInAppDomainEnumerator()), Component.For<Note>().AsSnapshotable()); WindsorConfiguration config = new WindsorConfiguration(container); NcqrsEnvironment.Configure(config); }
public void Storing_empty_event_stream_should_not_throw() { var targetStore = new MsSqlServerEventStore(connectionString); var theEventSourceId = Guid.NewGuid(); var theCommitId = Guid.NewGuid(); var eventStream = Prepare.Events(new object[0]) .ForSourceUncomitted(theEventSourceId, theCommitId); targetStore.Store(eventStream); Assert.Pass(); }
public void Saving_with_concurrent_event_adds_should_not_be_causing_deadlocks() { // test created in response to an issue with high frequency adds causing deadlocks on the EventSource table. // I reworked the sequencing of reads/updates to the EventSource table to reduce the amount // of time to any locks will be held. But this wasn't strictly required as the problem resided // in the fact that there was no index on the event source table result in full table scans occuring. // I therefore also changed the DDL to incude an non clustered index on EventSource.Id which resulted // in a nice performance boost during informal testing. var targetStore = new MsSqlServerEventStore(connectionString); var tasks = new Task[30]; // this number require to reproduce the issue might vary depending on hardware for (int idx = 0; idx < tasks.Length; idx++) { tasks[idx] = Task.Factory.StartNew(() => { var theEventSourceId = Guid.NewGuid(); var theCommitId = Guid.NewGuid(); var eventStream = Prepare.Events(new CustomerCreatedEvent(Task.CurrentId.ToString(), 35)) .ForSourceUncomitted(theEventSourceId, theCommitId); // should not be receiving a deadlock targetStore.Store(eventStream); }); } Task.WaitAll(tasks); }
public void Saving_snapshot_should_not_throw_an_exception_when_snapshot_is_valid() { var targetStore = new MsSqlServerEventStore(connectionString); var anId = Guid.NewGuid(); var aVersion = 12; var snapshot = new Snapshot(anId, aVersion, new MySnapshot()); targetStore.SaveSnapshot(snapshot); var savedSnapshot = targetStore.GetSnapshot(anId, long.MaxValue); savedSnapshot.EventSourceId.Should().Be(anId); savedSnapshot.Version.Should().Be(aVersion); }
public void Storing_entity_sourced_event_should_preserve_entity_id() { var targetStore = new MsSqlServerEventStore(connectionString); var theEventSourceId = Guid.NewGuid(); var theCommitId = Guid.NewGuid(); var theEntityId = Guid.NewGuid(); var eventStream = Prepare.Events(new AccountNameChangedEvent(theEntityId, "NewName")) .ForSourceUncomitted(theEventSourceId, theCommitId); targetStore.Store(eventStream); var restoredEvent = targetStore.ReadFrom(theEventSourceId, long.MinValue, long.MaxValue).Single(); var payload = (AccountNameChangedEvent)restoredEvent.Payload; payload.EntityId.Should().Be(theEntityId); }
public void Saving_with_concurrent_event_edits_should_be_subject_to_concurrency_checks() { // test created in response to an issue with concurrent edits happening within the window between // reading the current version number of the aggregate and the event source record being updated with // the new version number. this would leave the event stream for an event source out of sequence and // the aggregate in a state in which it could not be retrieved :o var concurrencyExceptionThrown = false; var targetStore = new MsSqlServerEventStore(connectionString); var theEventSourceId = Guid.NewGuid(); var theCommitId = Guid.NewGuid(); // make sure that the event source for the aggregate is created var creationEvent = Prepare.Events(new CustomerCreatedEvent("Foo", 35)) .ForSourceUncomitted(theEventSourceId, theCommitId); targetStore.Store(creationEvent); var tasks = new Task[130]; // now simulate concurreny updates coming in on the same aggregate for (int idx = 0; idx < tasks.Length; idx++) { tasks[idx] = Task.Factory.StartNew(() => { var changeEvent = new CustomerNameChanged(DateTime.Now.Ticks.ToString()) { CustomerId = theEventSourceId }; var eventStream = Prepare.Events(changeEvent) .ForSourceUncomitted(theEventSourceId, Guid.NewGuid(), 2); try { targetStore.Store(eventStream); } catch (ConcurrencyException) { concurrencyExceptionThrown = true; } targetStore.ReadFrom(theEventSourceId, long.MinValue, long.MaxValue); }); } Task.WaitAll(tasks); if (concurrencyExceptionThrown == false) { Assert.Fail("We're expecting concurrency exceptions!"); } }
private static IEventStore InitializeEventStore() { var store = new MsSqlServerEventStore(RoleEnvironment.GetConfigurationSettingValue("EventStoreConnectionString")); return store; }
public void Storing_event_source_should_succeed() { var targetStore = new MsSqlServerEventStore(connectionString); var theEventSourceId = Guid.NewGuid(); var theCommitId = Guid.NewGuid(); var eventStream = Prepare.Events( new CustomerCreatedEvent("Foo", 35), new CustomerNameChanged("Name" + 2), new CustomerNameChanged("Name" + 3), new CustomerNameChanged("Name" + 4)) .ForSourceUncomitted(theEventSourceId, theCommitId); targetStore.Store(eventStream); var eventsFromStore = targetStore.ReadFrom(theEventSourceId, long.MinValue, long.MaxValue); eventsFromStore.Count().Should().Be(eventStream.Count()); for (int i = 0; i < eventsFromStore.Count(); i++) { var uncommittedEvent = eventStream.ElementAt(i); var committedEvent = eventsFromStore.ElementAt(i); committedEvent.EventSourceId.Should().Be(uncommittedEvent.EventSourceId); committedEvent.EventIdentifier.Should().Be(uncommittedEvent.EventIdentifier); committedEvent.EventSequence.Should().Be(uncommittedEvent.EventSequence); committedEvent.Payload.GetType().Should().Be(uncommittedEvent.Payload.GetType()); } }
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>(); }
private static IEventStore InitializeEventStore() { var eventStore = new MsSqlServerEventStore("Data Source=.\\sqlexpress; Initial Catalog=VersioningEventStore; Integrated Security=SSPI;"); return eventStore; }
public MsSqlServerEventStoreElementStore(string connectionString) { _wrappedStore = new MsSqlServerEventStore(connectionString); _connectionString = connectionString; }
private static IEventStore InitializeEventStore() { var store = new MsSqlServerEventStore(@"Data Source=.\sqlexpress;Initial Catalog=NCQRSWorkshopEventStore;Integrated Security=True"); return store; }
private static IEventStore CreateEventStore() { var store = new MsSqlServerEventStore(@"Server=.\SQLEXPRESS;Database=EventStore;Trusted_Connection=True;"); return store; }
private static IEventStore InitializeEventStore() { var store = new MsSqlServerEventStore(Settings.Default.SqlEventStoreConnectionString); return store; }
private static IEventStore InitializeEventStore() { var store = new MsSqlServerEventStore(@"Data Source=.\SQLEXPRESS;Initial Catalog=EeffEventStore;Integrated Security=True"); return store; }
public void Saving_snapshot_should_not_throw_an_exception_when_snapshot_is_valid() { var targetStore = new MsSqlServerEventStore(DEFAULT_CONNECTION); var anId = Guid.NewGuid(); var aVersion = 12; var snapshot = new MySnapshot{EventSourceId=anId, EventSourceVersion=aVersion}; targetStore.SaveShapshot(snapshot); var savedSnapshot = targetStore.GetSnapshot(anId); savedSnapshot.EventSourceId.Should().Be(anId); savedSnapshot.EventSourceVersion.Should().Be(aVersion); }
private static IEventStore InitializeEventStore() { var store = new MsSqlServerEventStore(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString); return store; }