protected override string GetUnregisterProblem(IRelationEndPoint endPoint, RelationEndPointMap relationEndPointMap) { ArgumentUtility.CheckNotNull("endPoint", endPoint); ArgumentUtility.CheckNotNull("relationEndPointMap", relationEndPointMap); // An end-point must be unchanged to be unregisterable. if (endPoint.HasChanged) { return(string.Format( "Relation end-point '{0}' has changed. Only unchanged relation end-points can be unregistered.", endPoint.ID)); } // If it is a real object end-point pointing to a non-null object, and the opposite end-point is loaded, the opposite (virtual) end-point // must be unchanged. Virtual end-points cannot exist in changed state without their opposite real end-points. // (This only affects 1:n relations: for those, the opposite virtual end-point can be changed although the (one of many) real end-point is // unchanged. For 1:1 relations, the real and virtual end-points always have an equal HasChanged flag.) var maybeOppositeEndPoint = Maybe .ForValue(endPoint as IRealObjectEndPoint) .Select(ep => RelationEndPointID.CreateOpposite(ep.Definition, ep.OppositeObjectID)) .Select(oppositeEndPointID => relationEndPointMap[oppositeEndPointID]); if (maybeOppositeEndPoint.Where(ep => ep.HasChanged).HasValue) { return(string.Format( "The opposite relation property '{0}' of relation end-point '{1}' has changed. Non-virtual end-points that are part of changed relations " + "cannot be unloaded.", maybeOppositeEndPoint.Value().Definition.PropertyName, endPoint.ID)); } return(null); }
protected override string GetUnregisterProblem(IRelationEndPoint endPoint, RelationEndPointMap relationEndPointMap) { ArgumentUtility.CheckNotNull("endPoint", endPoint); ArgumentUtility.CheckNotNull("relationEndPointMap", relationEndPointMap); var objectEndPoint = endPoint as IObjectEndPoint; if (objectEndPoint != null) { if (objectEndPoint.OppositeObjectID == null && objectEndPoint.OriginalOppositeObjectID == null) { return(null); } } else { var collectionEndPoint = (ICollectionEndPoint)endPoint; if (collectionEndPoint.GetData().Count == 0 && collectionEndPoint.GetOriginalData().Count == 0) { return(null); } } return(string.Format("Relation end-point '{0}' would leave a dangling reference.", endPoint.ID)); }
protected IRelationEndPoint GetOppositeEndPoint( IRelationEndPoint originatingEndPoint, DomainObject oppositeObject, IRelationEndPointProvider endPointProvider) { var oppositeEndPointID = RelationEndPointID.CreateOpposite(originatingEndPoint.Definition, oppositeObject.GetSafeID()); return(endPointProvider.GetRelationEndPointWithLazyLoad(oppositeEndPointID)); }
public override void SetUp() { base.SetUp(); _listener = NullClientTransactionListener.Instance; _domainObject = DomainObjectMother.CreateObjectInTransaction <Client> (TestableClientTransaction); _dataContainer = _domainObject.GetInternalDataContainerForTransaction(TestableClientTransaction); _propertyDefinition = GetPropertyDefinition(typeof(Client), "ParentClient"); _relationEndPoint = TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(_dataContainer.AssociatedRelationEndPointIDs[0]); }
void IFlattenedSerializable.SerializeIntoFlatStructure(FlattenedSerializationInfo info) { ArgumentUtility.CheckNotNull("info", info); info.AddHandle(_transactionEventSink); var endPointArray = new IRelationEndPoint[Count]; _relationEndPoints.Values.CopyTo(endPointArray, 0); info.AddArray(endPointArray); }
public override void SetUp() { base.SetUp(); _validator = new MandatoryRelationValidator(); _endPointMock = MockRepository.GenerateStrictMock <IRelationEndPoint>(); _mandatoryEndPointDefinition = GetEndPointDefinition(typeof(Order), "OrderTicket"); _nonMandatoryEndPointDefinition = GetEndPointDefinition(typeof(Computer), "Employee"); }
public override void SetUp() { base.SetUp(); _mockRepository = new MockRepository(); _id = RelationEndPointID.Create(DomainObjectIDs.Computer1, ReflectionMappingHelper.GetPropertyName(typeof(Computer), "Employee")); _endPointMock = _mockRepository.StrictMock <IRelationEndPoint> (); _command = new NullEndPointModificationCommand(_endPointMock); }
public override void SetUp() { base.SetUp(); _endPoint1 = MockRepository.GenerateStub <IRelationEndPoint> (); _endPoint2 = MockRepository.GenerateStub <IRelationEndPoint> (); _registrationAgentMock = MockRepository.GenerateStrictMock <IRelationEndPointRegistrationAgent>(); _map = new RelationEndPointMap(MockRepository.GenerateStub <IClientTransactionEventSink> ()); _command = new UnregisterEndPointsCommand(new[] { _endPoint1, _endPoint2 }, _registrationAgentMock, _map); }
public override void SetUp() { base.SetUp(); _transaction = new TestableClientTransaction(); var id = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order).FullName + ".Customer"); _endPoint = _transaction.ExecuteInScope(() => RelationEndPointObjectMother.CreateObjectEndPoint(id, null)); _command = new RelationEndPointTouchCommand(_endPoint); }
public void SetDataFromSubTransaction (IRelationEndPoint source) { var sourceCollectionEndPoint = ArgumentUtility.CheckNotNullAndType<StateUpdateRaisingCollectionEndPointDecorator> ("source", source); var hasChangedFastBefore = _innerEndPoint.HasChangedFast; try { _innerEndPoint.SetDataFromSubTransaction (sourceCollectionEndPoint.InnerEndPoint); } finally { RaiseStateUpdatedIfNecessary(hasChangedFastBefore); } }
public void GetOrCreateVirtualEndPoint_DoesNotSupportAnonymousEndPoints() { var client = DomainObjectIDs.Client2.GetObject <Client> (); var parentClientEndPointDefinition = client.ID.ClassDefinition.GetRelationEndPointDefinition(typeof(Client) + ".ParentClient"); IRelationEndPoint unidirectionalEndPoint = _relationEndPointManager.GetRelationEndPointWithLazyLoad(RelationEndPointID.Create(client.ID, parentClientEndPointDefinition)); Client parentClient = client.ParentClient; Assert.That(parentClient, Is.Not.Null); var anonymousEndPointDefinition = unidirectionalEndPoint.Definition.GetOppositeEndPointDefinition(); _relationEndPointManager.GetOrCreateVirtualEndPoint(RelationEndPointID.Create(parentClient.ID, anonymousEndPointDefinition)); }
public void AddEndPoint(IRelationEndPoint endPoint) { ArgumentUtility.CheckNotNull("endPoint", endPoint); _transactionEventSink.RaiseRelationEndPointMapRegisteringEvent(endPoint); var id = endPoint.ID; try { _relationEndPoints.Add(id, endPoint); } catch (ArgumentException ex) { var message = string.Format("A relation end-point with ID '{0}' has already been registered.", id); throw new InvalidOperationException(message, ex); } }
protected RelationEndPointModificationCommand( IRelationEndPoint modifiedEndPoint, DomainObject oldRelatedObject, DomainObject newRelatedObject, IClientTransactionEventSink transactionEventSink) { ArgumentUtility.CheckNotNull("modifiedEndPoint", modifiedEndPoint); ArgumentUtility.CheckNotNull("transactionEventSink", transactionEventSink); _modifiedEndPoint = modifiedEndPoint; _domainObject = modifiedEndPoint.GetDomainObject(); _oldRelatedObject = oldRelatedObject; _newRelatedObject = newRelatedObject; _transactionEventSink = transactionEventSink; }
public override sealed void SetDataFromSubTransaction(IRelationEndPoint source) { var sourceObjectEndPoint = ArgumentUtility.CheckNotNullAndType <ObjectEndPoint> ("source", source); if (Definition != sourceObjectEndPoint.Definition) { var message = string.Format( "Cannot set this end point's value from '{0}'; the end points do not have the same end point definition.", source.ID); throw new ArgumentException(message, "source"); } SetOppositeObjectDataFromSubTransaction(sourceObjectEndPoint); if (sourceObjectEndPoint.HasBeenTouched || HasChanged) { Touch(); } }
public void UnregisterEndPoint(IRelationEndPoint endPoint, RelationEndPointMap map) { ArgumentUtility.CheckNotNull("endPoint", endPoint); ArgumentUtility.CheckNotNull("map", map); if (map[endPoint.ID] != endPoint) { var message = string.Format("End-point '{0}' is not part of this map.\r\nParameter name: endPoint", endPoint.ID); throw new ArgumentException(message); } var realObjectEndPoint = endPoint as IRealObjectEndPoint; if (realObjectEndPoint != null) { UnregisterOppositeForRealObjectEndPoint(realObjectEndPoint, map); } map.RemoveEndPoint(endPoint.ID); }
public void RegisterEndPoint(IRelationEndPoint endPoint, RelationEndPointMap map) { ArgumentUtility.CheckNotNull("endPoint", endPoint); ArgumentUtility.CheckNotNull("map", map); if (map[endPoint.ID] != null) { var message = string.Format("A relation end-point with ID '{0}' has already been registered.", endPoint.ID); throw new InvalidOperationException(message); } map.AddEndPoint(endPoint); var realObjectEndPoint = endPoint as IRealObjectEndPoint; if (realObjectEndPoint != null) { RegisterOppositeForRealObjectEndPoint(realObjectEndPoint); } }
public static T GetEndPointWithOppositeDefinition <T> (this IRelationEndPoint endPoint, ObjectID oppositeObjectID) where T : IRelationEndPoint { ArgumentUtility.CheckNotNull("endPoint", endPoint); var oppositeDefinition = endPoint.Definition.GetOppositeEndPointDefinition(); var id = RelationEndPointID.Create(oppositeObjectID, oppositeDefinition); var oppositeEndPoint = endPoint.ClientTransaction.DataManager.GetRelationEndPointWithLazyLoad(id); if (!(oppositeEndPoint is T)) { var message = String.Format( "The opposite end point '{0}' is of type '{1}', not of type '{2}'.", oppositeEndPoint.ID, oppositeEndPoint.GetType(), typeof(T)); throw new InvalidOperationException(message); } return((T)oppositeEndPoint); }
public override void SetUp() { base.SetUp(); _transaction = new TestableClientTransaction(); _objectID = DomainObjectIDs.Order1; _domainObject = _transaction.ExecuteInScope(() => Order.NewObject()); _endPointDefinition = GetEndPointDefinition(typeof(Order), "OrderTicket"); _endPointMock = MockRepository.GenerateMock <IRelationEndPoint> (); _endPointMock.Stub(mock => mock.ClientTransaction).Return(_transaction); _endPointMock.Stub(mock => mock.ObjectID).Return(_objectID); _endPointMock.Stub(mock => mock.Definition).Return(_endPointDefinition); _endPointMock.Stub(mock => mock.GetDomainObject()).Return(_domainObject); _oldRelatedObject = _transaction.ExecuteInScope(() => OrderTicket.NewObject()); _newRelatedObject = _transaction.ExecuteInScope(() => OrderTicket.NewObject()); _transactionEventSinkWithMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>(); _command = CreateTestableCommand(); _commandPartialMock = CreateCommandPartialMock(); }
public static void AddEndPoint(RelationEndPointManager endPointManager, IRelationEndPoint endPoint) { var map = GetMap(endPointManager); map.AddEndPoint(endPoint); }
public NullEndPointModificationCommand(IRelationEndPoint affectedEndPoint) { _affectedEndPoint = affectedEndPoint; }
public void RaiseRelationEndPointMapRegisteringEvent(IRelationEndPoint endPoint) { _listenerCollection.RelationEndPointMapRegistering(_clientTransaction, endPoint); }
protected abstract string GetUnregisterProblem(IRelationEndPoint endPoint, RelationEndPointMap relationEndPointMap);
public static void ReplaceEndPoint(RelationEndPointManager endPointManager, IRelationEndPoint endPoint) { RemoveEndPoint(endPointManager, endPoint.ID); AddEndPoint(endPointManager, endPoint); }
public RelationEndPointTouchCommand(IRelationEndPoint endPoint) { _endPoint = endPoint; }
public static void AddEndPoint(DataManager dataManager, IRelationEndPoint endPoint) { RelationEndPointManagerTestHelper.AddEndPoint((RelationEndPointManager)GetRelationEndPointManager(dataManager), endPoint); }
public void SetDataFromSubTransaction(IRelationEndPoint source) { throw new InvalidOperationException("SetDataFromSubTransaction cannot be called on a NullObjectEndPoint."); }
public void RelationEndPointMapRegistering(ClientTransaction clientTransaction, IRelationEndPoint endPoint) { throw CreateException(); }
public void RelationEndPointMapRegistering(ClientTransaction clientTransaction, IRelationEndPoint endPoint) { if (s_log.IsDebugEnabled()) { s_log.DebugFormat("{0} RelationEndPointMapRegistering: {1}", clientTransaction.ID, endPoint.ID); } }
public override void SetDataFromSubTransaction(IRelationEndPoint source) { throw new NotImplementedException(); }
public virtual void RelationEndPointMapRegistering(ClientTransaction clientTransaction, IRelationEndPoint endPoint) { foreach (var listener in _listeners) { listener.RelationEndPointMapRegistering(clientTransaction, endPoint); } }