コード例 #1
0
    public async Task Should_not_generate_a_to_long_unique_property_id()
    {
        IAsyncDocumentSession session;
        var options      = this.CreateContextWithAsyncSessionPresent(out session);
        var persister    = new SagaPersister();
        var uniqueString = Guid.NewGuid().ToString();
        var saga         = new SagaWithUniquePropertyAndALongNamespace
        {
            Id           = Guid.NewGuid(),
            UniqueString = uniqueString
        };
        var synchronizedSession = new RavenDBSynchronizedStorageSession(session);

        await persister.Save(saga, this.CreateMetadata <SomeSaga>(saga), synchronizedSession, options);

        await session.SaveChangesAsync().ConfigureAwait(false);
    }
    public async Task Should_not_generate_a_to_long_unique_property_id()
    {
        using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options))
        {
            var persister    = new SagaPersister(new SagaPersistenceConfiguration());
            var uniqueString = Guid.NewGuid().ToString();
            var saga         = new SagaWithUniquePropertyAndALongNamespace
            {
                Id           = Guid.NewGuid(),
                UniqueString = uniqueString
            };
            var synchronizedSession = new RavenDBSynchronizedStorageSession(session, new ContextBag());

            await persister.Save(saga, this.CreateMetadata <SomeSaga>(saga), synchronizedSession, options);

            await session.SaveChangesAsync().ConfigureAwait(false);
        }
    }
    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
        };

        var synchronizedSession = new RavenDBSynchronizedStorageSession(session);

        await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), synchronizedSession, options);

        await session.SaveChangesAsync().ConfigureAwait(false);

        session.Dispose();

        options             = this.CreateContextWithAsyncSessionPresent(out session);
        synchronizedSession = new RavenDBSynchronizedStorageSession(session);

        var saga = await persister.Get <SagaData>(saga1.Id, synchronizedSession, options);

        await persister.Complete(saga, synchronizedSession, options);

        await session.SaveChangesAsync().ConfigureAwait(false);

        session.Dispose();

        options             = this.CreateContextWithAsyncSessionPresent(out session);
        synchronizedSession = new RavenDBSynchronizedStorageSession(session);

        var saga2 = new SagaData
        {
            Id           = Guid.NewGuid(),
            UniqueString = uniqueString
        };

        await persister.Save(saga2, this.CreateMetadata <SomeSaga>(saga2), synchronizedSession, options);

        await session.SaveChangesAsync().ConfigureAwait(false);
    }
    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(new SagaPersistenceConfiguration());
            var entity    = new SagaData
            {
                Id = sagaId
            };

            // Save a saga
            using (var synchronizedSession = new RavenDBSynchronizedStorageSession(session, options))
            {
                await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, options);

                await session.SaveChangesAsync().ConfigureAwait(false);
            }

            // Delete the saga
            using (var synchronizedSession = new RavenDBSynchronizedStorageSession(session, options))
            {
                var saga = await persister.Get <SagaData>(sagaId, synchronizedSession, options);

                await persister.Complete(saga, synchronizedSession, options);

                await session.SaveChangesAsync().ConfigureAwait(false);
            }

            // Check to see if the saga is gone
            SagaData           testSaga;
            SagaUniqueIdentity testIdentity;
            using (var synchronizedSession = new RavenDBSynchronizedStorageSession(session, options))
            {
                testSaga = await persister.Get <SagaData>(sagaId, synchronizedSession, options).ConfigureAwait(false);

                testIdentity = await session.Query <SagaUniqueIdentity>().Customize(c => c.WaitForNonStaleResults()).SingleOrDefaultAsync(u => u.SagaId == sagaId).ConfigureAwait(false);
            }

            Assert.Null(testSaga);
            Assert.Null(testIdentity);
        }
    }
コード例 #5
0
        public async Task Dispose_without_complete_rolls_back()
        {
            var documentId = Guid.NewGuid().ToString();

            using (var writeDocSession = store.OpenAsyncSession().UsingOptimisticConcurrency())
                using (var writeSession = new RavenDBSynchronizedStorageSession(writeDocSession, true))
                {
                    await writeSession.Session.StoreAsync(new TestDocument { Value = "43" }, documentId);

                    // do not call CompleteAsync
                }

            using (var readSession = store.OpenAsyncSession().UsingOptimisticConcurrency())
            {
                var storedDocument = await readSession.LoadAsync <TestDocument>(documentId);

                Assert.IsNull(storedDocument);
            }
        }
コード例 #6
0
        public async Task CompleteAsync_without_savechanges_rolls_back()
        {
            var documentId = Guid.NewGuid().ToString();

            using (var writeDocSession = store.OpenAsyncSession().UsingOptimisticConcurrency())
                using (var writeSession = new RavenDBSynchronizedStorageSession(writeDocSession, new ContextBag(), false))
                {
                    await writeSession.Session.StoreAsync(new TestDocument { Value = "43" }, documentId);

                    await writeSession.CompleteAsync();
                }

            using (var readSession = store.OpenAsyncSession().UsingOptimisticConcurrency())
            {
                var storedDocument = await readSession.LoadAsync <TestDocument>(documentId);

                Assert.IsNull(storedDocument);
            }
        }
    public async Task should_throw_a_ArgumentNullException()
    {
        var saga1 = new SagaData
        {
            Id           = Guid.NewGuid(),
            UniqueString = null
        };

        IAsyncDocumentSession session;
        var context      = this.CreateContextWithAsyncSessionPresent(out session);
        var ravenSession = new RavenDBSynchronizedStorageSession(session, true);
        var persister    = new SagaPersister();

        var exception = await Catch <ArgumentNullException>(async() =>
        {
            await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), ravenSession, context);
            await session.SaveChangesAsync().ConfigureAwait(false);
        });

        Assert.IsNotNull(exception);
    }
コード例 #8
0
    public async Task Should_throw_a_ArgumentNullException()
    {
        var saga1 = new SagaData
        {
            Id           = Guid.NewGuid(),
            UniqueString = null
        };

        using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var context))
        {
            var ravenSession = new RavenDBSynchronizedStorageSession(session, new ContextBag());
            var persister    = new SagaPersister(new SagaPersistenceConfiguration());

            var exception = await Catch <ArgumentNullException>(async cancellationToken =>
            {
                await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), ravenSession, context, cancellationToken);
                await session.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
            });

            Assert.IsNotNull(exception);
        }
    }
    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");
    }
コード例 #10
0
    public async Task It_should_enforce_uniqueness()
    {
        var persister    = new SagaPersister(new SagaPersistenceConfiguration());
        var uniqueString = Guid.NewGuid().ToString();

        using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options))
        {
            var saga1 = new SagaData
            {
                Id           = Guid.NewGuid(),
                UniqueString = uniqueString
            };

            var synchronizedSession = new RavenDBSynchronizedStorageSession(session, new ContextBag());

            await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), synchronizedSession, options);

            await session.SaveChangesAsync().ConfigureAwait(false);
        }

        var exception = await Catch <ConcurrencyException>(async cancellationToken =>
        {
            using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options))
            {
                var saga2 = new SagaData
                {
                    Id           = Guid.NewGuid(),
                    UniqueString = uniqueString
                };

                var synchronizedSession = new RavenDBSynchronizedStorageSession(session, new ContextBag());

                await persister.Save(saga2, this.CreateMetadata <SomeSaga>(saga2), synchronizedSession, options, cancellationToken);
                await session.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
            }
        });

        Assert.IsNotNull(exception);
    }
コード例 #11
0
        public async Task CompleteAsync_with_savechanges_enabled_completes_transaction()
        {
            var newDocument = new TestDocument {
                Value = "42"
            };

            using (var writeDocSession = store.OpenAsyncSession().UsingOptimisticConcurrency())
                using (var writeSession = new RavenDBSynchronizedStorageSession(writeDocSession, new ContextBag(), true))
                {
                    await writeSession.Session.StoreAsync(newDocument);

                    await writeSession.CompleteAsync();
                }

            using (var readSession = store.OpenAsyncSession().UsingOptimisticConcurrency())
            {
                var storedDocument = await readSession.LoadAsync <TestDocument>(newDocument.Id);

                Assert.NotNull(storedDocument);
                Assert.AreEqual(newDocument.Value, storedDocument.Value);
            }
        }
コード例 #12
0
    public async Task Datetime_property_should_be_persisted()
    {
        var entity = new SagaData
        {
            Id               = Guid.NewGuid(),
            UniqueString     = "SomeUniqueString",
            DateTimeProperty = DateTime.Parse("12/02/2010 12:00:00.01")
        };

        IAsyncDocumentSession session;
        var options             = this.CreateContextWithAsyncSessionPresent(out session);
        var persister           = new SagaPersister();
        var synchronizedSession = new RavenDBSynchronizedStorageSession(session);

        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.DateTimeProperty, savedEntity.DateTimeProperty);
    }
    public async Task It_should_load_successfully()
    {
        var unique = Guid.NewGuid().ToString();

        CreateLegacySagaDocuments(store, unique);

        using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var options))
        {
            var persister = new SagaPersister();

            var synchronizedSession = new RavenDBSynchronizedStorageSession(session);

            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");
        }
    }
コード例 #14
0
    public async Task Enums_should_be_persisted()
    {
        var entity = new SagaData
        {
            Id           = Guid.NewGuid(),
            UniqueString = "SomeUniqueString",
            Status       = StatusEnum.AnotherStatus
        };

        IAsyncDocumentSession session;

        var context             = this.CreateContextWithAsyncSessionPresent(out session);
        var persister           = new SagaPersister();
        var synchronizedSession = new RavenDBSynchronizedStorageSession(session);

        await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, context);

        await session.SaveChangesAsync().ConfigureAwait(false);

        var savedEntity = await persister.Get <SagaData>(entity.Id, synchronizedSession, context);

        Assert.AreEqual(entity.Status, savedEntity.Status);
    }
コード例 #15
0
    public async Task Enums_should_be_persisted()
    {
        var entity = new SagaData
        {
            Id           = Guid.NewGuid(),
            UniqueString = "SomeUniqueString",
            Status       = StatusEnum.AnotherStatus
        };

        using (var session = store.OpenAsyncSession().UsingOptimisticConcurrency().InContext(out var context))
        {
            var persister           = new SagaPersister(new SagaPersistenceConfiguration());
            var synchronizedSession = new RavenDBSynchronizedStorageSession(session, context);

            await persister.Save(entity, this.CreateMetadata <SomeSaga>(entity), synchronizedSession, context);

            await session.SaveChangesAsync().ConfigureAwait(false);

            var savedEntity = await persister.Get <SagaData>(entity.Id, synchronizedSession, context);

            Assert.AreEqual(entity.Status, savedEntity.Status);
        }
    }
    public async Task Datetime_property_should_be_persisted()
    {
        var entity = new SagaData
        {
            Id               = Guid.NewGuid(),
            UniqueString     = "SomeUniqueString",
            DateTimeProperty = DateTime.Parse("12/02/2010 12:00:00.01")
        };

        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.DateTimeProperty, savedEntity.DateTimeProperty);
        }
    }
コード例 #17
0
    public async Task It_should_enforce_uniqueness()
    {
        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
        };

        var synchronizedSession = new RavenDBSynchronizedStorageSession(session);

        await persister.Save(saga1, this.CreateMetadata <SomeSaga>(saga1), synchronizedSession, options);

        await session.SaveChangesAsync().ConfigureAwait(false);

        session.Dispose();

        var exception = await Catch <ConcurrencyException>(async() =>
        {
            options             = this.CreateContextWithAsyncSessionPresent(out session);
            synchronizedSession = new RavenDBSynchronizedStorageSession(session);
            var saga2           = new SagaData
            {
                Id           = Guid.NewGuid(),
                UniqueString = uniqueString
            };
            await persister.Save(saga2, this.CreateMetadata <SomeSaga>(saga2), synchronizedSession, options);
            await session.SaveChangesAsync().ConfigureAwait(false);
        });

        Assert.IsNotNull(exception);
    }
コード例 #18
0
        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);
                        }
                    }
                }
            }
        }