public void GetObject()
        {
            var order = (Order)LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.Order1, false);

            Assert.That(order, Is.Not.Null);
            Assert.That(order.ID, Is.EqualTo(DomainObjectIDs.Order1));
            Assert.That(order.CtorCalled, Is.False);
        }
Esempio n. 2
0
        public void ModifyingProperty_NotLoaded()
        {
            _transporter.Load(DomainObjectIDs.Computer2);

            var transportTransaction = _transporter.GetTransportedObject(DomainObjectIDs.Computer2).RootTransaction;
            var source = LifetimeService.GetObject(transportTransaction, DomainObjectIDs.Computer1, false);

            _listener.PropertyValueChanging(TestableClientTransaction, source, GetPropertyDefinition(typeof(Computer), "SerialNumber"), null, null);
        }
        public void GetObject_IncludeDeleted_True()
        {
            DomainObjectIDs.Order1.GetObject <Order> ().Delete();
            var order = (Order)LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.Order1, true);

            Assert.That(order, Is.Not.Null);
            Assert.That(order.ID, Is.EqualTo(DomainObjectIDs.Order1));
            Assert.That(order.State, Is.EqualTo(StateType.Deleted));
        }
Esempio n. 4
0
        public static DomainObject GetChangedObject(ClientTransaction transaction, ObjectID objectID)
        {
            var changedInstance = LifetimeService.GetObject(transaction, objectID, false);

            changedInstance.RegisterForCommit();
            Assert.That(changedInstance.State, Is.EqualTo(StateType.Changed));
            Assert.That(ClientTransactionTestHelper.GetDataManager(transaction).DataContainers[objectID].State, Is.EqualTo(StateType.Changed));
            return(changedInstance);
        }
Esempio n. 5
0
        private Substitution GetSubstitution(ClientTransaction transaction)
        {
            if (_substitutionHandle == null)
            {
                return(null);
            }

            return((Substitution)LifetimeService.GetObject(transaction, _substitutionHandle.ObjectID, false));
        }
        public override void SetUp()
        {
            base.SetUp();

            _transaction = new TestableClientTransaction();
            _order1      = (Order)LifetimeService.GetObject(_transaction, DomainObjectIDs.Order1, false);
            _transactionEventSinkWithMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>();

            _deleteOrder1Command = new DeleteCommand(_transaction, _order1, _transactionEventSinkWithMock);
        }
        public void GetObject_WithInvalidObject_Throws()
        {
            var instance = Order.NewObject();

            instance.Delete();
            Assert.That(instance.State, Is.EqualTo(StateType.Invalid));

            Assert.That(() => LifetimeService.GetObject(TestableClientTransaction, instance.ID, false), Throws.TypeOf <ObjectInvalidException> ());
            Assert.That(() => LifetimeService.GetObject(TestableClientTransaction, instance.ID, true), Throws.TypeOf <ObjectInvalidException> ());
        }
Esempio n. 8
0
        public override void SetUp()
        {
            base.SetUp();

            _transaction     = ClientTransaction.CreateRootTransaction();
            _cachingListener = new DomainObjectStateCache(_transaction);

            _existingOrder     = (Order)LifetimeService.GetObject(_transaction, DomainObjectIDs.Order1, false);
            _newOrder          = (Order)LifetimeService.NewObject(_transaction, typeof(Order), ParamList.Empty);
            _notYetLoadedOrder = (Order)LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.Order3);
        }
Esempio n. 9
0
        public void Traversal_NotAffectedByNotProcessingAnObject()
        {
            Order order = DomainObjectIDs.Order1.GetObject <Order> ();
            HashSet <DomainObject> graph = new DomainObjectGraphTraverser(order, new TestTraversalStrategy(false, true)).GetFlattenedRelatedObjectGraph();

            var expected = new HashSet <DomainObject> {
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.Distributor2, false)
            };

            Assert.That(graph, Is.EquivalentTo(expected));
        }
        public static ObjectID SetRelationInOtherTransaction(RelationEndPointID endPointID, ObjectID relatedID)
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var domainObject = LifetimeService.GetObject(ClientTransaction.Current, endPointID.ObjectID, true);
                SetForeignKeyProperty(domainObject, (RelationEndPointDefinition)endPointID.Definition, relatedID);
                ClientTransaction.Current.Commit();

                return(domainObject.ID);
            }
        }
Esempio n. 11
0
 protected T[] GetExpectedObjects <T> (params ObjectID[] expectedObjectIDs)
     where T : DomainObject
 {
     if (expectedObjectIDs == null)
     {
         return new T[] { null }
     }
     ;
     return((from id in expectedObjectIDs
             select(id == null ? null : (T)LifetimeService.GetObject(TestableClientTransaction, id, false))).ToArray());
 }
        public void GetObject_Deleted()
        {
            var domainObject = LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.ClassWithAllDataTypes1, false);

            LifetimeService.DeleteObject(TestableClientTransaction, domainObject);

            Assert.That(
                () => LifetimeService.GetObject(TestableClientTransaction, domainObject.ID, false),
                Throws.TypeOf <ObjectDeletedException> ().With.Message.EqualTo(
                    "Object 'ClassWithAllDataTypes|3f647d79-0caf-4a53-baa7-a56831f8ce2d|System.Guid' is already deleted."));
            Assert.That(LifetimeService.GetObject(TestableClientTransaction, domainObject.ID, true), Is.SameAs(domainObject));
        }
Esempio n. 13
0
        protected T CreateObjectInDatabaseAndLoad <T> () where T : DomainObject
        {
            ObjectID objectID;

            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var domainObject = LifetimeService.NewObject(ClientTransaction.Current, typeof(T), ParamList.Empty);
                ClientTransaction.Current.Commit();
                objectID = domainObject.ID;
            }
            return((T)LifetimeService.GetObject(ClientTransaction.Current, objectID, false));
        }
        public static ObjectID CreateObjectAndSetRelationInOtherTransaction <TCreated, TRelated> (ObjectID relatedID, Action <TCreated, TRelated> setter)
            where TCreated : DomainObject
            where TRelated : DomainObject
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var domainObject = (TCreated)LifetimeService.NewObject(ClientTransaction.Current, typeof(TCreated), ParamList.Empty);
                setter(domainObject, relatedID != null ? (TRelated)LifetimeService.GetObject(ClientTransaction.Current, relatedID, true) : null);
                ClientTransaction.Current.Commit();

                return(domainObject.ID);
            }
        }
        public static ObjectID SetRelationInOtherTransaction <TOriginating, TRelated> (ObjectID originatingID, ObjectID relatedID, Action <TOriginating, TRelated> setter)
            where TOriginating : DomainObject
            where TRelated : DomainObject
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var domainObject = (TOriginating)LifetimeService.GetObject(ClientTransaction.Current, originatingID, true);
                setter(domainObject, relatedID != null ? (TRelated)LifetimeService.GetObject(ClientTransaction.Current, relatedID, true) : null);
                ClientTransaction.Current.Commit();

                return(domainObject.ID);
            }
        }
        public override void SetUp()
        {
            base.SetUp();

            _order    = (Order)LifetimeService.GetObjectReference(WriteableSubTransaction, DomainObjectIDs.Order1);
            _location = (Location)LifetimeService.GetObjectReference(WriteableSubTransaction, DomainObjectIDs.Location1);
            _client1  = (Client)LifetimeService.GetObject(WriteableSubTransaction, DomainObjectIDs.Client1, false);
            _client2  = (Client)LifetimeService.GetObject(WriteableSubTransaction, DomainObjectIDs.Client2, false);
            _client3  = (Client)LifetimeService.GetObject(WriteableSubTransaction, DomainObjectIDs.Client3, false);
            _client4  = (Client)LifetimeService.NewObject(WriteableSubTransaction, typeof(Client), ParamList.Empty);

            _loadEventReceiverMock = MockRepository.GenerateStrictMock <ILoadEventReceiver>();
            _order.SetLoadEventReceiver(_loadEventReceiverMock);
            _location.SetLoadEventReceiver(_loadEventReceiverMock);
        }
        public void GetObject_Invalid()
        {
            var domainObject = ClassWithAllDataTypes.NewObject();

            domainObject.Delete();

            var expectedMessage = string.Format("Object '{0}' is invalid in this transaction.", domainObject.ID);

            Assert.That(
                () => LifetimeService.GetObject(TestableClientTransaction, domainObject.ID, true),
                Throws.TypeOf <ObjectInvalidException> ().With.Message.EqualTo(expectedMessage));
            Assert.That(
                () => LifetimeService.GetObject(TestableClientTransaction, domainObject.ID, false),
                Throws.TypeOf <ObjectInvalidException> ().With.Message.EqualTo(expectedMessage));
        }
Esempio n. 18
0
        public void Get_StateCombinationsFromDatabase()
        {
            DatabaseFixtures dbFixtures   = new DatabaseFixtures();
            var expectedAcl               = dbFixtures.CreateAndCommitAccessControlListWithStateCombinations(10, ClientTransactionScope.CurrentTransaction);
            var expectedStateCombinations = expectedAcl.StateCombinations;

            using (ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope())
            {
                var actualAcl = (StatefulAccessControlList)LifetimeService.GetObject(ClientTransaction.Current, expectedAcl.ID, false);

                Assert.That(actualAcl.StateCombinations.Count, Is.EqualTo(9));
                for (int i = 0; i < 9; i++)
                {
                    Assert.That(actualAcl.StateCombinations[i].ID, Is.EqualTo(expectedStateCombinations[i].ID));
                }
            }
        }
Esempio n. 19
0
        public void Get_AccessControlEntriesFromDatabase()
        {
            DatabaseFixtures  dbFixtures  = new DatabaseFixtures();
            AccessControlList expectedAcl =
                dbFixtures.CreateAndCommitAccessControlListWithAccessControlEntries(10, ClientTransactionScope.CurrentTransaction);
            ObjectList <AccessControlEntry> expectedAces = expectedAcl.AccessControlEntries;

            using (ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope())
            {
                var actualAcl = (AccessControlList)LifetimeService.GetObject(ClientTransaction.Current, expectedAcl.ID, false);

                Assert.That(actualAcl.AccessControlEntries.Count, Is.EqualTo(10));
                for (int i = 0; i < 10; i++)
                {
                    Assert.That(actualAcl.AccessControlEntries[i].ID, Is.EqualTo(expectedAces[i].ID));
                }
            }
        }
        public void GetObject_Twice()
        {
            DomainObject domainObject1 = LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.ClassWithAllDataTypes1, false);

            Assert.That(_eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(1));

            var domainObjects = _eventReceiver.LoadedDomainObjectLists[0];

            Assert.That(domainObjects.Count, Is.EqualTo(1));
            Assert.That(domainObjects[0], Is.SameAs(domainObject1));
            _eventReceiver.Clear();

            DomainObject domainObject2 = LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.ClassWithAllDataTypes1, false);

            Assert.That(_eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(0));

            Assert.That(domainObject2, Is.SameAs(domainObject1));
        }
Esempio n. 21
0
        public void OnDomainObjectLoaded()
        {
            var tx = CreateTransactionWithStubbedLoading(_objectID);

            var mixinInstance = new HookedDomainObjectMixin();

            Assert.That(mixinInstance.OnLoadedCalled, Is.False);
            Assert.That(mixinInstance.OnCreatedCalled, Is.False);
            Assert.That(mixinInstance.OnDomainObjectReferenceInitializingCalled, Is.False);

            using (new MixedObjectInstantiationScope(mixinInstance))
            {
                LifetimeService.GetObject(tx, _objectID, false);
            }

            Assert.That(mixinInstance.OnLoadedCalled, Is.True);
            Assert.That(mixinInstance.OnLoadedLoadMode, Is.EqualTo(LoadMode.WholeDomainObjectInitialized));
            Assert.That(mixinInstance.OnCreatedCalled, Is.False);
            Assert.That(mixinInstance.OnDomainObjectReferenceInitializingCalled, Is.True);
        }
Esempio n. 22
0
        public void SingleInheritance_GetObject()
        {
            ObjectID firstDerivedClassObjectID;
            ObjectID secondDerivedClassObjectID;

            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                var firstDerivedClass = SingleInheritanceFirstDerivedClass.NewObject();
                firstDerivedClassObjectID = firstDerivedClass.ID;
                var secondDerivedClass = SingleInheritanceSecondDerivedClass.NewObject();
                secondDerivedClassObjectID = secondDerivedClass.ID;

                ClientTransaction.Current.Commit();
            }

            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                Assert.IsInstanceOf(typeof(SingleInheritanceFirstDerivedClass), LifetimeService.GetObject(ClientTransaction.Current, firstDerivedClassObjectID, false));
                Assert.IsInstanceOf(typeof(SingleInheritanceSecondDerivedClass), LifetimeService.GetObject(ClientTransaction.Current, secondDerivedClassObjectID, false));
            }
        }
Esempio n. 23
0
        public void GetFlattenedRelatedObjectGraph_WithTraversalFilter_FollowLink_IncludeObject()
        {
            Order order = DomainObjectIDs.Order1.GetObject <Order> ();
            var   graph = new DomainObjectGraphTraverser(order, new TestTraversalStrategy(false, false)).GetFlattenedRelatedObjectGraph();

            var expected = new HashSet <DomainObject> {
                order,
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.OrderTicket1, false),
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.OrderItem1, false),
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.OrderItem2, false),
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.Customer1, false),
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.Official1, false),
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.IndustrialSector1, false),
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.Partner1, false),
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.PartnerWithoutCeo, false),
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.Supplier1, false),
                LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.Distributor2, false)
            };

            Assert.That(graph, Is.EquivalentTo(expected));
        }
        private TransportedDomainObjects TransportAndDeleteObjects(params ObjectID[] objectsToLoadAndDelete)
        {
            var transporter = new DomainObjectTransporter();

            foreach (ObjectID id in objectsToLoadAndDelete)
            {
                transporter.Load(id);
            }

            ModifyDatabase(
                delegate
            {
                foreach (var id in objectsToLoadAndDelete)
                {
                    var domainObject = LifetimeService.GetObject(ClientTransaction.Current, id, false);
                    LifetimeService.DeleteObject(ClientTransaction.Current, domainObject);
                }
            });

            return(Transport(transporter));
        }
        private TransportedDomainObjects TransportAndChangeObjects(string propertyName, object newValue, params ObjectID[] objectsToLoadAndDelete)
        {
            var transporter = new DomainObjectTransporter();

            foreach (ObjectID id in objectsToLoadAndDelete)
            {
                transporter.Load(id);
            }

            ModifyDatabase(
                delegate
            {
                foreach (var id in objectsToLoadAndDelete)
                {
                    var domainObject = LifetimeService.GetObject(ClientTransaction.Current, id, false);
                    var properties   = new PropertyIndexer(domainObject);
                    properties[propertyName].SetValueWithoutTypeCheck(newValue);
                }
            });

            return(Transport(transporter));
        }
Esempio n. 26
0
        protected void CheckCollectionRelationRegistered(
            ObjectID originatingObjectID, Type declaringType, string shortPropertyName, bool checkOrdering, params ObjectID[] expectedRelatedObjectIDs)
        {
            var relationEndPointDefinition =
                originatingObjectID.ClassDefinition.GetMandatoryRelationEndPointDefinition(
                    declaringType.FullName + "." + shortPropertyName);

            var endPointID         = RelationEndPointID.Create(originatingObjectID, relationEndPointDefinition);
            var collectionEndPoint = (ICollectionEndPoint)TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID);

            Assert.That(collectionEndPoint, Is.Not.Null);

            var expectedRelatedObjects = expectedRelatedObjectIDs.Select(id => LifetimeService.GetObject(TestableClientTransaction, id, false)).ToArray();

            if (checkOrdering)
            {
                Assert.That(collectionEndPoint.Collection, Is.EqualTo(expectedRelatedObjects));
            }
            else
            {
                Assert.That(collectionEndPoint.Collection, Is.EquivalentTo(expectedRelatedObjects));
            }
        }
Esempio n. 27
0
        public void LoadSingleObject()
        {
            var clientTransaction = ClientTransaction.CreateRootTransaction();

            LifetimeService.GetObject(clientTransaction, _objectID, false);
            clientTransaction.Discard();

            Assert.That(
                _tracingLinqToSqlAppender.TraceLog,
                Is.StringMatching(
                    @"^ConnectionStarted \((?<connectionid>[^,]+)\)" + Environment.NewLine
                    + @"StatementExecuted \(\k<connectionid>, (?<statementid>[^,]+), "
                    + @"SELECT \[ID\], \[ClassID\], \[Timestamp\], \[SampleProperty\] "
                    + @"FROM \[SampleObject\] WHERE \[ID\] = \@ID;" + Environment.NewLine
                    + @"-- Ignore unbounded result sets: TOP \*" + Environment.NewLine
                    + @"-- Parameters:" + Environment.NewLine
                    + string.Format(@"-- \@ID = \[-\[{0}\]-\] \[-\[Type \(0\)\]-\]", _objectID.Value) + Environment.NewLine
                    + @"\)" + Environment.NewLine
                    + @"CommandDurationAndRowCount \(\k<connectionid>, \d+, \<null\>\)" + Environment.NewLine
                    + @"StatementRowCount \(\k<connectionid>, \k<statementid>, 1\)" + Environment.NewLine
                    + @"ConnectionDisposed \(\k<connectionid>\)" + Environment.NewLine
                    + @"$"));
        }
Esempio n. 28
0
        public void OnDomainObjectLoadedInSubTransaction()
        {
            var tx = CreateTransactionWithStubbedLoading(_objectID);

            var mixinInstance = new HookedDomainObjectMixin();

            Assert.That(mixinInstance.OnLoadedCalled, Is.False);
            Assert.That(mixinInstance.OnCreatedCalled, Is.False);
            Assert.That(mixinInstance.OnDomainObjectReferenceInitializingCalled, Is.False);

            using (new MixedObjectInstantiationScope(mixinInstance))
            {
                var subTx = tx.CreateSubTransaction();
                LifetimeService.GetObject(subTx, _objectID, false);
                subTx.Discard();
            }

            Assert.That(mixinInstance.OnLoadedCalled, Is.True);
            Assert.That(mixinInstance.OnLoadedCount, Is.EqualTo(2));
            Assert.That(mixinInstance.OnLoadedLoadMode, Is.EqualTo(LoadMode.DataContainerLoadedOnly));
            Assert.That(mixinInstance.OnCreatedCalled, Is.False);
            Assert.That(mixinInstance.OnDomainObjectReferenceInitializingCalled, Is.True);
        }
Esempio n. 29
0
        public void TryGetObjects_UnloadedObjects_PropagatedToParent()
        {
            ClientTransaction parent         = ClientTransaction.CreateRootTransaction();
            ClientTransaction subTransaction = parent.CreateSubTransaction();

            LifetimeService.GetObject(subTransaction, DomainObjectIDs.ClassWithAllDataTypes1, false); // preload ClassWithAllDataTypes

            var extensionMock = MockRepository.GenerateMock <IClientTransactionExtension> ();

            extensionMock.Stub(stub => stub.Key).Return("mock");
            parent.Extensions.Add(extensionMock);

            LifetimeService.TryGetObjects <DomainObject> (
                subTransaction,
                DomainObjectIDs.Order1,
                DomainObjectIDs.ClassWithAllDataTypes1, // this has already been loaded
                DomainObjectIDs.Order3,
                DomainObjectIDs.OrderItem1);

            extensionMock.AssertWasCalled(mock => mock.ObjectsLoading(Arg.Is(parent),
                                                                      Arg <ReadOnlyCollection <ObjectID> > .List.Equal(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1 })));
            extensionMock.AssertWasNotCalled(mock => mock.ObjectsLoading(Arg.Is(parent),
                                                                         Arg <ReadOnlyCollection <ObjectID> > .List.ContainsAll(new[] { DomainObjectIDs.ClassWithAllDataTypes1 })));
        }
Esempio n. 30
0
 public static T GetObjectInTransaction <T> (ClientTransaction transaction, ObjectID objectID) where T : DomainObject
 {
     return((T)LifetimeService.GetObject(transaction, objectID, true));
 }