public override void SetUp() { base.SetUp(); _order1 = DomainObjectIDs.Order1.GetObject <Order> (Transaction); _order2 = DomainObjectIDs.Order2.GetObject <Order> (Transaction); _order3 = DomainObjectIDs.Order3.GetObject <Order> (Transaction); // Collection currently contains _order1, _order2 _modifiedCollectionData = new DomainObjectCollectionData(new[] { _order1, _order2 }); // _order1 will stay, _order2 will be removed, _order3 will be added _newCollection = new OrderCollection { _order1, _order3 }; _mockRepository = new MockRepository(); _collectionManagerMock = _mockRepository.StrictMock <ICollectionEndPointCollectionManager> (); _command = new CollectionEndPointSetCollectionCommand( CollectionEndPoint, _newCollection, _modifiedCollectionData, _collectionManagerMock, TransactionEventSinkMock); }
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 CollectionEndPointSetCollectionCommand( ICollectionEndPoint modifiedEndPoint, DomainObjectCollection newCollection, IDomainObjectCollectionData modifiedCollectionData, ICollectionEndPointCollectionManager collectionEndPointCollectionManager, IClientTransactionEventSink transactionEventSink) : base( ArgumentUtility.CheckNotNull("modifiedEndPoint", modifiedEndPoint), null, null, ArgumentUtility.CheckNotNull("transactionEventSink", transactionEventSink)) { ArgumentUtility.CheckNotNull("newCollection", newCollection); ArgumentUtility.CheckNotNull("modifiedCollectionData", modifiedCollectionData); ArgumentUtility.CheckNotNull("collectionEndPointCollectionManager", collectionEndPointCollectionManager); if (modifiedEndPoint.IsNull) { throw new ArgumentException("Modified end point is null, a NullEndPointModificationCommand is needed.", "modifiedEndPoint"); } _newCollection = newCollection; _modifiedCollectionData = modifiedCollectionData; _collectionEndPointCollectionManager = collectionEndPointCollectionManager; var oldOppositeObjects = ModifiedCollectionData; _removedObjects = oldOppositeObjects.Where(oldObject => !NewCollection.Contains(oldObject.ID)).ToArray(); var newOppositeObjects = NewCollection.Cast <DomainObject> (); _addedObjects = newOppositeObjects.Where(newObject => !ModifiedCollectionData.ContainsObjectID(newObject.ID)).ToArray(); }
public IDataManagementCommand CreateSetCollectionCommand( ICollectionEndPoint collectionEndPoint, DomainObjectCollection newCollection, ICollectionEndPointCollectionManager collectionEndPointCollectionManager) { ArgumentUtility.CheckNotNull("collectionEndPoint", collectionEndPoint); ArgumentUtility.CheckNotNull("newCollection", newCollection); var completeState = EndPointLoader.LoadEndPointAndGetNewState(collectionEndPoint); return(completeState.CreateSetCollectionCommand(collectionEndPoint, newCollection, collectionEndPointCollectionManager)); }
protected CollectionEndPoint(FlattenedDeserializationInfo info) : base(info) { _collectionManager = info.GetValueForHandle <ICollectionEndPointCollectionManager>(); _lazyLoader = info.GetValueForHandle <ILazyLoader>(); _endPointProvider = info.GetValueForHandle <IRelationEndPointProvider> (); _transactionEventSink = info.GetValueForHandle <IClientTransactionEventSink> (); _dataManagerFactory = info.GetValueForHandle <ICollectionEndPointDataManagerFactory> (); _loadState = info.GetValue <ICollectionEndPointLoadState>(); _hasBeenTouched = info.GetBoolValue(); }
public override void SetUp() { base.SetUp(); _definition = Configuration.GetTypeDefinition(typeof(Customer)).GetRelationEndPointDefinition(typeof(Customer).FullName + ".Orders"); _collectionEndPointMock = MockRepository.GenerateStrictMock <ICollectionEndPoint>(); _dataManagerMock = MockRepository.GenerateStrictMock <ICollectionEndPointDataManager>(); _dataManagerMock.Stub(stub => stub.EndPointID).Return(RelationEndPointID.Create(DomainObjectIDs.Customer1, _definition)); _endPointProviderStub = MockRepository.GenerateStub <IRelationEndPointProvider> (); _transactionEventSinkStub = MockRepository.GenerateStub <IClientTransactionEventSink> (); _eventRaiserMock = MockRepository.GenerateStrictMock <IDomainObjectCollectionEventRaiser>(); _loadState = new CompleteCollectionEndPointLoadState(_dataManagerMock, _endPointProviderStub, _transactionEventSinkStub); _relatedObject = DomainObjectMother.CreateFakeObject <Order> (DomainObjectIDs.Order1); _relatedEndPointStub = MockRepository.GenerateStub <IRealObjectEndPoint> (); _relatedEndPointStub.Stub(stub => stub.GetDomainObjectReference()).Return(_relatedObject); _relatedEndPointStub.Stub(stub => stub.ObjectID).Return(_relatedObject.ID); _owningObject = DomainObjectMother.CreateFakeObject <Customer>(); _collectionManagerStub = MockRepository.GenerateStub <ICollectionEndPointCollectionManager> (); }
public IDataManagementCommand CreateSetCollectionCommand( ICollectionEndPoint collectionEndPoint, DomainObjectCollection newCollection, ICollectionEndPointCollectionManager collectionEndPointCollectionManager) { ArgumentUtility.CheckNotNull("collectionEndPoint", collectionEndPoint); ArgumentUtility.CheckNotNull("newCollection", newCollection); ArgumentUtility.CheckNotNull("collectionEndPointCollectionManager", collectionEndPointCollectionManager); if (UnsynchronizedOppositeEndPoints.Count != 0) { var message = string.Format( "The collection of relation property '{0}' of domain object '{1}' cannot be replaced because the opposite object property '{2}' of domain " + "object '{3}' is out of sync. To make this change, synchronize the two properties by calling the " + "'BidirectionalRelationSyncService.Synchronize' method on the '{2}' property.", DataManager.EndPointID.Definition.PropertyName, DataManager.EndPointID.ObjectID, DataManager.EndPointID.Definition.GetOppositeEndPointDefinition().PropertyName, UnsynchronizedOppositeEndPoints.First().ObjectID); throw new InvalidOperationException(message); } if (!IsSynchronized(collectionEndPoint)) { var message = string.Format( "The collection of relation property '{0}' of domain object '{1}' cannot be replaced because the relation property is out of sync with " + "the opposite object property '{2}' of domain object '{3}'. To make this change, synchronize the two properties by calling the " + "'BidirectionalRelationSyncService.Synchronize' method on the '{0}' property.", DataManager.EndPointID.Definition.PropertyName, DataManager.EndPointID.ObjectID, DataManager.EndPointID.Definition.GetOppositeEndPointDefinition().PropertyName, DataManager.OriginalItemsWithoutEndPoints.First().ID); throw new InvalidOperationException(message); } return(new CollectionEndPointSetCollectionCommand( collectionEndPoint, newCollection, DataManager.CollectionData, collectionEndPointCollectionManager, TransactionEventSink)); }
public CollectionEndPoint( ClientTransaction clientTransaction, RelationEndPointID id, ICollectionEndPointCollectionManager collectionManager, ILazyLoader lazyLoader, IRelationEndPointProvider endPointProvider, IClientTransactionEventSink transactionEventSink, ICollectionEndPointDataManagerFactory dataManagerFactory) : base(ArgumentUtility.CheckNotNull("clientTransaction", clientTransaction), ArgumentUtility.CheckNotNull("id", id)) { ArgumentUtility.CheckNotNull("collectionManager", collectionManager); ArgumentUtility.CheckNotNull("lazyLoader", lazyLoader); ArgumentUtility.CheckNotNull("endPointProvider", endPointProvider); ArgumentUtility.CheckNotNull("transactionEventSink", transactionEventSink); ArgumentUtility.CheckNotNull("dataManagerFactory", dataManagerFactory); if (id.Definition.Cardinality != CardinalityType.Many) { throw new ArgumentException("End point ID must refer to an end point with cardinality 'Many'.", "id"); } if (id.Definition.IsAnonymous) { throw new ArgumentException("End point ID must not refer to an anonymous end point.", "id"); } Assertion.IsTrue(ID.Definition.IsVirtual); _hasBeenTouched = false; _collectionManager = collectionManager; _lazyLoader = lazyLoader; _endPointProvider = endPointProvider; _transactionEventSink = transactionEventSink; _dataManagerFactory = dataManagerFactory; SetIncompleteLoadState(); }