Beispiel #1
0
        public async Task DeleteByStreamId()
        {
            var useCase = UseCases.Simple();
            var r1      = await Prepare(Fixture.Store, Fixture.AggregateRootServices, useCase).ConfigureAwait(false);

            using (var sess = Fixture.Store.OpenSession())
            {
                var ok = await sess.DeleteStreamAsync(r1.StreamId).ConfigureAwait(false);

                Assert.True(ok, CreateMessage("deleting previously saved aggregate"));
            }

            var notExists = await VerifyNotExists(r1.StreamId).ConfigureAwait(false);

            Assert.True(notExists, CreateMessage("stream exists even after delete"));
        }
Beispiel #2
0
        public async Task SaveAndHydrateWithinOneSession()
        {
            var r1 = UseCases.Simple().AsDirtyCustomerAggregate(Fixture.AggregateRootServices);

            using (var sess = Fixture.Store.OpenSession())
            {
                var ok = await sess.SaveUncommitedEventsAsync <CustomerAggregate, Customer>(r1).ConfigureAwait(false);

                Assert.True(ok, CreateMessage("saving uncommited events"));

                var r2 = new CustomerAggregate(r1.StreamId, Fixture.AggregateRootServices);
                ok = await sess.HydrateAsync <CustomerAggregate, Customer>(r2).ConfigureAwait(false);

                Assert.True(ok, "hydrating previously saved user");
                var result = Comparer.Compare(r1, r2);
                Assert.True(result.AreEqual, CreateMessage(result.DifferencesString));
            }
        }
Beispiel #3
0
        public async Task DropSaveInsideNotCompletedTransactionScope()
        {
            var r1 = UseCases.Simple().AsDirtyCustomerAggregate(Fixture.AggregateRootServices);

            using (var tx = Util.CreateTransactionScope())
                using (var sess = Fixture.Store.OpenSession())
                {
                    var ok = await sess.SaveUncommitedEventsAsync <CustomerAggregate, Customer>(r1).ConfigureAwait(false);

                    Assert.True(ok, CreateMessage("saving uncommited events"));

                    // tx.Complete(); => should ignore the save
                }

            var notExists = await VerifyNotExists(r1.StreamId).ConfigureAwait(false);

            Assert.True(notExists, CreateMessage("stream exists even after delete"));
        }
Beispiel #4
0
        public async Task SaveInsideTransactionScope()
        {
            var r1 = UseCases.Simple().AsDirtyCustomerAggregate(Fixture.AggregateRootServices);

            using (var tx = Util.CreateTransactionScope())
                using (var sess = Fixture.Store.OpenSession())
                {
                    var savedOk = await sess.SaveUncommitedEventsAsync <CustomerAggregate, Customer>(r1).ConfigureAwait(false);

                    Assert.True(savedOk, CreateMessage("saving uncommited events"));

                    tx.Complete();
                }

            var(ok, error) = await Verify(r1.StreamId, r1).ConfigureAwait(false);

            Assert.True(ok, CreateMessage(error));
        }
Beispiel #5
0
        public async Task SaveInsideNotCompletedButSupressedTransactionScope()
        {
            var r1 = UseCases.Simple().AsDirtyCustomerAggregate(Fixture.AggregateRootServices);

            using (var tx = Util.CreateTransactionScope())
                using (var sess = Fixture.Store.OpenSession(suppressAmbientTransaction: true))
                {
                    var savedOk = await sess.SaveUncommitedEventsAsync <CustomerAggregate, Customer>(r1).ConfigureAwait(false);

                    Assert.True(savedOk, CreateMessage("saving uncommited events"));

                    // no tx.Complete(); => should still accept, because tx is supressed,
                    // so it should behave like there is none.
                }

            var(ok, error) = await Verify(r1.StreamId, r1).ConfigureAwait(false);

            Assert.True(ok, CreateMessage(error));
        }