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 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 When_a_duplicate_messages_starting_a_saga_arrive_sequentially_one_of_them_fails() { var context = CreateMessageContext(); var sagaData = CreateNewSagaData(); var transaction1 = await outboxPersister.BeginTransaction(context); var session1 = new OutboxEventStoreSynchronizedStorageSession(connection, (EventStoreOutboxTransaction)transaction1); await persister.Save(sagaData, new SagaCorrelationProperty(CorrelationPropName, sagaData.StringProperty), session1, context); await transaction1.Commit(); var transaction2 = await outboxPersister.BeginTransaction(context); var session2 = new OutboxEventStoreSynchronizedStorageSession(connection, (EventStoreOutboxTransaction)transaction2); var loadedData = await persister.Get <SagaData>(CorrelationPropName, sagaData.StringProperty, session2, context); await persister.Update(loadedData, session2, context); try { await transaction2.Commit(); Assert.Fail("Expected exception"); } catch (Exception ex) { StringAssert.StartsWith("Append failed due to WrongExpectedVersion.", ex.Message); } }
public void Get_EmptyId_Throws() { // arrange // act Action action = () => _persister.Get <TestSagaDataWithRowVersion>(Guid.Empty); // assert action.ShouldThrow <ArgumentException>() .WithMessage("*sagaId*"); }
public async Task TestRetrievingSagas(ConventionType seedType) { using (var db = new ReusableDB()) { List <TestSagaData> sagas; using (var store = db.NewStore()) { ApplyPrefillConventions(store, seedType); store.Initialize(); sagas = await Prefill(store, seedType); } // Need to ensure multiple runs will work, after conventions document is stored for (var i = 0; i < 3; i++) { using (var store = db.NewStore()) { Console.WriteLine($"Testing saga lookups with DocumentStore initially configured for {seedType} conventions."); ApplyTestConventions(store, seedType); store.Initialize(); foreach (var saga in sagas) { var persister = new SagaPersister(); Console.WriteLine($"Retrieving SagaId {saga.Id} by SagaId"); TestSagaData byId; using (var session = store.OpenAsyncSession()) { byId = await persister.Get <TestSagaData>(saga.Id, new RavenDBSynchronizedStorageSession(session, false), null); } Assert.IsNotNull(byId); Assert.AreEqual(byId.Id, saga.Id); Assert.AreEqual(byId.OrderId, saga.OrderId); Assert.AreEqual(byId.OriginalMessageId, saga.OriginalMessageId); Assert.AreEqual(byId.Originator, saga.Originator); Assert.AreEqual(1, saga.Counter); Console.WriteLine($"Retrieving SagaId {saga.Id} by Correlation Property OrderId={saga.OrderId}"); using (var session = store.OpenAsyncSession()) { byId = await persister.Get <TestSagaData>("OrderId", saga.OrderId, new RavenDBSynchronizedStorageSession(session, false), new ContextBag()); } Assert.IsNotNull(byId); Assert.AreEqual(byId.Id, saga.Id); Assert.AreEqual(byId.OrderId, saga.OrderId); Assert.AreEqual(byId.OriginalMessageId, saga.OriginalMessageId); Assert.AreEqual(byId.Originator, saga.Originator); Assert.AreEqual(1, saga.Counter); } } } } }
public async Task TestRetrievingSagas(ConventionType seedType) { using (var db = new ReusableDB()) { List<TestSagaData> sagas; using (var store = db.NewStore()) { ApplyPrefillConventions(store, seedType); store.Initialize(); sagas = await Prefill(store, seedType); } // Need to ensure multiple runs will work, after conventions document is stored for (var i = 0; i < 3; i++) { using (var store = db.NewStore()) { Console.WriteLine($"Testing saga lookups with DocumentStore initially configured for {seedType} conventions."); ApplyTestConventions(store, seedType); store.Initialize(); foreach (var saga in sagas) { var persister = new SagaPersister(); Console.WriteLine($"Retrieving SagaId {saga.Id} by SagaId"); TestSagaData byId; using (var session = store.OpenAsyncSession()) { byId = await persister.Get<TestSagaData>(saga.Id, new RavenDBSynchronizedStorageSession(session, false), null); } Assert.IsNotNull(byId); Assert.AreEqual(byId.Id, saga.Id); Assert.AreEqual(byId.OrderId, saga.OrderId); Assert.AreEqual(byId.OriginalMessageId, saga.OriginalMessageId); Assert.AreEqual(byId.Originator, saga.Originator); Assert.AreEqual(1, saga.Counter); Console.WriteLine($"Retrieving SagaId {saga.Id} by Correlation Property OrderId={saga.OrderId}"); using (var session = store.OpenAsyncSession()) { byId = await persister.Get<TestSagaData>("OrderId", saga.OrderId, new RavenDBSynchronizedStorageSession(session, false), new ContextBag()); } Assert.IsNotNull(byId); Assert.AreEqual(byId.Id, saga.Id); Assert.AreEqual(byId.OrderId, saga.OrderId); Assert.AreEqual(byId.OriginalMessageId, saga.OriginalMessageId); Assert.AreEqual(byId.Originator, saga.Originator); Assert.AreEqual(1, saga.Counter); } } } } }
public async Task When_a_duplicate_messages_starting_a_saga_arrive_sequentially_both_succeed() { var context = CreateMessageContext(); var sagaData = CreateNewSagaData(); var session1 = new EventStoreSynchronizedStorageSession(connection); await persister.Save(sagaData, new SagaCorrelationProperty(CorrelationPropName, sagaData.StringProperty), session1, context); var session2 = new EventStoreSynchronizedStorageSession(connection); var loadedData = await persister.Get <SagaData>(CorrelationPropName, sagaData.StringProperty, session2, context); await persister.Update(loadedData, session2, context); }
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 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() { 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 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 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 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 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 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 async Task TestMarkingAsComplete(ConventionType seedType) { using (var db = new ReusableDB()) { List <TestSagaData> sagas; using (var store = db.NewStore()) { ApplyPrefillConventions(store, seedType); store.Initialize(); sagas = await Prefill(store, seedType); } using (var store = db.NewStore()) { Console.WriteLine($"Testing saga lookups with DocumentStore initially configured for {seedType} conventions."); ApplyTestConventions(store, seedType); store.Initialize(); // Update each saga, once by id and once by correlation property foreach (var saga in sagas) { var persister = new SagaPersister(); using (var session = store.OpenAsyncSession()) { Console.WriteLine($"Retrieving SagaId {saga.Id} by Correlation Property OrderId={saga.OrderId} and completing."); var ravenDBSynchronizedStorageSession = new RavenDBSynchronizedStorageSession(session, false); var contextBag = new ContextBag(); var byOrderId = await persister.Get <TestSagaData>("OrderId", saga.OrderId, ravenDBSynchronizedStorageSession, contextBag); Assert.IsNotNull(byOrderId); await persister.Complete(byOrderId, ravenDBSynchronizedStorageSession, contextBag); await session.SaveChangesAsync(); } } db.WaitForIndexing(store); // Ensure terms are still the saga type and unique identity type var terms = store.DatabaseCommands.GetTerms("Raven/DocumentsByEntityName", "Tag", null, 1024).ToList(); Assert.AreEqual(2, terms.Count); foreach (var term in terms) { var query = new IndexQuery { Query = "Tag:" + term, PageSize = 0 }; // Ensure there are none left var queryResult = store.DatabaseCommands.Query("Raven/DocumentsByEntityName", query); Assert.AreEqual(0, queryResult.TotalResults); } } } }
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 void an_sagaEntity_by_property_value() { var loadedSagaA = SagaPersister.Get <SagaEntityA>("SomeIdentifier", IDENTIFIER); var loadedSagaB = SagaPersister.Get <SagaEntityB>("SomeIdentifier", IDENTIFIER); Assert.That(loadedSagaA.Id, Is.EqualTo(_sagaEntityA.Id)); Assert.That(loadedSagaB.Id, Is.EqualTo(_sagaEntityB.Id)); }
public async Task It_should_return_null() { IAsyncDocumentSession session; var options = this.CreateContextWithAsyncSessionPresent(out session); var persister = new SagaPersister(); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, true); Assert.Null(await persister.Get <SagaData>("UniqueString", Guid.NewGuid().ToString(), synchronizedSession, options)); }
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 async Task It_should_return_null() { using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var persister = new SagaPersister(new SagaPersistenceConfiguration()); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, new ContextBag()); Assert.Null(await persister.Get <SagaData>("UniqueString", Guid.NewGuid().ToString(), synchronizedSession, options)); } }
/// <summary> /// Uses the saga persister to find the saga. /// </summary> /// <param name="message"></param> /// <returns></returns> public TSaga FindBy(TMessage message) { if (SagaPersister == null) { throw new InvalidOperationException( "No saga persister configured. Please configure a saga persister if you want to use the nservicebus saga support"); } return(SagaPersister.Get <TSaga>(SagaProperty.Name, MessageProperty.GetValue(message, null))); }
public void It_should_return_null() { using (var store = DocumentStoreBuilder.Build()) { var factory = new RavenSessionFactory(store); factory.ReleaseSession(); var persister = new SagaPersister(factory); Assert.Null(persister.Get <SagaData>("UniqueString", Guid.NewGuid().ToString())); } }
Task <CountingSagaData> GetSagaDataById(Guid sagaId) { using (var session = this.OpenAsyncSession()) { var persister = new SagaPersister(); var context = new ContextBag(); context.Set(session); var synchronizedSession = new RavenDBSynchronizedStorageSession(session); return(persister.Get <CountingSagaData>(sagaId, synchronizedSession, context)); } }
public void an_sagaEntity() { ((SagaEntityA)_sagaEntityA).SomeIdentifier = A_NEW_VALUE; SagaPersister.Update(_sagaEntityA); SagaPersister.DocumentSessionFactory.Current.SaveChanges(); var loadedUpdatedSagaEntity = SagaPersister.Get <SagaEntityA>(_sagaEntityA.Id); Assert.That(loadedUpdatedSagaEntity.Id, Is.EqualTo(_sagaEntityA.Id)); Assert.That(loadedUpdatedSagaEntity.SomeIdentifier, Is.EqualTo(A_NEW_VALUE)); }
public void Should_delete_the_saga() { var sagaId = Guid.NewGuid(); SaveSaga(new TestSaga { Id = sagaId }); CompleteSaga <TestSaga>(sagaId); Assert.Null(SagaPersister.Get <TestSaga>(sagaId)); }
Task <CountingSagaData> GetSagaDataByProperty() { using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency()) { var persister = new SagaPersister(); var context = new ContextBag(); context.Set(session); var synchronizedSession = new RavenDBSynchronizedStorageSession(session); return(persister.Get <CountingSagaData>("Name", "Alpha", synchronizedSession, context)); } }
public async Task It_should_load_successfully() { var unique = Guid.NewGuid().ToString(); CreateLegacySagaDocuments(store, unique); IAsyncDocumentSession session; var options = this.CreateContextWithAsyncSessionPresent(out session); var persister = new SagaPersister(); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, true); var saga = await persister.Get<SagaWithUniqueProperty>("UniqueString", unique, synchronizedSession, options); Assert.IsNotNull(saga, "Saga is null"); await persister.Complete(saga, synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); Assert.IsNull(await persister.Get<SagaWithUniqueProperty>("UniqueString", unique, synchronizedSession, options), "Saga was not completed"); }
public void Should_delete_the_saga() { using (var store = DocumentStoreBuilder.Build()) { 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 async Task It_should_load_successfully() { var unique = Guid.NewGuid().ToString(); CreateLegacySagaDocuments(store, unique); IAsyncDocumentSession session; var options = this.CreateContextWithAsyncSessionPresent(out session); var persister = new SagaPersister(); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, true); var saga = await persister.Get <SagaWithUniqueProperty>("UniqueString", unique, synchronizedSession, options); Assert.IsNotNull(saga, "Saga is null"); await persister.Complete(saga, synchronizedSession, options); await session.SaveChangesAsync().ConfigureAwait(false); Assert.IsNull(await persister.Get <SagaWithUniqueProperty>("UniqueString", unique, synchronizedSession, options), "Saga was not completed"); }
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 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(); }
public async Task TestStoringSagas(ConventionType seedType) { using (var db = new ReusableDB()) { List<TestSagaData> sagas; using (var store = db.NewStore()) { ApplyPrefillConventions(store, seedType); store.Initialize(); sagas = await Prefill(store, seedType); } using (var store = db.NewStore()) { Console.WriteLine($"Testing saga updates with DocumentStore initially configured for {seedType} conventions."); ApplyTestConventions(store, seedType); store.Initialize(); // Update each saga, once by id and once by correlation property foreach (var saga in sagas) { var persister = new SagaPersister(); Console.WriteLine($"Retrieving SagaId {saga.Id} by SagaId"); using (var session = store.OpenAsyncSession()) { var ravenDBSynchronizedStorageSession = new RavenDBSynchronizedStorageSession(session, false); var byId = await persister.Get<TestSagaData>(saga.Id, ravenDBSynchronizedStorageSession, null); Assert.IsNotNull(byId); byId.Counter++; await persister.Update(byId, ravenDBSynchronizedStorageSession, null); await session.SaveChangesAsync(); Console.WriteLine($"Retrieving SagaId {saga.Id} by Correlation Property OrderId={saga.OrderId}"); var byOrderId = await persister.Get<TestSagaData>("OrderId", saga.OrderId, ravenDBSynchronizedStorageSession, new ContextBag()); Assert.IsNotNull(byOrderId); byOrderId.Counter++; await persister.Update(byOrderId, ravenDBSynchronizedStorageSession, null); await session.SaveChangesAsync(); } } Console.WriteLine("Retrieving each saga again by SagaId and making sure Counter == 3"); foreach (var saga in sagas) { var persister = new SagaPersister(); using (var session = store.OpenAsyncSession()) { Console.WriteLine($"Retrieving SagaId {saga.Id} by SagaId"); var byId = await persister.Get<TestSagaData>(saga.Id, new RavenDBSynchronizedStorageSession(session, false), null); Assert.IsNotNull(byId); Assert.AreEqual(3, byId.Counter); } } } } }
public async Task TestMarkingAsComplete(ConventionType seedType) { using (var db = new ReusableDB()) { List<TestSagaData> sagas; using (var store = db.NewStore()) { ApplyPrefillConventions(store, seedType); store.Initialize(); sagas = await Prefill(store, seedType); } using (var store = db.NewStore()) { Console.WriteLine($"Testing saga lookups with DocumentStore initially configured for {seedType} conventions."); ApplyTestConventions(store, seedType); store.Initialize(); // Update each saga, once by id and once by correlation property foreach (var saga in sagas) { var persister = new SagaPersister(); using (var session = store.OpenAsyncSession()) { Console.WriteLine($"Retrieving SagaId {saga.Id} by Correlation Property OrderId={saga.OrderId} and completing."); var ravenDBSynchronizedStorageSession = new RavenDBSynchronizedStorageSession(session, false); var contextBag = new ContextBag(); var byOrderId = await persister.Get<TestSagaData>("OrderId", saga.OrderId, ravenDBSynchronizedStorageSession, contextBag); Assert.IsNotNull(byOrderId); await persister.Complete(byOrderId, ravenDBSynchronizedStorageSession, contextBag); await session.SaveChangesAsync(); } } db.WaitForIndexing(store); // Ensure terms are still the saga type and unique identity type var terms = store.DatabaseCommands.GetTerms("Raven/DocumentsByEntityName", "Tag", null, 1024).ToList(); Assert.AreEqual(2, terms.Count); foreach (var term in terms) { var query = new IndexQuery { Query = "Tag:" + term, PageSize = 0 }; // Ensure there are none left var queryResult = store.DatabaseCommands.Query("Raven/DocumentsByEntityName", query); Assert.AreEqual(0, queryResult.TotalResults); } } } }