static void CreateLegacySagaDocuments(IDocumentStore store, string unique) { var sagaId = Guid.NewGuid(); var saga = new SagaWithUniqueProperty { Id = sagaId, UniqueString = unique }; var sagaDocId = $"SagaWithUniqueProperty/{sagaId}"; var typeName = Regex.Replace(typeof(SagaWithUniqueProperty).AssemblyQualifiedName, ", Version=.*", ""); DirectStore(store, sagaDocId, saga, "SagaWithUniqueProperty", typeName, unique); var uniqueIdentity = new SagaUniqueIdentity { Id = SagaUniqueIdentity.FormatId(typeof(SagaWithUniqueProperty), "UniqueString", unique), SagaId = sagaId, SagaDocId = sagaDocId, UniqueValue = unique }; DirectStore(store, uniqueIdentity.Id, uniqueIdentity, "SagaUniqueIdentity", "NServiceBus.Persistence.Raven.SagaPersister.SagaUniqueIdentity, NServiceBus.Core"); }
public void InterleavedSavingSagaShouldThrowException( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData) { sut.Save(sagaData); sut.Invoking(s => s.Save(sagaData)).ShouldThrow <MongoDuplicateKeyException>(); }
public void SavingSagaWithNullUniquePropertyShouldThrowException( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData) { sagaData.UniqueProperty = null; sut.Invoking(s => s.Save(sagaData)).ShouldThrow <ArgumentNullException>(); }
public void It_should_persist_successfully() { var saga1 = new SagaWithUniqueProperty { Id = Guid.NewGuid(), UniqueString = "whatever"}; var inMemorySagaPersister = new InMemorySagaPersister() as ISagaPersister; inMemorySagaPersister.Save(saga1); saga1 = inMemorySagaPersister.Get<SagaWithUniqueProperty>(saga1.Id); inMemorySagaPersister.Update(saga1); }
public void RetrievingSagaUsingIdNotFound( MongoSagaPersister sut, SagaWithUniqueProperty sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { sut.Get <SagaWithUniqueProperty>(sagaData.Id, session, context).Result.Should().BeNull(); }
public void UpdatingNonExistantSagaWithUniqueProperty( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData) { sut.Invoking(s => s.Update(sagaData)).ShouldThrow <InvalidOperationException>(); factory.RetrieveSagaData(sagaData).Should().BeNull(); }
public void RetrievingSagaUsingStringUniqueId( MongoSagaPersister sut, SagaWithUniqueProperty sagaData) { sut.Save(sagaData); var result = sut.Get <SagaWithUniqueProperty>("UniqueProperty", sagaData.UniqueProperty); result.ShouldBeEquivalentTo(sagaData); }
public void UpdatingSagaWithoutDocumentVersion( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { sut.Invoking(s => s.Update(sagaData, session, context).Wait()).ShouldThrow <InvalidOperationException>(); }
public void InterleavedSavingSagaShouldThrowException( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { sut.Save(sagaData, correlationProperty, session, context).Wait(); sut.Invoking(s => s.Save(sagaData, correlationProperty, session, context).Wait()) .ShouldThrow <MongoWriteException>(); }
public void UpdatingNonExistantSagaWithUniqueProperty( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { sut.Invoking(s => s.Update(sagaData, session, context).Wait()).ShouldThrow <InvalidOperationException>(); factory.RetrieveSagaData(sagaData).Should().BeNull(); }
public void SavingSagaWithUniqueProperty( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData) { sut.Save(sagaData); var entity = factory.RetrieveSagaData(sagaData); entity.Id.Should().Be(sagaData.Id); entity.UniqueProperty.Should().Be(sagaData.UniqueProperty); entity.NonUniqueProperty.Should().Be(sagaData.NonUniqueProperty); }
public void RetrievingSagaUsingId( MongoSagaPersister sut, SagaWithUniqueProperty sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { sut.Save(sagaData, correlationProperty, session, context).Wait(); var result = sut.Get <SagaWithUniqueProperty>(sagaData.Id, session, context).Result; result.ShouldBeEquivalentTo(sagaData); }
public void CompletingSagaShouldRemoveDocument( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { sut.Save(sagaData, correlationProperty, session, context).Wait(); sut.Complete(sagaData, session, context).Wait(); factory.RetrieveSagaData(sagaData).Should().BeNull(); }
public async Task Improperly_converted_saga_can_be_fixed() { var sagaId = Guid.NewGuid(); var sagaDocId = $"SagaWithUniqueProperty/{sagaId}"; var uniqueString = "abcd"; var identityDocId = SagaUniqueIdentity.FormatId(typeof(SagaWithUniqueProperty), "UniqueString", uniqueString); var sagaData = new SagaWithUniqueProperty { Id = Guid.Empty, // Improperly converted UniqueString = uniqueString }; var sagaContainer = new SagaDataContainer { Id = sagaDocId, Data = sagaData, IdentityDocId = identityDocId }; var uniqueIdentity = new SagaUniqueIdentity { Id = SagaUniqueIdentity.FormatId(typeof(SagaWithUniqueProperty), "UniqueString", uniqueString), SagaId = sagaId, SagaDocId = sagaDocId, UniqueValue = uniqueString }; using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var _)) { await session.StoreAsync(sagaContainer); await session.StoreAsync(uniqueIdentity); await session.SaveChangesAsync(); } using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options)) { var persister = new SagaPersister(new SagaPersistenceConfiguration()); var synchronizedSession = new RavenDBSynchronizedStorageSession(session, options); var loadedSaga = await persister.Get <SagaWithUniqueProperty>("UniqueString", uniqueString, synchronizedSession, options); Assert.IsNotNull(loadedSaga, "Saga is null"); Assert.AreNotEqual(Guid.Empty, loadedSaga.Id, "Id is Guid.Empty"); Assert.AreEqual(sagaId, loadedSaga.Id, "Saga Id is not the correct value."); } }
public void SavingDifferentSagaWithSameUniquePropertyShouldThrowDuplicateException( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData1, SagaWithUniqueProperty sagaData2) { var uniqueProperty = Guid.NewGuid().ToString(); sagaData1.UniqueProperty = uniqueProperty; sagaData2.UniqueProperty = uniqueProperty; sut.Save(sagaData1); sut.Invoking(s => s.Save(sagaData2)).ShouldThrow <MongoDuplicateKeyException>(); }
public void UpdateCollisionShouldFail( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData) { sut.Save(sagaData); var saga1 = factory.RetrieveSagaData(sagaData); var saga2 = factory.RetrieveSagaData(sagaData); saga1.UniqueProperty = Guid.NewGuid().ToString(); sut.Update(saga1); saga2.UniqueProperty = Guid.NewGuid().ToString(); sut.Invoking(s => s.Update(saga2)).ShouldThrow <InvalidOperationException>(); }
public void UpdatingSagaWithUniqueProperty( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData, string newValue) { sut.Save(sagaData); sagaData.NonUniqueProperty = newValue; sut.Update(sagaData); var entity = factory.RetrieveSagaData(sagaData); entity.NonUniqueProperty.Should().Be(newValue); }
public void should_throw_a_ArgumentNullException() { using (var store = DocumentStoreBuilder.Build()) { var saga1 = new SagaWithUniqueProperty { Id = Guid.NewGuid(), UniqueString = null }; var factory = new RavenSessionFactory(store); var persister = new SagaPersister(factory); persister.Save(saga1); factory.SaveChanges(); } }
public void SavingSagaWithUniqueProperty( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { sut.Save(sagaData, correlationProperty, session, context).Wait(); var entity = factory.RetrieveSagaData(sagaData); entity.Id.Should().Be(sagaData.Id); entity.UniqueProperty.Should().Be(sagaData.UniqueProperty); entity.SomeValue.Should().Be(sagaData.SomeValue); }
public void It_should_persist_successfully() { var saga1 = new SagaWithUniqueProperty {Id = Guid.NewGuid(), UniqueString = "whatever1"}; var saga2 = new SagaWithUniqueProperty {Id = Guid.NewGuid(), UniqueString = "whatever"}; var inMemorySagaPersister = new InMemorySagaPersister() as ISagaPersister; inMemorySagaPersister.Save(saga1); inMemorySagaPersister.Save(saga2); Assert.Throws<InvalidOperationException>(() => { var saga = inMemorySagaPersister.Get<SagaWithUniqueProperty>(saga2.Id); saga.UniqueString = "whatever1"; inMemorySagaPersister.Update(saga); }); }
public void UpdatingSagaWithNoChangesShouldNotUpdateVersion( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { sut.Save(sagaData, correlationProperty, session, context).Wait(); var saga1 = factory.RetrieveSagaData(sagaData); sut.Update(saga1, session, context).Wait(); var saga2 = factory.RetrieveSagaData(sagaData); saga2.DocumentVersion.Should().Be(saga1.DocumentVersion); }
public void UpdateCollisionShouldFail( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { sut.Save(sagaData, correlationProperty, session, context).Wait(); var saga1 = factory.RetrieveSagaData(sagaData); var saga2 = factory.RetrieveSagaData(sagaData); saga1.UniqueProperty = Guid.NewGuid().ToString(); sut.Update(saga1, session, context).Wait(); saga2.UniqueProperty = Guid.NewGuid().ToString(); sut.Invoking(s => s.Update(saga2, session, context).Wait()).ShouldThrow <InvalidOperationException>(); }
public void SavingSagaWithSameUniquePropertyAsAnAlreadyCompletedSaga( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData1, SagaWithUniqueProperty sagaData2) { var uniqueProperty = Guid.NewGuid().ToString(); sagaData1.UniqueProperty = uniqueProperty; sagaData2.UniqueProperty = uniqueProperty; sut.Save(sagaData1); sut.Complete(sagaData1); sut.Save(sagaData2); var entity = factory.RetrieveSagaData(sagaData2); entity.UniqueProperty.Should().Be(sagaData2.UniqueProperty); entity.NonUniqueProperty.Should().Be(sagaData2.NonUniqueProperty); }
public void SavingSagaWithSameUniquePropertyAsAnAlreadyCompletedSaga( MongoSagaPersister sut, MongoDatabaseFactory factory, SagaWithUniqueProperty sagaData1, SagaWithUniqueProperty sagaData2, SagaCorrelationProperty correlationProperty, SynchronizedStorageSession session, ContextBag context) { var uniqueProperty = Guid.NewGuid().ToString(); sagaData1.UniqueProperty = uniqueProperty; sagaData2.UniqueProperty = uniqueProperty; sut.Save(sagaData1, correlationProperty, session, context).Wait(); sut.Complete(sagaData1, session, context).Wait(); sut.Save(sagaData2, correlationProperty, session, context).Wait(); var entity = factory.RetrieveSagaData(sagaData2); entity.UniqueProperty.Should().Be(sagaData2.UniqueProperty); entity.SomeValue.Should().Be(sagaData2.SomeValue); }
static void CreateLegacySagaDocuments(IDocumentStore store, string unique) { var sagaId = Guid.NewGuid(); var saga = new SagaWithUniqueProperty { Id = sagaId, UniqueString = unique }; var sagaDocId = $"SagaWithUniqueProperty/{sagaId}"; DirectStore(store, sagaDocId, saga, "SagaWithUniqueProperty", ReflectionUtil.GetFullNameWithoutVersionInformation(typeof(SagaWithUniqueProperty)), unique); var uniqueIdentity = new SagaUniqueIdentity { Id = SagaUniqueIdentity.FormatId(typeof(SagaWithUniqueProperty), "UniqueString", unique), SagaId = sagaId, SagaDocId = sagaDocId, UniqueValue = unique }; DirectStore(store, uniqueIdentity.Id, uniqueIdentity, "SagaUniqueIdentity", "NServiceBus.Persistence.Raven.SagaPersister.SagaUniqueIdentity, NServiceBus.Core"); }
public void BaseSagaUpdateQuery(SagaWithUniqueProperty saga) { var query = saga.MongoUpdateQuery(); query.ToString().Should().Contain("DocumentVersion"); }