public void It_should_persist_successfully() { using (var store = DocumentStoreBuilder.Build()) { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga1); factory.SaveChanges(); factory.ReleaseSession(); var saga = persister.Get <SagaData>(saga1.Id); persister.Complete(saga); factory.SaveChanges(); factory.ReleaseSession(); var saga2 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga2); factory.SaveChanges(); } }
public void It_should_enforce_uniqueness() { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga1); factory.SaveChanges(); factory.ReleaseSession(); Assert.Throws<ConcurrencyException>(() => { var saga2 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga2); factory.SaveChanges(); }); }
public void It_should_allow_the_update() { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga1); factory.SaveChanges(); factory.ReleaseSession(); var saga = persister.Get<SagaData>(saga1.Id); saga.UniqueString = Guid.NewGuid().ToString(); persister.Update(saga); factory.SaveChanges(); factory.ReleaseSession(); var saga2 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; //this should not blow since we changed the unique value in the previous saga persister.Save(saga2); factory.SaveChanges(); }
public void It_should_persist_successfully() { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga1); factory.SaveChanges(); factory.ReleaseSession(); var saga = persister.Get<SagaData>(saga1.Id); persister.Complete(saga); factory.SaveChanges(); factory.ReleaseSession(); var saga2 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga2); factory.SaveChanges(); }
public void It_should_allow_the_update() { using (var store = DocumentStoreBuilder.Build()) { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga1); factory.SaveChanges(); factory.ReleaseSession(); var saga = persister.Get <SagaData>(saga1.Id); saga.UniqueString = Guid.NewGuid().ToString(); persister.Update(saga); factory.SaveChanges(); factory.ReleaseSession(); var saga2 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; //this should not blow since we changed the unique value in the previous saga persister.Save(saga2); factory.SaveChanges(); } }
public void It_should_enforce_uniqueness() { using (var store = DocumentStoreBuilder.Build()) { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga1); factory.SaveChanges(); factory.ReleaseSession(); Assert.Throws <ConcurrencyException>(() => { var saga2 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga2); factory.SaveChanges(); }); } }
public async Task Should_query_by_saga_type() { var otherSaga = new SomeOtherSagaData { Id = Guid.NewGuid(), SomeId = "test-id", SomeName = "Test Name" }; var saga = new SagaData { Id = Guid.NewGuid(), SomeId = "test-id", SomeName = "Test Name" }; IDocumentSession session; var context = this.CreateContextWithSessionPresent(out session); var sagaPersister = new SagaPersister(); var synchronizedStorageSession = new MartenSynchronizedStorageSession(session, true); var correlationProperty = new SagaCorrelationProperty("SomeId", saga.SomeId); await sagaPersister.Save(otherSaga, correlationProperty, synchronizedStorageSession, context); await sagaPersister.Save(saga, correlationProperty, synchronizedStorageSession, context); await session.SaveChangesAsync().ConfigureAwait(false); var savedSaga = await sagaPersister.Get <SagaData>(correlationProperty.Name, correlationProperty.Value, synchronizedStorageSession, context); savedSaga.Id.Should().Be(saga.Id); }
public async Task When_a_duplicate_messages_starting_a_saga_arrive_simultanously_one_of_them_fails() { var context = CreateMessageContext(); var transaction1 = await outboxPersister.BeginTransaction(context); var session1 = new OutboxEventStoreSynchronizedStorageSession(connection, (EventStoreOutboxTransaction)transaction1); var sagaData = CreateNewSagaData(); await persister.Save(sagaData, new SagaCorrelationProperty(CorrelationPropName, sagaData.StringProperty), session1, context); var transaction2 = await outboxPersister.BeginTransaction(context); var session2 = new OutboxEventStoreSynchronizedStorageSession(connection, (EventStoreOutboxTransaction)transaction2); try { await persister.Save(sagaData, new SagaCorrelationProperty(CorrelationPropName, sagaData.StringProperty), session2, context); Assert.Fail("Expected exception"); } catch (Exception ex) { StringAssert.StartsWith("Append failed due to WrongExpectedVersion.", ex.Message); } }
public async Task Should_delete_the_unique_doc_properly() { var sagaId = Guid.NewGuid(); IAsyncDocumentSession session; var options = this.CreateContextWithAsyncSessionPresent(out session); var persister = new SagaPersister(); var sagaEntity = new SagaData { Id = sagaId, SomeId = Guid.NewGuid() }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session); await persister.Save(sagaEntity, this.CreateMetadata <SomeSaga>(sagaEntity), synchronizedSession, options); //session.Advanced.GetMetadataFor(sagaEntity).Remove("NServiceBus-UniqueDocId"); await session.SaveChangesAsync().ConfigureAwait(false); var saga = await persister.Get <SagaData>(sagaId, synchronizedSession, options); await persister.Complete(saga, synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); Assert.Null(await session.Query <SagaUniqueIdentity>().Customize(c => c.WaitForNonStaleResults()).SingleOrDefaultAsync(u => u.SagaId == sagaId)); }
public async Task The_saga_data_should_be_removed() { var saga = new SagaData { Id = Guid.NewGuid(), SomeId = "test-id", SomeName = "Test Name" }; IDocumentSession session; var context = this.CreateContextWithSessionPresent(out session); var sagaPersister = new SagaPersister(); var synchronizedStorageSession = new MartenSynchronizedStorageSession(session, true); await sagaPersister.Save(saga, new SagaCorrelationProperty("SomeId", saga.SomeId), synchronizedStorageSession, context); await session.SaveChangesAsync().ConfigureAwait(false); await sagaPersister.Complete(saga, synchronizedStorageSession, context); await session.SaveChangesAsync().ConfigureAwait(false); var savedSaga = await sagaPersister.Get <SagaData>(saga.Id, synchronizedStorageSession, context); savedSaga.Should().BeNull(); }
public async Task Public_setters_and_getters_of_concrete_classes_should_be_persisted() { var entity = new SagaData { Id = Guid.NewGuid(), UniqueString = "SomeUniqueString", TestComponent = new TestComponent { Property = "Prop" } }; using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var persister = new SagaPersister(new SagaPersistenceConfiguration()); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, options); await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); var savedEntity = await persister.Get <SagaData>(entity.Id, synchronizedSession, options); Assert.AreEqual(entity.TestComponent.Property, savedEntity.TestComponent.Property); Assert.AreEqual(entity.TestComponent.AnotherProperty, savedEntity.TestComponent.AnotherProperty); } }
public async Task Schema_version_should_be_persisted() { // arrange var entity = new SagaData { Id = Guid.NewGuid(), UniqueString = "SomeUniqueString", }; var persister = new SagaPersister(); using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var context)) { var synchronizedSession = new RavenDBSynchronizedStorageSession(session); // act await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, context); await session.SaveChangesAsync(); // assert var sagaDataContainerId = SagaPersister.DocumentIdForSagaData(session, entity); var sagaDataContainer = await session.LoadAsync <SagaDataContainer>(sagaDataContainerId); var sagaDataContainerMetadata = session.Advanced.GetMetadataFor(sagaDataContainer); var sagaUniqueIdentityId = sagaDataContainer.IdentityDocId; var sagaUniqueIdentity = await session.LoadAsync <SagaUniqueIdentity>(sagaUniqueIdentityId); var sagaUniqueIdentityMetadata = session.Advanced.GetMetadataFor(sagaUniqueIdentity); Assert.AreEqual(SagaDataContainer.SchemaVersion, sagaDataContainerMetadata[SchemaVersionExtensions.SagaDataContainerSchemaVersionMetadataKey]); Assert.AreEqual(SagaUniqueIdentity.SchemaVersion, sagaUniqueIdentityMetadata[SchemaVersionExtensions.SagaUniqueIdentitySchemaVersionMetadataKey]); } }
public async Task Should_delete_the_saga_and_the_unique_doc() { var sagaId = Guid.NewGuid(); using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var persister = new SagaPersister(); var entity = new SagaData { Id = sagaId }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session); await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); var saga = await persister.Get <SagaData>(sagaId, synchronizedSession, options); await persister.Complete(saga, synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); Assert.Null(await persister.Get <SagaData>(sagaId, synchronizedSession, options)); Assert.Null(await session.Query <SagaUniqueIdentity>().Customize(c => c.WaitForNonStaleResults()).SingleOrDefaultAsync(u => u.SagaId == sagaId).ConfigureAwait(false)); } }
public async Task Inherited_property_classes_should_be_persisted() { IAsyncDocumentSession session; var options = this.CreateContextWithAsyncSessionPresent(out session); var persister = new SagaPersister(); var entity = new SagaData { Id = Guid.NewGuid(), UniqueString = "SomeUniqueString", PolymorphicRelatedProperty = new PolymorphicProperty { SomeInt = 9 } }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session, true); await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); var savedEntity = await persister.Get <SagaData>(entity.Id, synchronizedSession, options); var expected = (PolymorphicProperty)entity.PolymorphicRelatedProperty; var actual = (PolymorphicProperty)savedEntity.PolymorphicRelatedProperty; Assert.AreEqual(expected.SomeInt, actual.SomeInt); }
public async Task It_should_persist_successfully() { IAsyncDocumentSession session; var options = this.CreateContextWithAsyncSessionPresent(out session); var persister = new SagaPersister(); var uniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString, NonUniqueString = "notUnique" }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session, true); await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); var saga = await persister.Get <SagaData>(saga1.Id, synchronizedSession, options); saga.NonUniqueString = "notUnique2"; await persister.Update(saga, synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); }
public async Task The_database_should_enforce_the_uniqueness() { var failed = false; using (var session = SessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { var correlationProperty = new SagaCorrelationProperty("UniqueString", "whatever"); var storageSession = new TestingNHibernateSynchronizedStorageSession(session); await SagaPersister.Save(new SagaWithUniqueProperty { Id = Guid.NewGuid(), UniqueString = "whatever" }, correlationProperty, storageSession, new ContextBag()).ConfigureAwait(false); await SagaPersister.Save(new SagaWithUniqueProperty { Id = Guid.NewGuid(), UniqueString = "whatever" }, correlationProperty, storageSession, new ContextBag()).ConfigureAwait(false); try { transaction.Commit(); } catch (Exception) { failed = true; } } Assert.IsTrue(failed); }
public async Task It_should_persist_successfully() { var saga = new SagaData { Id = Guid.NewGuid(), SomeId = "test-id", SomeName = "Test Name" }; IDocumentSession session; var context = this.CreateContextWithSessionPresent(out session); var sagaPersister = new SagaPersister(); var synchronizedStorageSession = new MartenSynchronizedStorageSession(session, true); await sagaPersister.Save(saga, new SagaCorrelationProperty("SomeId", saga.SomeId), synchronizedStorageSession, context); await session.SaveChangesAsync().ConfigureAwait(false); var savedSaga = await sagaPersister.Get <SagaData>(saga.Id, synchronizedStorageSession, context); savedSaga.SomeName = "Another name"; await sagaPersister.Update(saga, synchronizedStorageSession, context); await session.SaveChangesAsync().ConfigureAwait(false); var updatedSaga = await sagaPersister.Get <SagaData>(saga.Id, synchronizedStorageSession, context); updatedSaga.SomeName.Should().Be("Another name"); }
public async Task Public_setters_and_getters_of_concrete_classes_should_be_persisted() { var entity = new SagaData { Id = Guid.NewGuid(), UniqueString = "SomeUniqueString", TestComponent = new TestComponent { Property = "Prop" } }; IAsyncDocumentSession session; var options = this.CreateContextWithAsyncSessionPresent(out session); var persister = new SagaPersister(); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, true); await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); var savedEntity = await persister.Get <SagaData>(entity.Id, synchronizedSession, options); Assert.AreEqual(entity.TestComponent.Property, savedEntity.TestComponent.Property); Assert.AreEqual(entity.TestComponent.AnotherProperty, savedEntity.TestComponent.AnotherProperty); }
public void It_should_persist_successfully() { using (var store = DocumentStoreBuilder.Build()) { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var anotherUniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString, NonUniqueString = "notUnique" }; persister.Save(saga1); factory.SaveChanges(); var saga = persister.Get <SagaData>(saga1.Id); saga.NonUniqueString = "notUnique2"; saga.UniqueString = anotherUniqueString; persister.Update(saga); factory.SaveChanges(); } }
public async Task It_should_persist_successfully() { using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var persister = new SagaPersister(); var uniqueString = Guid.NewGuid().ToString(); var anotherUniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString, NonUniqueString = "notUnique" }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session); await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); var saga = await persister.Get <SagaData>(saga1.Id, synchronizedSession, options); saga.NonUniqueString = "notUnique2"; saga.UniqueString = anotherUniqueString; await persister.Update(saga, synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); } }
public async Task Inherited_property_classes_should_be_persisted() { using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var persister = new SagaPersister(new SagaPersistenceConfiguration()); var entity = new SagaData { Id = Guid.NewGuid(), UniqueString = "SomeUniqueString", PolymorphicRelatedProperty = new PolymorphicProperty { SomeInt = 9 } }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session, options); await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); var savedEntity = await persister.Get <SagaData>(entity.Id, synchronizedSession, options); var expected = (PolymorphicProperty)entity.PolymorphicRelatedProperty; var actual = (PolymorphicProperty)savedEntity.PolymorphicRelatedProperty; Assert.AreEqual(expected.SomeInt, actual.SomeInt); } }
public void SetUp() { _sagaEntityA = new SagaEntityA { Id = Guid.NewGuid(), SomeIdentifier = IDENTIFIER }; SagaPersister.Save(_sagaEntityA); SagaPersister.DocumentSessionFactory.Current.SaveChanges(); }
public void Save_NullSaga_Throws() { // arrange // act Action action = () => _persister.Save(null); // assert action.ShouldThrow <ArgumentNullException>() .WithMessage("*saga*"); }
private async Task <List <TestSagaData> > Prefill(IDocumentStore store, ConventionType seedType) { var snooper = StoreSnooper.Install(store); Console.WriteLine($"Filling database with saga data, using {seedType} conventions"); var names = new Dictionary <ConventionType, string> { { ConventionType.RavenDefault, "TestSagaDatas" }, { ConventionType.NSBDefault, "TestSaga" }, { ConventionType.Customer, "ataDagaStseT" } }; var name = names[seedType]; var sagas = Enumerable.Range(1001, 10) .Select(orderId => new TestSagaData { Id = Guid.NewGuid(), OrderId = orderId, OriginalMessageId = Guid.NewGuid().ToString(), Originator = "SomeSaga", Counter = 1 }) .ToList(); foreach (var saga in sagas) { snooper.Clear(); var persister = new SagaPersister(); Console.WriteLine($"Storing SagaId {saga.Id}"); using (var session = store.OpenAsyncSession()) { await persister.Save(saga, new SagaCorrelationProperty("OrderId", saga.OrderId), new RavenDBSynchronizedStorageSession(session, false), null); await session.SaveChangesAsync(); } var keysStored = snooper.KeysStored.ToList(); foreach (var key in keysStored) { Console.WriteLine($" * Document created: {key}"); } Assert.AreEqual(2, snooper.KeyCount); Assert.Contains($"{name}/{saga.Id}", keysStored); } return(sagas); }
public override void SetupContext() { base.SetupContext(); entity = new TestSaga { Id = Guid.NewGuid() }; entity.Status = StatusEnum.AnotherStatus; SagaPersister.Save(entity); savedEntity = SagaPersister.Get <TestSaga>(entity.Id); }
public async Task It_should_enforce_uniqueness() { var persister = new SagaPersister(new SagaPersistenceConfiguration()); var uniqueString = Guid.NewGuid().ToString(); using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session, new ContextBag()); await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); } var exception = await Catch <ConcurrencyException>(async cancellationToken => { using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var saga2 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session, new ContextBag()); await persister.Save(saga2, this.CreateMetadata <SomeSaga>(saga2), synchronizedSession, options, cancellationToken); await session.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } }); Assert.IsNotNull(exception); }
public override void SetupContext() { base.SetupContext(); entity = new TestSaga { Id = Guid.NewGuid() }; entity.DateTimeProperty = DateTime.Parse("12/02/2010 12:00:00.01").ToUniversalTime(); SagaPersister.Save(entity); savedEntity = SagaPersister.Get <TestSaga>(entity.Id); }
public void SetUp() { Saga1 = new SagaEntityWithUniqueProperty { Id = Guid.NewGuid(), OriginalMessageId = "original message id for saga1", Originator = "[email protected]", ThisShouldBeUnique = UNIQUE_VALUE_ONE }; SagaPersister.Save(Saga1); SagaPersister.DocumentSessionFactory.Current.SaveChanges(); }
public void Should_not_generate_a_to_long_unique_property_id() { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var saga = new SagaWithUniquePropertyAndALongNamespace { Id = Guid.NewGuid(), UniqueString = uniqueString }; persister.Save(saga); factory.SaveChanges(); }
public async Task It_should_persist_successfully() { var saga1Id = Guid.NewGuid(); var uniqueString = Guid.NewGuid().ToString(); using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var persister = new SagaPersister(new SagaPersistenceConfiguration()); var saga1 = new SagaData { Id = saga1Id, UniqueString = uniqueString }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session, options); await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); } using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var persister = new SagaPersister(new SagaPersistenceConfiguration()); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, options); var saga = await persister.Get <SagaData>(saga1Id, synchronizedSession, options); await persister.Complete(saga, synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); } using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var persister = new SagaPersister(new SagaPersistenceConfiguration()); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, options); var saga2 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; await persister.Save(saga2, this.CreateMetadata <SomeSaga>(saga2), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); } }
public async Task It_should_enforce_uniqueness() { IAsyncDocumentSession session; var options = this.CreateContextWithAsyncSessionPresent(out session); var persister = new SagaPersister(); var uniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; var synchronizedSession = new RavenDBSynchronizedStorageSession(session); await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); session.Dispose(); var exception = await Catch <ConcurrencyException>(async() => { options = this.CreateContextWithAsyncSessionPresent(out session); synchronizedSession = new RavenDBSynchronizedStorageSession(session); var saga2 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString }; await persister.Save(saga2, this.CreateMetadata <SomeSaga>(saga2), synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); }); Assert.IsNotNull(exception); }
public void Error_should_rollback_nhibernate_transaction() { UnitOfWork.Begin(); SagaPersister.Save(new TestSaga { Id = Guid.NewGuid() }); UnitOfWork.End(new Exception()); using (var session = SessionFactory.OpenSession()) { Assert.AreEqual(session.CreateCriteria(typeof(TestSaga)).List <TestSaga>().Count, 0); } }
public override void SetupContext() { base.SetupContext(); entity = new TestSaga { Id = Guid.NewGuid() }; entity.TestComponent = new TestComponent { Property = "Prop" }; SagaPersister.Save(entity); savedEntity = SagaPersister.Get <TestSaga>(entity.Id); }
public override void SetupContext() { base.SetupContext(); entity = new TestSaga { Id = Guid.NewGuid() }; entity.PolymorpicRelatedProperty = new PolymorpicProperty { SomeInt = 9 }; SagaPersister.Save(entity); savedEntity = SagaPersister.Get <TestSaga>(entity.Id); }
public void Enums_should_be_persisted() { var entity = new SagaData { Id = Guid.NewGuid(), Status = StatusEnum.AnotherStatus }; var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); persister.Save(entity); factory.SaveChanges(); var savedEntity = persister.Get<SagaData>(entity.Id); Assert.AreEqual(entity.Status, savedEntity.Status); }
public void Public_setters_and_getters_of_concrete_classes_should_be_persisted() { var entity = new SagaData { Id = Guid.NewGuid(), TestComponent = new TestComponent { Property = "Prop" } }; var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); persister.Save(entity); factory.SaveChanges(); var savedEntity = persister.Get<SagaData>(entity.Id); Assert.AreEqual(entity.TestComponent.Property, savedEntity.TestComponent.Property); Assert.AreEqual(entity.TestComponent.AnotherProperty, savedEntity.TestComponent.AnotherProperty); }
public void Should_delete_the_saga() { var sagaId = Guid.NewGuid(); var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); persister.Save(new SagaData { Id = sagaId }); factory.SaveChanges(); var saga = persister.Get<SagaData>(sagaId); persister.Complete(saga); factory.SaveChanges(); Assert.Null(persister.Get<SagaData>(sagaId)); }
public void Inherited_property_classes_should_be_persisted() { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var entity = new SagaData { Id = Guid.NewGuid(), PolymorphicRelatedProperty = new PolymorphicProperty { SomeInt = 9 } }; persister.Save(entity); factory.SaveChanges(); var savedEntity = persister.Get<SagaData>(entity.Id); var expected = (PolymorphicProperty)entity.PolymorphicRelatedProperty; var actual = (PolymorphicProperty)savedEntity.PolymorphicRelatedProperty; Assert.AreEqual(expected.SomeInt, actual.SomeInt); }
public void It_should_set_the_attribute_and_allow_the_update() { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var anotherUniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString, NonUniqueString = "notUnique" }; persister.Save(saga1); factory.SaveChanges(); factory.ReleaseSession(); using (var session = store.OpenSession()) { //fake that the attribute was just added by removing the metadata session.Advanced.GetMetadataFor(saga1).Remove(SagaPersister.UniqueValueMetadataKey); session.SaveChanges(); } var saga = persister.Get<SagaData>(saga1.Id); saga.UniqueString = anotherUniqueString; persister.Update(saga); factory.SaveChanges(); factory.ReleaseSession(); using (var session = store.OpenSession()) { var value = session.Advanced.GetMetadataFor(saga1)[SagaPersister.UniqueValueMetadataKey].ToString(); Assert.AreEqual(anotherUniqueString, value); } }
public void It_should_persist_successfully() { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); var uniqueString = Guid.NewGuid().ToString(); var anotherUniqueString = Guid.NewGuid().ToString(); var saga1 = new SagaData { Id = Guid.NewGuid(), UniqueString = uniqueString, NonUniqueString = "notUnique" }; persister.Save(saga1); factory.SaveChanges(); var saga = persister.Get<SagaData>(saga1.Id); saga.NonUniqueString = "notUnique2"; saga.UniqueString = anotherUniqueString; persister.Update(saga); factory.SaveChanges(); }
private async Task<List<TestSagaData>> Prefill(IDocumentStore store, ConventionType seedType) { var snooper = StoreSnooper.Install(store); Console.WriteLine($"Filling database with saga data, using {seedType} conventions"); var names = new Dictionary<ConventionType, string> { {ConventionType.RavenDefault, "TestSagaDatas"}, {ConventionType.NSBDefault, "TestSaga"}, {ConventionType.Customer, "ataDagaStseT"} }; var name = names[seedType]; var sagas = Enumerable.Range(1001, 10) .Select(orderId => new TestSagaData { Id = Guid.NewGuid(), OrderId = orderId, OriginalMessageId = Guid.NewGuid().ToString(), Originator = "SomeSaga", Counter = 1 }) .ToList(); foreach (var saga in sagas) { snooper.Clear(); var persister = new SagaPersister(); Console.WriteLine($"Storing SagaId {saga.Id}"); using (var session = store.OpenAsyncSession()) { await persister.Save(saga, new SagaCorrelationProperty("OrderId", saga.OrderId), new RavenDBSynchronizedStorageSession(session, false), null); await session.SaveChangesAsync(); } var keysStored = snooper.KeysStored.ToList(); foreach (var key in keysStored) { Console.WriteLine($" * Document created: {key}"); } Assert.AreEqual(2, snooper.KeyCount); Assert.Contains($"{name}/{saga.Id}", keysStored); } return sagas; }