public void SaveSagaData(
     MongoSagaPersister sut,
     MongoDatabaseFactory factory,
     DeviceCommandSagaState state)
 {
     sut.Save(state);
 }
 public void SaveSagaData(
     MongoSagaPersister sut,
     MongoDatabaseFactory factory,
     DeviceCommandSagaState state)
 {
     sut.Save(state);
 }
 public void SavingSagaWithNullUniquePropertyShouldThrowException(
     MongoSagaPersister sut,
     MongoDatabaseFactory factory,
     SagaWithUniqueProperty sagaData)
 {
     sagaData.UniqueProperty = null;
     sut.Invoking(s => s.Save(sagaData)).ShouldThrow<ArgumentNullException>();
 }
 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 SaveSagaData(
            MongoSagaPersister sut,
            DeviceCommandSagaState state,
            SynchronizedStorageSession session,
            ContextBag context)
        {
            var correlationProperty = new SagaCorrelationProperty("SagaKey", state.SagaKey);

            sut.Save(state, correlationProperty, session, context).Wait();
        }
 public void RetrievingSagaUsingCorrelationPropertyNotFound(
     MongoSagaPersister sut,
     SagaCorrelationProperty correlationProperty,
     SynchronizedStorageSession session,
     ContextBag context)
 {
     sut.Get <SagaWithUniqueProperty>(correlationProperty.Name, "badvalue", session, context)
     .Result.Should()
     .BeNull();
 }
 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 SavingSagaWithoutUniqueProperty(
            MongoSagaPersister sut,
            MongoDatabaseFactory factory,
            SagaWithoutUniqueProperties sagaData)
        {
            sut.Save(sagaData);

            var entity = factory.RetrieveSagaData(sagaData);

            entity.Id.Should().Be(sagaData.Id);
            entity.NonUniqueProperty.Should().Be(sagaData.NonUniqueProperty);
        }
        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 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();
        }
Exemple #13
0
        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 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 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,
            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);
        }
        public void BasicMongoSagaPersisterConstruction(MongoDatabaseFactory factory)
        {
            var sut = new MongoSagaPersister(factory);

            sut.Should().NotBeNull();
        }
 public void BasicMongoSagaPersisterConstruction(MongoDatabaseFactory factory)
 {
     var sut = new MongoSagaPersister(factory);
 }
        public void RetrievingSagaUsingStringUniqueId(
            MongoSagaPersister sut,
            SagaWithUniqueProperty sagaData)
        {
            sut.Save(sagaData);

            var result = sut.Get<SagaWithUniqueProperty>("UniqueProperty", sagaData.UniqueProperty);

            result.ShouldBeEquivalentTo(sagaData);
        }
        public void RetrievingSagaUsingGuidUniqueId(
            MongoSagaPersister sut,
            SagaWithUniqueGuidProperty sagaData)
        {
            sut.Save(sagaData);

            var result = sut.Get<SagaWithUniqueGuidProperty>("SomeId", sagaData.SomeId);

            result.ShouldBeEquivalentTo(sagaData);
        }
        public void RetrievingSagaUsingId(
            MongoSagaPersister sut,
            SagaWithoutUniqueProperties sagaData)
        {
            sut.Save(sagaData);

            var result = sut.Get<SagaWithoutUniqueProperties>(sagaData.Id);

            result.ShouldBeEquivalentTo(sagaData);
        }
 public void UpdatingSagaWithoutDocumentVersion(
     MongoSagaPersister sut,
     MongoDatabaseFactory factory,
     SagaWithoutUniqueProperties sagaData)
 {
     sut.Invoking(s => s.Update(sagaData)).ShouldThrow<InvalidOperationException>();
 }
        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 UpdatingNonExistantSagaWithUniqueProperty(
            MongoSagaPersister sut,
            MongoDatabaseFactory factory,
            SagaWithUniqueProperty sagaData)
        {
            sut.Invoking(s => s.Update(sagaData)).ShouldThrow<InvalidOperationException>();

            factory.RetrieveSagaData(sagaData).Should().BeNull();
        }
        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 SavingSagaWithoutDocumentVersionShouldThrowException(
     MongoSagaPersister sut,
     MongoDatabaseFactory factory,
     SagaWithoutDocumentVersion sagaData)
 {
     sut.Invoking(s => s.Save(sagaData)).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 InterleavedSavingSagaShouldThrowException(
     MongoSagaPersister sut,
     MongoDatabaseFactory factory,
     SagaWithUniqueProperty sagaData)
 {
     sut.Save(sagaData);
     sut.Invoking(s => s.Save(sagaData)).ShouldThrow<MongoDuplicateKeyException>();
 }
        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 CompletingSagaShouldRemoveDocument(
            MongoSagaPersister sut,
            MongoDatabaseFactory factory,
            SagaWithoutUniqueProperties sagaData)
        {
            sut.Save(sagaData);

            sut.Complete(sagaData);
            factory.RetrieveSagaData(sagaData).Should().BeNull();
        }