コード例 #1
0
        public override void SetUp()
        {
            base.SetUp();

            _clientTransaction = ClientTransaction.CreateRootTransaction();

            _newDomainObject = _clientTransaction.ExecuteInScope(() => Order.NewObject());
            _changedObject   = _clientTransaction.ExecuteInScope(() =>
            {
                var instance = DomainObjectIDs.Order1.GetObject <Order> ();
                instance.RegisterForCommit();
                return(instance);
            });
            _deletedObject = _clientTransaction.ExecuteInScope(() =>
            {
                var instance = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
                instance.Delete();
                return(instance);
            });
            _invalidObject = _clientTransaction.ExecuteInScope(() =>
            {
                var instance = Order.NewObject();
                instance.Delete();
                return(instance);
            });
            _unchangedObject    = _clientTransaction.ExecuteInScope(() => DomainObjectIDs.Order4.GetObject <Order> ());
            _notLoadedYetObject = LifetimeService.GetObjectReference(_clientTransaction, DomainObjectIDs.Order5);

            _registrar = new CommittingEventRegistrar(_clientTransaction);
        }
コード例 #2
0
        public void SetRelatedObject_SucceedsWithItemFromSameRootTransaction()
        {
            OrderTicket orderTicket = _rootTransaction.ExecuteInScope(() => OrderTicket.NewObject());

            _order1LoadedInRootTransaction.OrderTicket = orderTicket;
            Assert.That(_order1LoadedInRootTransaction.OrderTicket, Is.SameAs(orderTicket));
        }
コード例 #3
0
        public override void SetUp()
        {
            base.SetUp();

            _transaction      = ClientTransaction.CreateRootTransaction();
            _industrialSector = _transaction.ExecuteInScope(() => IndustrialSector.NewObject());
            _order            = _transaction.ExecuteInScope(() => Order.NewObject());
        }
コード例 #4
0
        public void GetObject_IncludeDeletedTrue_LoadsDeletedObject()
        {
            _clientTransaction.ExecuteInScope(() => _orderID1.GetObject <Order>().Delete());

            var result = _orderID1.GetObject <Order> (_clientTransaction, includeDeleted: true);

            Assert.That(result, Is.Not.Null);
            CheckDomainObject(result, _clientTransaction, expectedState: StateType.Deleted);
        }
コード例 #5
0
        public void ExecuteInScope_Action_RunsDelegate()
        {
            bool   delegateRun = false;
            Action action      = () => delegateRun = true;

            _transaction.ExecuteInScope(action);

            Assert.That(delegateRun, Is.True);
        }
 private DomainObject GetDeletedObject()
 {
     return(_transaction.ExecuteInScope(
                () =>
     {
         var instance = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ();
         instance.Delete();
         return instance;
     }));
 }
コード例 #7
0
        public void Count()
        {
            Assert.That(_order.Properties.GetPropertyCount(), Is.EqualTo(6));

            OrderItem orderItem = _transaction.ExecuteInScope(() => OrderItem.NewObject());

            Assert.That(orderItem.Properties.GetPropertyCount(), Is.EqualTo(3));

            ClassWithAllDataTypes cwadt = _transaction.ExecuteInScope(() => ClassWithAllDataTypes.NewObject());

            Assert.That(cwadt.Properties.GetPropertyCount(), Is.EqualTo(48));
        }
コード例 #8
0
 public void OnObjectCreatedAsClone(ClientTransaction cloneTransaction, DomainObject original)
 {
     CallbackInvoked            = true;
     CallbackCloneTransaction   = cloneTransaction;
     CallbackCurrentTransaction = ClientTransaction.Current;
     CallbackOriginal           = original;
     PropertyValueInCallback    = cloneTransaction.ExecuteInScope(() => Property);
 }
コード例 #9
0
        public override void SetUp()
        {
            base.SetUp();

            _clientTransaction = ClientTransaction.CreateRootTransaction();

            _eventBroker = new ClientTransactionEventBroker(_clientTransaction);

            _domainObject1       = _clientTransaction.ExecuteInScope(() => DomainObjectIDs.Order1.GetObject <Order> ());
            _domainObject2       = _clientTransaction.ExecuteInScope(() => DomainObjectIDs.Order3.GetObject <Order> ());
            _invalidDomainObject = _clientTransaction.ExecuteInScope(
                () =>
            {
                var order = Order.NewObject();
                order.Delete();
                return(order);
            });

            _mockRepository                 = new MockRepository();
            _order1EventReceiverMock        = _mockRepository.StrictMock <DomainObjectMockEventReceiver> (_domainObject1);
            _order2EventReceiverMock        = _mockRepository.StrictMock <DomainObjectMockEventReceiver> (_domainObject2);
            _invalidObjectEventReceiverMock = _mockRepository.StrictMock <DomainObjectMockEventReceiver> (_invalidDomainObject);

            _unloadEventReceiverMock = _mockRepository.StrictMock <IUnloadEventReceiver> ();
            ((TestDomainBase)_domainObject1).SetUnloadEventReceiver(_unloadEventReceiverMock);
            ((TestDomainBase)_domainObject2).SetUnloadEventReceiver(_unloadEventReceiverMock);

            _transactionEventReceiverMock = _mockRepository.StrictMock <ClientTransactionMockEventReceiver> (_clientTransaction);

            _loadEventReceiverMock = _mockRepository.StrictMock <ILoadEventReceiver> ();
            ((TestDomainBase)_domainObject1).SetLoadEventReceiver(_loadEventReceiverMock);
            ((TestDomainBase)_domainObject2).SetLoadEventReceiver(_loadEventReceiverMock);

            _extensionMock = _mockRepository.StrictMock <IClientTransactionExtension> ();
            _extensionMock.Stub(stub => stub.Key).Return("extension");
            _extensionMock.Replay();
            _eventBroker.Extensions.Add(_extensionMock);
            _extensionMock.BackToRecord();

            _listenerMock = _mockRepository.StrictMock <IClientTransactionListener> ();
            _eventBroker.AddListener(_listenerMock);
        }
コード例 #10
0
 private void CheckDomainObject(
     DomainObject result,
     ClientTransaction expectedClientTransaction,
     ObjectID expectedID     = null,
     StateType?expectedState = null)
 {
     Assert.That(expectedClientTransaction.IsEnlisted(result), Is.True);
     if (expectedID != null)
     {
         Assert.That(result.ID, Is.EqualTo(expectedID));
     }
     if (expectedState != null)
     {
         Assert.That(expectedClientTransaction.ExecuteInScope(() => result.State), Is.EqualTo(expectedState));
     }
 }
コード例 #11
0
        public void ExecuteInScope_NestedForDifferentTransactionsInTheHierarchy()
        {
            var middleTransaction = _rootTransaction.CreateSubTransaction();
            var subTransaction    = middleTransaction.CreateSubTransaction();

            Assert.That(_rootTransaction.ActiveTransaction, Is.SameAs(_rootTransaction));
            Assert.That(_order1LoadedInRootTransaction.DefaultTransactionContext.ClientTransaction, Is.SameAs(_rootTransaction));

            middleTransaction.ExecuteInScope(() =>
            {
                Assert.That(_rootTransaction.ActiveTransaction, Is.SameAs(middleTransaction));
                Assert.That(_order1LoadedInRootTransaction.DefaultTransactionContext.ClientTransaction, Is.SameAs(middleTransaction));

                subTransaction.ExecuteInScope(
                    () =>
                {
                    Assert.That(_rootTransaction.ActiveTransaction, Is.SameAs(subTransaction));
                    Assert.That(_order1LoadedInRootTransaction.DefaultTransactionContext.ClientTransaction, Is.SameAs(subTransaction));

                    _rootTransaction.ExecuteInScope(
                        () =>
                    {
                        Assert.That(_rootTransaction.ActiveTransaction, Is.SameAs(_rootTransaction));
                        Assert.That(_order1LoadedInRootTransaction.DefaultTransactionContext.ClientTransaction, Is.SameAs(_rootTransaction));
                    });

                    Assert.That(_rootTransaction.ActiveTransaction, Is.SameAs(subTransaction));
                    Assert.That(_order1LoadedInRootTransaction.DefaultTransactionContext.ClientTransaction, Is.SameAs(subTransaction));
                });

                Assert.That(_rootTransaction.ActiveTransaction, Is.SameAs(middleTransaction));
                Assert.That(_order1LoadedInRootTransaction.DefaultTransactionContext.ClientTransaction, Is.SameAs(middleTransaction));
            });

            Assert.That(_rootTransaction.ActiveTransaction, Is.SameAs(_rootTransaction));
            Assert.That(_order1LoadedInRootTransaction.DefaultTransactionContext.ClientTransaction, Is.SameAs(_rootTransaction));
        }
コード例 #12
0
        public void LoadStoreMixedDomainObject()
        {
            SetDatabaseModifyable();

            ClientTransaction clientTransaction = ClientTransaction.CreateRootTransaction();

            var mixedInstance   = clientTransaction.ExecuteInScope(() => TargetClassForPersistentMixin.NewObject());
            var mixin           = Mixin.Get <MixinAddingPersistentProperties> (mixedInstance);
            var relationTarget1 = clientTransaction.ExecuteInScope(() => RelationTargetForPersistentMixin.NewObject());
            var relationTarget2 = clientTransaction.ExecuteInScope(() => RelationTargetForPersistentMixin.NewObject());
            var relationTarget3 = clientTransaction.ExecuteInScope(() => RelationTargetForPersistentMixin.NewObject());
            var relationTarget4 = clientTransaction.ExecuteInScope(() => RelationTargetForPersistentMixin.NewObject());
            var relationTarget5 = clientTransaction.ExecuteInScope(() => RelationTargetForPersistentMixin.NewObject());

            mixin.PersistentProperty      = 10;
            mixin.NonPersistentProperty   = 100;
            mixin.ExtraPersistentProperty = 1000;
            mixin.RelationProperty        = relationTarget1;
            mixin.VirtualRelationProperty = relationTarget2;
            mixin.CollectionProperty1Side.Add(relationTarget3);
            mixin.CollectionPropertyNSide        = relationTarget4;
            mixin.UnidirectionalRelationProperty = relationTarget5;

            mixedInstance.RootTransaction.Commit();

            var otherClientTransaction = ClientTransaction.CreateRootTransaction();

            var loadedInstance = mixedInstance.ID.GetObject <TargetClassForPersistentMixin> (otherClientTransaction);
            var loadedMixin    = Mixin.Get <MixinAddingPersistentProperties> (loadedInstance);

            Assert.That(loadedInstance, Is.Not.SameAs(mixedInstance));
            Assert.That(loadedMixin, Is.Not.SameAs(mixin));

            Assert.That(loadedMixin.PersistentProperty, Is.EqualTo(10));
            Assert.That(loadedMixin.NonPersistentProperty, Is.EqualTo(0));
            Assert.That(loadedMixin.ExtraPersistentProperty, Is.EqualTo(1000));
            Assert.That(loadedMixin.RelationProperty.ID, Is.EqualTo(mixin.RelationProperty.ID));
            Assert.That(loadedMixin.VirtualRelationProperty.ID, Is.EqualTo(mixin.VirtualRelationProperty.ID));
            Assert.That(loadedMixin.CollectionProperty1Side.Count, Is.EqualTo(mixin.CollectionProperty1Side.Count));
            Assert.That(loadedMixin.CollectionProperty1Side[0].ID, Is.EqualTo(mixin.CollectionProperty1Side[0].ID));
            Assert.That(loadedMixin.CollectionPropertyNSide.ID, Is.EqualTo(mixin.CollectionPropertyNSide.ID));
            Assert.That(loadedMixin.UnidirectionalRelationProperty.ID, Is.EqualTo(mixin.UnidirectionalRelationProperty.ID));
        }
コード例 #13
0
 public void GetState_FromDataContainer_Changed()
 {
     _transaction.ExecuteInScope(() => _existingOrder.OrderNumber++);
     Assert.That(_cachingListener.GetState(_existingOrder.ID), Is.EqualTo(StateType.Changed));
 }
コード例 #14
0
        public void NewObject_InRootTransaction_AssociatesThatRootTransaction()
        {
            var order = _rootTransaction.ExecuteInScope(() => Order.NewObject());

            Assert.That(order.RootTransaction, Is.SameAs(_rootTransaction));
        }