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 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 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 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 SavingSagaWithoutDocumentVersionShouldThrowException(
     MongoSagaPersister sut,
     MongoDatabaseFactory factory,
     SagaWithoutDocumentVersion sagaData)
 {
     sut.Invoking(s => s.Save(sagaData)).ShouldThrow<InvalidOperationException>();
 }
        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>();
        }