public void CommittingTheOuterScopeCommitsDuh()
        {
            var container = new WindsorContainer();
            var unitOfWorkSpy = new UnitOfWorkSpy();
            container.Register(
                Component.For<ISingleContextUseGuard>().ImplementedBy<SingleThreadUseGuard>(),
                Component.For<IUnitOfWorkParticipant>().Instance(unitOfWorkSpy)
                );

            using(var outerScope = container.BeginTransactionalUnitOfWorkScope())
            {
                unitOfWorkSpy.UnitOfWork.Should().NotBe(null);
                unitOfWorkSpy.Committed.Should().Be(false);
                unitOfWorkSpy.RolledBack.Should().Be(false);
                using (var innerScope = container.BeginTransactionalUnitOfWorkScope())
                {
                    innerScope.Commit();
                    unitOfWorkSpy.UnitOfWork.Should().NotBe(null);
                    unitOfWorkSpy.Committed.Should().Be(false);
                    unitOfWorkSpy.RolledBack.Should().Be(false);
                }
                unitOfWorkSpy.UnitOfWork.Should().NotBe(null);
                unitOfWorkSpy.Committed.Should().Be(false);
                unitOfWorkSpy.RolledBack.Should().Be(false);
                outerScope.Commit();
            }
            unitOfWorkSpy.UnitOfWork.Should().Be(null);
            unitOfWorkSpy.Committed.Should().Be(true);
            unitOfWorkSpy.RolledBack.Should().Be(false);
        }
        public void CommittingTheOuterScopeCommitsDuh()
        {
            var container     = new WindsorContainer();
            var unitOfWorkSpy = new UnitOfWorkSpy();

            container.Register(
                Component.For <ISingleContextUseGuard>().ImplementedBy <SingleThreadUseGuard>(),
                Component.For <IUnitOfWorkParticipant>().Instance(unitOfWorkSpy)
                );

            using (var outerScope = container.BeginTransactionalUnitOfWorkScope())
            {
                unitOfWorkSpy.UnitOfWork.Should().NotBe(null);
                unitOfWorkSpy.Committed.Should().Be(false);
                unitOfWorkSpy.RolledBack.Should().Be(false);
                using (var innerScope = container.BeginTransactionalUnitOfWorkScope())
                {
                    innerScope.Commit();
                    unitOfWorkSpy.UnitOfWork.Should().NotBe(null);
                    unitOfWorkSpy.Committed.Should().Be(false);
                    unitOfWorkSpy.RolledBack.Should().Be(false);
                }
                unitOfWorkSpy.UnitOfWork.Should().NotBe(null);
                unitOfWorkSpy.Committed.Should().Be(false);
                unitOfWorkSpy.RolledBack.Should().Be(false);
                outerScope.Commit();
            }
            unitOfWorkSpy.UnitOfWork.Should().Be(null);
            unitOfWorkSpy.Committed.Should().Be(true);
            unitOfWorkSpy.RolledBack.Should().Be(false);
        }
예제 #3
0
        public void CanFetchQueryModelAfterAggregateHasBeenCreated()
        {
            using (_container.BeginScope())
            {
                var aggregates = _container.Resolve <IEventStoreSession>();
                var accountId  = Guid.Parse("00000000-0000-0000-0000-000000000001");

                MyAccount registered;
                using (var transaction = _container.BeginTransactionalUnitOfWorkScope())
                {
                    registered = MyAccount.Register(aggregates, accountId, "email", "password");
                    transaction.Commit();
                }


                registered.Email.Should().Be("email");
                registered.Password.Should().Be("password");


                var reader      = _container.Resolve <IDocumentDbReader>();
                var loadedModel = reader.Get <MyAccountQueryModel>(registered.Id);

                loadedModel.Should().NotBe(null);
                loadedModel.Id.Should().Be(accountId);
                loadedModel.Email.Should().Be(registered.Email);
                loadedModel.Password.Should().Be(registered.Password);
            }
        }