public void GetOptionalRelatedObjectTwice()
        {
            var id = new ObjectID("ClassWithValidRelations", new Guid("{6BE4FA61-E050-469c-9DBA-B47FFBB0F8AD}"));

            CountingObjectLoaderDecorator decorator = null;
            var clientTransaction =
                ClientTransactionObjectMother.CreateTransactionWithObjectLoaderDecorator <TestableClientTransaction> (
                    loader => decorator ?? (decorator = new CountingObjectLoaderDecorator(loader)));

            DomainObject classWithValidRelation = clientTransaction.GetObject(id, false);

            Assert.That(decorator.NumberOfCallsToLoadObject, Is.EqualTo(1));
            Assert.That(decorator.NumberOfCallsToLoadRelatedObject, Is.EqualTo(0));

            Assert.That(
                clientTransaction.GetRelatedObject(
                    RelationEndPointID.Create(
                        classWithValidRelation.ID, "Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithValidRelations.ClassWithGuidKeyOptional")),
                Is.Null);

            Assert.That(decorator.NumberOfCallsToLoadObject, Is.EqualTo(1));
            Assert.That(decorator.NumberOfCallsToLoadRelatedObject, Is.EqualTo(0));

            clientTransaction.GetRelatedObject(
                RelationEndPointID.Create(classWithValidRelation.ID, "Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithValidRelations.ClassWithGuidKeyOptional"));

            Assert.That(decorator.NumberOfCallsToLoadObject, Is.EqualTo(1));
            Assert.That(decorator.NumberOfCallsToLoadRelatedObject, Is.EqualTo(0));
        }
        public void Create_WithDefinition()
        {
            var endPointID = RelationEndPointID.Create(_objectID, _endPointDefinition);

            Assert.That(endPointID.Definition, Is.EqualTo(_endPointDefinition));
            Assert.That(endPointID.ObjectID, Is.EqualTo(_objectID));
        }
        public void Create_WithPropertyIdentifier()
        {
            var endPointID = RelationEndPointID.Create(_objectID, _propertyName);

            Assert.That(endPointID.Definition, Is.EqualTo(_endPointDefinition));
            Assert.That(endPointID.ObjectID, Is.EqualTo(_objectID));
        }
        public void StaticEquals()
        {
            var id1 = RelationEndPointID.Create(_objectID, _propertyName);
            var id2 = RelationEndPointID.Create(_objectID, _propertyName);

            Assert.That(RelationEndPointID.Equals(id1, id2), Is.True);
        }
        public void EqualityOperatorID1Null()
        {
            var id2 = RelationEndPointID.Create(DomainObjectIDs.OrderTicket1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderTicket.Order");

            Assert.That(null == id2, Is.False);
            Assert.That(null != id2, Is.True);
        }
        public void DelegatingMembers()
        {
            var objectID              = DomainObjectIDs.Order1;
            var dataContainer         = DataContainer.CreateNew(objectID);
            var relationEndPointID    = RelationEndPointID.Create(objectID, typeof(Order), "OrderTicket");
            var virtualEndPoint       = MockRepository.GenerateStub <IVirtualEndPoint>();
            var domainObject          = DomainObjectMother.CreateFakeObject <Order>();
            var persistableData       = new PersistableData(domainObject, StateType.Unchanged, dataContainer, new IRelationEndPoint[0]);
            var dataManagementCommand = MockRepository.GenerateStub <IDataManagementCommand> ();
            var randomBoolean         = BooleanObjectMother.GetRandomBoolean();

            CheckDelegation(dm => dm.GetOrCreateVirtualEndPoint(relationEndPointID), virtualEndPoint);
            CheckDelegation(dm => dm.GetRelationEndPointWithLazyLoad(relationEndPointID), virtualEndPoint);
            CheckDelegation(dm => dm.GetRelationEndPointWithoutLoading(relationEndPointID), virtualEndPoint);
            CheckDelegation(dm => dm.GetDataContainerWithoutLoading(objectID), dataContainer);
            CheckDelegation(dm => dm.RegisterDataContainer(dataContainer));
            CheckDelegation(dm => dm.Discard(dataContainer));
            CheckDelegation(dm => dm.DataContainers, MockRepository.GenerateStub <IDataContainerMapReadOnlyView> ());
            CheckDelegation(dm => dm.RelationEndPoints, MockRepository.GenerateStub <IRelationEndPointMapReadOnlyView> ());
            CheckDelegation(dm => dm.GetState(objectID), StateType.Deleted);
            CheckDelegation(dm => dm.GetDataContainerWithLazyLoad(objectID, randomBoolean), dataContainer);
            CheckDelegation(dm => dm.GetDataContainersWithLazyLoad(new[] { objectID }, true), new[] { dataContainer });
            CheckDelegation(dm => dm.GetLoadedDataByObjectState(StateType.Unchanged), new[] { persistableData });
            CheckDelegation(dm => dm.MarkInvalid(domainObject));
            CheckDelegation(dm => dm.MarkNotInvalid(objectID));
            CheckDelegation(dm => dm.Commit());
            CheckDelegation(dm => dm.Rollback());
            CheckDelegation(dm => dm.CreateDeleteCommand(domainObject), dataManagementCommand);
            CheckDelegation(dm => dm.CreateUnloadCommand(new[] { objectID }), dataManagementCommand);
            CheckDelegation(dm => dm.CreateUnloadVirtualEndPointsCommand(new[] { relationEndPointID }), dataManagementCommand);
            CheckDelegation(dm => dm.CreateUnloadAllCommand(), dataManagementCommand);
            CheckDelegation(dm => dm.LoadLazyCollectionEndPoint(relationEndPointID));
            CheckDelegation(dm => dm.LoadLazyVirtualObjectEndPoint(relationEndPointID));
            CheckDelegation(dm => dm.LoadLazyDataContainer(objectID), dataContainer);
        }
Esempio n. 7
0
        public void RegisterEndPoint_RealEndPoint_PointingToNonNull_OppositeObjectEndPoint_VirtualEndPointNotYetComplete()
        {
            var objectReference = DomainObjectMother.CreateFakeObject <OrderItem> ();

            var endPointMock = CreateRealObjectEndPointMock(DomainObjectIDs.OrderTicket1, "Order", DomainObjectIDs.Order1);

            endPointMock.Stub(stub => stub.GetDomainObjectReference()).Return(objectReference);

            var oppositeEndPointMock = MockRepository.GenerateStrictMock <IVirtualObjectEndPoint> ();

            oppositeEndPointMock.Stub(stub => stub.IsDataComplete).Return(false);
            oppositeEndPointMock.Expect(mock => mock.RegisterOriginalOppositeEndPoint(endPointMock));
            oppositeEndPointMock.Expect(mock => mock.MarkDataComplete(objectReference));
            oppositeEndPointMock.Replay();

            var oppositeEndPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderTicket");

            _virtualEndPointProviderMock
            .Expect(mock => mock.GetOrCreateVirtualEndPoint(oppositeEndPointID))
            .Return(oppositeEndPointMock);
            _virtualEndPointProviderMock.Replay();

            _agent.RegisterEndPoint(endPointMock, _map);

            endPointMock.VerifyAllExpectations();
            _virtualEndPointProviderMock.VerifyAllExpectations();
            oppositeEndPointMock.VerifyAllExpectations();
            Assert.That(_map, Has.Member(endPointMock));
        }
Esempio n. 8
0
        public override void SetUp()
        {
            base.SetUp();

            _customerEndPointID = RelationEndPointID.Create(DomainObjectIDs.Customer1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders");
            _order1             = DomainObjectIDs.Order1.GetObject <Order> ();
            _order3             = DomainObjectIDs.Order3.GetObject <Order> ();

            _fakeCollection           = new OrderCollection();
            _collectionManagerMock    = MockRepository.GenerateStrictMock <ICollectionEndPointCollectionManager> ();
            _lazyLoaderMock           = MockRepository.GenerateMock <ILazyLoader> ();
            _endPointProviderStub     = MockRepository.GenerateStub <IRelationEndPointProvider> ();
            _transactionEventSinkStub = MockRepository.GenerateStub <IClientTransactionEventSink> ();
            _dataManagerFactoryStub   = MockRepository.GenerateStub <ICollectionEndPointDataManagerFactory> ();
            _loadStateMock            = MockRepository.GenerateStrictMock <ICollectionEndPointLoadState> ();

            _endPoint = new CollectionEndPoint(
                TestableClientTransaction,
                _customerEndPointID,
                _collectionManagerMock,
                _lazyLoaderMock,
                _endPointProviderStub,
                _transactionEventSinkStub,
                _dataManagerFactoryStub);
            PrivateInvoke.SetNonPublicField(_endPoint, "_loadState", _loadStateMock);
            _endPointProviderStub.Stub(stub => stub.GetOrCreateVirtualEndPoint(_customerEndPointID)).Return(_endPoint);

            _relatedEndPointStub = MockRepository.GenerateStub <IRealObjectEndPoint> ();
        }
        public void UnloadVirtualEndPointAndItemData_AnonymousEndPoint()
        {
            var anonymousEndPointDefinition = GetEndPointDefinition(typeof(Location), "Client").GetOppositeEndPointDefinition();
            var endPointID = RelationEndPointID.Create(DomainObjectIDs.Client1, anonymousEndPointDefinition);

            UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, endPointID);
        }
Esempio n. 10
0
        public void CreateUnregisterCommandForDataContainer_WithMultipleUnregisterableEndPoints()
        {
            var dataContainer = DataContainer.CreateNew(DomainObjectIDs.Order1);
            var endPoint1     = MockRepository.GenerateStub <IVirtualObjectEndPoint> ();

            endPoint1.Stub(stub => stub.ID).Return(RelationEndPointID.Create(dataContainer.ID, typeof(Order), "OrderTicket"));
            endPoint1.Stub(stub => stub.Definition).Return(endPoint1.ID.Definition);
            endPoint1.Stub(stub => stub.OppositeObjectID).Return(DomainObjectIDs.OrderTicket1);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPoint1);

            var endPoint2 = MockRepository.GenerateStub <IRealObjectEndPoint> ();

            endPoint2.Stub(stub => stub.ID).Return(RelationEndPointID.Create(dataContainer.ID, typeof(Order), "Customer"));
            endPoint2.Stub(stub => stub.Definition).Return(endPoint2.ID.Definition);
            endPoint2.Stub(stub => stub.OriginalOppositeObjectID).Return(DomainObjectIDs.Customer1);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPoint2);

            var command = _relationEndPointManager.CreateUnregisterCommandForDataContainer(dataContainer);

            Assert.That(command, Is.TypeOf <ExceptionCommand> ());
            Assert.That(
                ((ExceptionCommand)command).Exception.Message,
                Is.EqualTo(
                    "The relations of object 'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid' cannot be unloaded.\r\n"
                    + "Relation end-point "
                    + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket' "
                    + "would leave a dangling reference.\r\n"
                    + "Relation end-point "
                    + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer' "
                    + "would leave a dangling reference."));
        }
Esempio n. 11
0
        public void CreateUnloadVirtualEndPointsCommand()
        {
            var endPointID1 = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderItems");
            var endPointID2 = RelationEndPointID.Create(DomainObjectIDs.Order3, typeof(Order), "OrderItems");

            var endPointStub1 = MockRepository.GenerateStub <IVirtualEndPoint> ();

            endPointStub1.Stub(stub => stub.ID).Return(endPointID1);
            endPointStub1.Stub(stub => stub.CanBeMarkedIncomplete).Return(true);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub1);

            var endPointStub2 = MockRepository.GenerateStub <IVirtualEndPoint> ();

            endPointStub2.Stub(stub => stub.ID).Return(endPointID2);
            endPointStub2.Stub(stub => stub.CanBeMarkedIncomplete).Return(true);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub2);

            var result = _relationEndPointManager.CreateUnloadVirtualEndPointsCommand(new[] { endPointID1, endPointID2 });

            Assert.That(
                result,
                Is.TypeOf <UnloadVirtualEndPointsCommand>()
                .With.Property("VirtualEndPoints").EqualTo(new[] { endPointStub1, endPointStub2 })
                .And.Property("RelationEndPointMap").SameAs(_relationEndPointManager.RelationEndPoints)
                .And.Property("RegistrationAgent").SameAs(_relationEndPointManager.RegistrationAgent));
        }
Esempio n. 12
0
        public void CreateUnregisterCommandForDataContainer_WithUnregisterableEndPoint_DueToChangedOpposite()
        {
            var dataContainer = DataContainer.CreateForExisting(DomainObjectIDs.Order1, null, pd => pd.DefaultValue);
            var endPoint      = MockRepository.GenerateStub <IRealObjectEndPoint> ();

            endPoint.Stub(stub => stub.ID).Return(RelationEndPointID.Create(dataContainer.ID, typeof(Order), "Customer"));
            endPoint.Stub(stub => stub.Definition).Return(endPoint.ID.Definition);
            endPoint.Stub(stub => stub.HasChanged).Return(false);
            endPoint.Stub(stub => stub.OppositeObjectID).Return(DomainObjectIDs.Customer1);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPoint);

            var oppositeEndPoint = MockRepository.GenerateStub <IVirtualEndPoint> ();

            oppositeEndPoint.Stub(stub => stub.ID).Return(RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders"));
            oppositeEndPoint.Stub(stub => stub.Definition).Return(oppositeEndPoint.ID.Definition);
            oppositeEndPoint.Stub(stub => stub.HasChanged).Return(true);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, oppositeEndPoint);

            var command = _relationEndPointManager.CreateUnregisterCommandForDataContainer(dataContainer);

            Assert.That(command, Is.TypeOf <ExceptionCommand> ());
            Assert.That(((ExceptionCommand)command).Exception, Is.TypeOf <InvalidOperationException> ());
            Assert.That(((ExceptionCommand)command).Exception.Message, Is.EqualTo(
                            "The relations of object 'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid' cannot be unloaded.\r\n"
                            + "The opposite relation property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders' of relation end-point "
                            + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer' has changed. "
                            + "Non-virtual end-points that are part of changed relations cannot be unloaded."));
        }
Esempio n. 13
0
        public void GetEndPointWithOppositeDefinition_ID_InvalidType()
        {
            var id       = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order).FullName + ".Customer");
            var endPoint = RelationEndPointObjectMother.CreateObjectEndPoint(id, null);

            endPoint.GetEndPointWithOppositeDefinition <IObjectEndPoint> ((ObjectID)null);
        }
        public void GetOptionalRelatedObjectOverVirtualEndPointTwice()
        {
            var id = new ObjectID("ClassWithGuidKey", new Guid("{672C8754-C617-4b7a-890C-BFEF8AC86564}"));

            CountingObjectLoaderDecorator decorator = null;
            var clientTransactionMock = ClientTransactionObjectMother.CreateTransactionWithObjectLoaderDecorator <TestableClientTransaction> (
                loader => decorator ?? (decorator = new CountingObjectLoaderDecorator(loader)));

            DomainObject classWithGuidKey = clientTransactionMock.GetObject(id, false);

            Assert.That(decorator.NumberOfCallsToLoadObject, Is.EqualTo(1));
            Assert.That(decorator.NumberOfCallsToLoadRelatedObject, Is.EqualTo(0));

            Assert.That(
                clientTransactionMock.GetRelatedObject(
                    RelationEndPointID.Create(
                        classWithGuidKey.ID, "Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithGuidKey.ClassWithValidRelationsOptional")),
                Is.Null);

            Assert.That(decorator.NumberOfCallsToLoadObject, Is.EqualTo(1));
            Assert.That(decorator.NumberOfCallsToLoadRelatedObject, Is.EqualTo(1));

            clientTransactionMock.GetRelatedObject(
                RelationEndPointID.Create(classWithGuidKey.ID, "Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithGuidKey.ClassWithValidRelationsOptional"));

            Assert.That(decorator.NumberOfCallsToLoadObject, Is.EqualTo(1));
            Assert.That(decorator.NumberOfCallsToLoadRelatedObject, Is.EqualTo(1));
        }
Esempio n. 15
0
        public void Synchronize_AnonymousEndPoint()
        {
            var locationClientEndPoint = RelationEndPointID.Create(DomainObjectIDs.Location1, typeof(Location), "Client");
            var endPointID             = RelationEndPointID.Create(DomainObjectIDs.Client1, locationClientEndPoint.Definition.GetOppositeEndPointDefinition());

            BidirectionalRelationSyncService.Synchronize(_transaction, endPointID);
        }
Esempio n. 16
0
 public void HasBeenTouched_FromManyPropertyAdd()
 {
     CheckTouching(delegate { _newCustomer.Orders.Add(_order1); }, _order1, "Customer",
                   RelationEndPointID.Create(_order1.ID, typeof(Order).FullName + ".Customer"),
                   RelationEndPointID.Create(_newCustomer.ID, typeof(Customer).FullName + ".Orders"),
                   RelationEndPointID.Create(_oldCustomer.ID, typeof(Customer).FullName + ".Orders"));
 }
        public void RelationChanging_LoadedObject_ForbiddenWhenEndPointCompleteInSubTransaction()
        {
            ClientTransactionTestHelper.SetIsWriteable(_transaction, false);

            _listener.AddCurrentlyLoadingObjectIDs(new[] { DomainObjectIDs.Order1 });
            Assert.That(_listener.IsInLoadMode, Is.True);

            var fakeSubTransaction = CreateFakeSubTransaction(_transaction);

            var relationEndPointID = RelationEndPointID.Create(_order1.ID, _orderTicketEndPointDefinition);

            // Works if there is no matching end-point in the subtx.
            Assert.That(ClientTransactionTestHelper.GetIDataManager(fakeSubTransaction).RelationEndPoints[relationEndPointID], Is.Null);
            Assert.That(() => _listener.RelationChanging(_transaction, _order1, _orderTicketEndPointDefinition, null, null), Throws.Nothing);

            fakeSubTransaction.EnsureDataComplete(relationEndPointID);
            var relationEndPoint = (IVirtualEndPoint)ClientTransactionTestHelper.GetIDataManager(fakeSubTransaction).RelationEndPoints[relationEndPointID];

            // Still works if the matching end-point is incomplete
            relationEndPoint.MarkDataIncomplete();
            Assert.That(ClientTransactionTestHelper.GetIDataManager(fakeSubTransaction).RelationEndPoints[relationEndPointID].IsDataComplete, Is.False);
            Assert.That(() => _listener.RelationChanging(_transaction, _order1, _orderTicketEndPointDefinition, null, null), Throws.Nothing);

            // Throws if the matching end-point is complete
            relationEndPoint.EnsureDataComplete();
            Assert.That(ClientTransactionTestHelper.GetIDataManager(fakeSubTransaction).RelationEndPoints[relationEndPointID].IsDataComplete, Is.True);
            Assert.That(
                () => _listener.RelationChanging(_transaction, _order1, _orderTicketEndPointDefinition, null, null),
                Throws.InvalidOperationException.With.Message.EqualTo(
                    "The relation property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket' of object "
                    + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid' can no longer be modified because its "
                    + "data has already been loaded into the subtransaction."));
        }
Esempio n. 18
0
 public void HasBeenTouched_FromManyPropertyReplace_OriginalValue()
 {
     CheckTouching(delegate { _oldCustomer.Orders[_oldCustomer.Orders.IndexOf(_order1)] = _order1; }, _order1, "Customer",
                   RelationEndPointID.Create(_order1.ID, typeof(Order).FullName + ".Customer"),
                   RelationEndPointID.Create(_oldCustomer.ID, typeof(Customer).FullName + ".Orders"),
                   RelationEndPointID.Create(_oldCustomer.ID, typeof(Customer).FullName + ".Orders"));
 }
Esempio n. 19
0
        public void RegisterEndPoint_RealEndPoint_PointingToNonNull_OppositeCollectionEndPoint()
        {
            var endPointMock = CreateRealObjectEndPointMock(DomainObjectIDs.OrderItem1, "Order", DomainObjectIDs.Order1);

            var oppositeEndPointMock = MockRepository.GenerateStrictMock <ICollectionEndPoint> ();

            oppositeEndPointMock.Stub(stub => stub.IsDataComplete).Return(false);
            oppositeEndPointMock.Expect(mock => mock.RegisterOriginalOppositeEndPoint(endPointMock));
            oppositeEndPointMock.Replay();

            var oppositeEndPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderItems");

            _virtualEndPointProviderMock
            .Expect(mock => mock.GetOrCreateVirtualEndPoint(oppositeEndPointID))
            .Return(oppositeEndPointMock);
            _virtualEndPointProviderMock.Replay();

            _agent.RegisterEndPoint(endPointMock, _map);

            endPointMock.VerifyAllExpectations();
            _virtualEndPointProviderMock.VerifyAllExpectations();

            oppositeEndPointMock.AssertWasNotCalled(mock => mock.MarkDataComplete(Arg <DomainObject[]> .Is.Anything));
            oppositeEndPointMock.VerifyAllExpectations();

            Assert.That(_map, Has.Member(endPointMock));
        }
Esempio n. 20
0
        public void EagerFetching_OnLoadedMethod_CanAlreadyAccessFetchedRelation_WithoutGoingToThePersistenceLayer()
        {
            var ordersQuery = CreateOrdersQuery("OrderNo IN (1)");

            AddOrderItemsFetchQuery(ordersQuery, "o.OrderNo IN (1)");

            var id1 = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderItems");

            bool onLoadedRaised = false;

            var order1Reference = DomainObjectIDs.Order1.GetObjectReference <Order>();

            order1Reference.ProtectedLoaded += (sender, args) =>
            {
                var persistenceExtensionMock = MockRepository.GenerateStrictMock <IPersistenceExtension>();
                using (ScopeWithPersistenceExtension(persistenceExtensionMock))
                {
                    Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(id1), Is.Not.Null);
                    Assert.That(
                        order1Reference.OrderItems,
                        Is.EquivalentTo(
                            new[] { DomainObjectIDs.OrderItem1.GetObjectReference <OrderItem>(), DomainObjectIDs.OrderItem2.GetObjectReference <OrderItem>() }));

                    persistenceExtensionMock.AssertWasNotCalled(mock => mock.ConnectionOpened(Arg <Guid> .Is.Anything));
                }
                onLoadedRaised = true;
            };

            Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(id1), Is.Null);

            TestableClientTransaction.QueryManager.GetCollection(ordersQuery);

            Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(id1), Is.Not.Null);
            Assert.That(onLoadedRaised, Is.True);
        }
Esempio n. 21
0
        public override void SetUp()
        {
            base.SetUp();

            _endPointID          = RelationEndPointID.Create(DomainObjectIDs.Order1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket");
            _endPointPartialMock = MockRepository.GeneratePartialMock <TestableObjectEndPoint> (TestableClientTransaction, _endPointID);
        }
        public override void RelationChanging(
            ClientTransaction clientTransaction,
            DomainObject domainObject,
            IRelationEndPointDefinition relationEndPointDefinition,
            DomainObject oldRelatedObject,
            DomainObject newRelatedObject)
        {
            ArgumentUtility.CheckNotNull("clientTransaction", clientTransaction);
            ArgumentUtility.CheckNotNull("domainObject", domainObject);
            ArgumentUtility.CheckNotNull("relationEndPointDefinition", relationEndPointDefinition);

            if (IsInLoadMode)
            {
                CheckModifiedObjectID(domainObject.ID, relationEndPointDefinition.PropertyName);
                // This is here mostly for defensiveness purposes; it would be very difficult to construct a scenario where this is triggered.
                // There is no integration test for this check.
                if (clientTransaction.SubTransaction != null)
                {
                    var endPointID = RelationEndPointID.Create(domainObject.ID, relationEndPointDefinition);
                    var endPointInSubTransaction = clientTransaction.SubTransaction.DataManager.RelationEndPoints[endPointID];
                    if (endPointInSubTransaction != null && endPointInSubTransaction.IsDataComplete)
                    {
                        var message = string.Format(
                            "The relation property '{0}' of object '{1}' can no longer be modified because its data has already been loaded into the subtransaction.",
                            relationEndPointDefinition.PropertyName,
                            domainObject.ID);
                        throw new InvalidOperationException(message);
                    }
                }
            }
            else
            {
                base.RelationChanging(clientTransaction, domainObject, relationEndPointDefinition, oldRelatedObject, newRelatedObject);
            }
        }
        public void StaticNotEquals()
        {
            var id1 = RelationEndPointID.Create(_objectID, _propertyName);
            var id2 = RelationEndPointID.Create(DomainObjectIDs.OrderTicket1, "Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderTicket.Order");

            Assert.That(RelationEndPointID.Equals(id1, id2), Is.False);
        }
        private void RegisterEndPointData(
            IRelationEndPointDefinition relationEndPointDefinition,
            IEnumerable <ILoadedObjectData> originatingObjects,
            IDictionary <ObjectID, ILoadedObjectData> groupedRelatedObjects)
        {
            var relatedObjectsByOriginalObject = groupedRelatedObjects;

            foreach (var originatingObject in originatingObjects)
            {
                if (!originatingObject.IsNull && originatingObject.ObjectID.ClassDefinition.IsRelationEndPoint(relationEndPointDefinition))
                {
                    var relationEndPointID = RelationEndPointID.Create(originatingObject.ObjectID, relationEndPointDefinition);
                    var relatedObjectData  = relatedObjectsByOriginalObject.GetValueOrDefault(originatingObject.ObjectID) ?? new NullLoadedObjectData();
                    var relatedObject      = relatedObjectData.GetDomainObjectReference();
                    if (relationEndPointDefinition.IsMandatory && relatedObject == null)
                    {
                        var message = string.Format(
                            "The fetched mandatory relation property '{0}' on object '{1}' contains no related object.",
                            relationEndPointDefinition.PropertyName,
                            relationEndPointID.ObjectID);
                        throw new InvalidOperationException(message);
                    }
                    if (!TrySetVirtualObjectEndPointData(relationEndPointID, relatedObject))
                    {
                        s_log.DebugFormat("Relation data for relation end-point '{0}' is discarded; the end-point has already been loaded.", relationEndPointID);
                    }
                }
            }
        }
        public void EqualityOperatorID2Null()
        {
            var id1 = RelationEndPointID.Create(_objectID, _propertyName);

            Assert.That(id1 == null, Is.False);
            Assert.That(id1 != null, Is.True);
        }
Esempio n. 26
0
        public void GetUnregisterProblem_OppositeLoadedEndPointHasChanged()
        {
            var relationEndPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "Customer");

            var endPointStub = MockRepository.GenerateStub <IRealObjectEndPoint> ();

            endPointStub.Stub(stub => stub.HasChanged).Return(false);
            endPointStub.Stub(stub => stub.ID).Return(relationEndPointID);
            endPointStub.Stub(stub => stub.Definition).Return(relationEndPointID.Definition);
            endPointStub.Stub(stub => stub.OppositeObjectID).Return(DomainObjectIDs.Customer1);

            var oppositeEndPointID   = RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders");
            var oppositeEndPointStub = MockRepository.GenerateStub <IRealObjectEndPoint> ();

            oppositeEndPointStub.Stub(stub => stub.ID).Return(oppositeEndPointID);
            oppositeEndPointStub.Stub(stub => stub.Definition).Return(oppositeEndPointID.Definition);
            oppositeEndPointStub.Stub(stub => stub.HasChanged).Return(true);
            _map.AddEndPoint(oppositeEndPointStub);

            var result = (string)PrivateInvoke.InvokeNonPublicMethod(_agent, "GetUnregisterProblem", endPointStub, _map);

            Assert.That(result, Is.EqualTo(
                            "The opposite relation property "
                            + "'Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders' of relation end-point "
                            + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer' has changed. "
                            + "Non-virtual end-points that are part of changed relations cannot be unloaded."));
        }
        public void Create_WithDefinition_NullObjectID()
        {
            var endPointID = RelationEndPointID.Create(null, _endPointDefinition);

            Assert.That(endPointID.Definition, Is.EqualTo(_endPointDefinition));
            Assert.That(endPointID.ObjectID, Is.Null);
        }
Esempio n. 28
0
        public void Synchronize_InTransactionHierarchy_StartsWithRoot()
        {
            var endPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderItems");

            var endPointMockInParent = MockRepository.GenerateStrictMock <IRelationEndPoint> ();

            endPointMockInParent.Stub(stub => stub.ID).Return(endPointID);
            endPointMockInParent.Stub(stub => stub.Definition).Return(endPointID.Definition);
            endPointMockInParent.Stub(stub => stub.IsDataComplete).Return(true);
            endPointMockInParent.Expect(mock => mock.Synchronize());
            endPointMockInParent.Replay();
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointMockInParent);

            var subTransaction    = _transaction.CreateSubTransaction();
            var endPointMockInSub = MockRepository.GenerateStrictMock <IRelationEndPoint> ();

            endPointMockInSub.Stub(stub => stub.ID).Return(endPointID);
            endPointMockInSub.Stub(stub => stub.Definition).Return(endPointID.Definition);
            endPointMockInSub.Stub(stub => stub.IsDataComplete).Return(true);
            endPointMockInSub.Expect(mock => mock.Synchronize());
            endPointMockInSub.Replay();
            DataManagerTestHelper.AddEndPoint(ClientTransactionTestHelper.GetDataManager(subTransaction), endPointMockInSub);

            BidirectionalRelationSyncService.Synchronize(subTransaction, endPointID);

            endPointMockInParent.VerifyAllExpectations();
            endPointMockInSub.VerifyAllExpectations();
        }
        public void Create_WithTypeAndPropertyName()
        {
            var endPointID = RelationEndPointID.Create(_objectID, typeof(Order), "OrderTicket");

            Assert.That(endPointID.Definition, Is.EqualTo(_endPointDefinition));
            Assert.That(endPointID.ObjectID, Is.EqualTo(_objectID));
        }
Esempio n. 30
0
        public void RelationEndPointManager_Content()
        {
            DomainObjectIDs.Order1.GetObject <Order> ().OrderItems.EnsureDataComplete();
            Assert.That(_relationEndPointManager.RelationEndPoints.Count, Is.EqualTo(7));

            var deserializedManager = (RelationEndPointManager)DataManagerTestHelper.GetRelationEndPointManager(
                Serializer.SerializeAndDeserialize(TestableClientTransaction.DataManager));

            Assert.That(deserializedManager.ClientTransaction, Is.Not.Null);
            Assert.That(deserializedManager.ClientTransaction, Is.InstanceOf(typeof(TestableClientTransaction)));
            Assert.That(deserializedManager.ClientTransaction, Is.Not.SameAs(TestableClientTransaction));
            Assert.That(deserializedManager.LazyLoader, Is.Not.Null);
            Assert.That(deserializedManager.LazyLoader, Is.TypeOf(_relationEndPointManager.LazyLoader.GetType()));
            Assert.That(deserializedManager.EndPointFactory, Is.Not.Null);
            Assert.That(deserializedManager.EndPointFactory, Is.TypeOf(_relationEndPointManager.EndPointFactory.GetType()));
            Assert.That(deserializedManager.RegistrationAgent, Is.TypeOf(_relationEndPointManager.RegistrationAgent.GetType()));
            Assert.That(deserializedManager.DataContainerEndPointsRegistrationAgent, Is.Not.Null);

            Assert.That(deserializedManager.RelationEndPoints.Count, Is.EqualTo(7));

            var endPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, ReflectionMappingHelper.GetPropertyName(typeof(Order), "OrderItems"));
            var endPoint   = (ICollectionEndPoint)deserializedManager.GetRelationEndPointWithoutLoading(endPointID);

            Assert.That(endPoint.ClientTransaction, Is.SameAs(deserializedManager.ClientTransaction));
        }