Пример #1
0
        public async Task It_should_persist_successfully()
        {
            var saga1 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };
            var saga2 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };

            var persister = new InMemorySagaPersister();

            var firstInsertSession = new InMemorySynchronizedStorageSession();
            await persister.Save(saga1, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga1), firstInsertSession, new ContextBag());

            await firstInsertSession.CompleteAsync();

            var updateSession = new InMemorySynchronizedStorageSession();

            saga1 = await persister.Get <SagaWithUniquePropertyData>(saga1.Id, updateSession, new ContextBag());

            saga1.UniqueString = "whatever2";
            await persister.Update(saga1, updateSession, new ContextBag());

            await updateSession.CompleteAsync();

            var secondInsertSession = new InMemorySynchronizedStorageSession();
            await persister.Save(saga2, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga2), secondInsertSession, new ContextBag());

            await secondInsertSession.CompleteAsync();
        }
        public async Task Should_delete_the_saga()
        {
            var saga = new SagaWithUniquePropertyData {
                Id = Guid.NewGuid(), UniqueString = "whatever"
            };

            var persister     = new InMemorySagaPersister();
            var insertSession = new InMemorySynchronizedStorageSession();
            await persister.Save(saga, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga), insertSession, new ContextBag());

            await insertSession.CompleteAsync();

            var intentionallySharedContext = new ContextBag();
            var sagaData = await persister.Get <SagaWithUniquePropertyData>(saga.Id, new InMemorySynchronizedStorageSession(), intentionallySharedContext);

            var completeSession = new InMemorySynchronizedStorageSession();
            await persister.Complete(saga, completeSession, intentionallySharedContext);

            await completeSession.CompleteAsync();

            var completedSagaData = await persister.Get <SagaWithUniquePropertyData>(saga.Id, new InMemorySynchronizedStorageSession(), new ContextBag());

            Assert.NotNull(sagaData);
            Assert.Null(completedSagaData);
        }
        public async Task It_should_enforce_uniqueness()
        {
            var saga1 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };
            var saga2 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };

            var persister      = new InMemorySagaPersister();
            var winningSession = new InMemorySynchronizedStorageSession();
            var losingSession  = new InMemorySynchronizedStorageSession();

            await persister.Save(saga1, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga1), winningSession, new ContextBag());

            await persister.Save(saga2, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga1), losingSession, new ContextBag());

            await winningSession.CompleteAsync();

            Assert.That(async() => await losingSession.CompleteAsync(), Throws.InstanceOf <InvalidOperationException>());
        }
        async Task SaveSaga(SagaWithUniquePropertyData saga)
        {
            using (var session = new InMemorySynchronizedStorageSession())
            {
                var ctx = new ContextBag();
                await persister.Save(saga, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga), session, ctx);

                await session.CompleteAsync();
            }
        }
Пример #5
0
        public void Should_delete_the_saga()
        {
            var saga = new SagaWithUniquePropertyData {
                Id = Guid.NewGuid(), UniqueString = "whatever"
            };

            persister.Save(saga);
            Assert.NotNull(persister.Get <SagaWithUniquePropertyData>(saga.Id));
            persister.Complete(saga);
            Assert.Null(persister.Get <SagaWithUniquePropertyData>(saga.Id));
        }
        public void It_should_enforce_uniqueness()
        {
            var saga1 = new SagaWithUniquePropertyData {
                Id = Guid.NewGuid(), UniqueString = "whatever"
            };
            var saga2 = new SagaWithUniquePropertyData {
                Id = Guid.NewGuid(), UniqueString = "whatever"
            };

            persister.Save(saga1);
            Assert.Throws <InvalidOperationException>(() => persister.Save(saga2));
        }
Пример #7
0
        public void It_should_persist_successfully()
        {
            var saga1 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };

            persister.Save(saga1);
            saga1 = persister.Get <SagaWithUniquePropertyData>(saga1.Id);
            persister.Update(saga1);
        }
        public void It_should_persist_successfully()
        {
            var saga1 = new SagaWithUniquePropertyData {
                Id = Guid.NewGuid(), UniqueString = "whatever"
            };
            var saga2 = new SagaWithUniquePropertyData {
                Id = Guid.NewGuid(), UniqueString = "whatever"
            };


            persister.Save(saga1);
            persister.Complete(saga1);
            persister.Save(saga2);
            persister.Complete(saga2);
            persister.Save(saga1);
            persister.Complete(saga1);
        }
        public void  It_should_persist_successfully()
        {
            var saga1 = new SagaWithTwoUniquePropertiesData {
                Id = Guid.NewGuid(), UniqueString = "whatever", UniqueInt = 5
            };
            var saga2 = new AnotherSagaWithTwoUniquePropertiesData {
                Id = Guid.NewGuid(), UniqueString = "whatever", UniqueInt = 5
            };
            var saga3 = new SagaWithUniquePropertyData {
                Id = Guid.NewGuid(), UniqueString = "whatever"
            };



            persister.Save(saga1);
            persister.Save(saga2);
            persister.Save(saga3);
        }
Пример #10
0
        public void It_should_persist_successfully()
        {
            var saga1 = new SagaWithUniquePropertyData {
                Id = Guid.NewGuid(), UniqueString = "whatever1"
            };
            var saga2 = new SagaWithUniquePropertyData {
                Id = Guid.NewGuid(), UniqueString = "whatever"
            };

            persister.Save(saga1);
            persister.Save(saga2);

            Assert.Throws <InvalidOperationException>(() =>
            {
                var saga          = persister.Get <SagaWithUniquePropertyData>(saga2.Id);
                saga.UniqueString = "whatever1";
                persister.Update(saga);
            });
        }
Пример #11
0
        public async Task It_should_persist_successfully()
        {
            var saga1 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };
            var saga2 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };

            var persister = new InMemorySagaPersister();

            using (var session1 = new InMemorySynchronizedStorageSession())
            {
                await persister.Save(saga1, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga1), session1, new ContextBag());

                await persister.Complete(saga1, session1, new ContextBag());

                await session1.CompleteAsync();
            }

            using (var session2 = new InMemorySynchronizedStorageSession())
            {
                await persister.Save(saga2, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga2), session2, new ContextBag());

                await persister.Complete(saga2, session2, new ContextBag());

                await session2.CompleteAsync();
            }

            using (var session3 = new InMemorySynchronizedStorageSession())
            {
                await persister.Save(saga1, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga1), session3, new ContextBag());

                await persister.Complete(saga1, session3, new ContextBag());

                await session3.CompleteAsync();
            }
        }
Пример #12
0
        public async Task It_should_persist_successfully()
        {
            var saga1 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };
            var saga2 = new AnotherSagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };

            var persister   = new InMemorySagaPersister();
            var transaction = new InMemorySynchronizedStorageSession();
            await persister.Save(saga1, SagaMetadataHelper.GetMetadata <SagaWithUniqueProperty>(saga1), transaction, new ContextBag());

            await persister.Save(saga2, SagaMetadataHelper.GetMetadata <AnotherSagaTwoUniqueProperty>(saga2), transaction, new ContextBag());

            await transaction.CompleteAsync();
        }
        public async Task It_should_persist_successfully()
        {
            var saga1 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };
            var saga2 = new SagaWithUniquePropertyData
            {
                Id           = Guid.NewGuid(),
                UniqueString = "whatever"
            };

            await SaveSaga(saga1);
            await CompleteSaga(saga1.Id);

            await SaveSaga(saga2);
            await CompleteSaga(saga2.Id);

            await SaveSaga(saga1);
            await CompleteSaga(saga1.Id);
        }