public void ExpandToAllRelatedObjects() { // Scenario: orderItem.Order = newOrder; var oldRelatedEndPointID = RelationEndPointID.Resolve(_oldRelatedObject, o => o.OrderItems); var oldRelatedEndPointMock = MockRepository.GenerateStrictMock <ICollectionEndPoint>(); var newRelatedEndPointID = RelationEndPointID.Resolve(_newRelatedObject, o => o.OrderItems); var newRelatedEndPointMock = MockRepository.GenerateStrictMock <ICollectionEndPoint>(); EndPointProviderStub.Stub(stub => stub.GetRelationEndPointWithLazyLoad(oldRelatedEndPointID)).Return(oldRelatedEndPointMock); EndPointProviderStub.Stub(stub => stub.GetRelationEndPointWithLazyLoad(newRelatedEndPointID)).Return(newRelatedEndPointMock); // oldOrder.OrderItems.Remove (orderItem) var fakeRemoveCommand = MockRepository.GenerateStub <IDataManagementCommand>(); fakeRemoveCommand.Stub(stub => stub.GetAllExceptions()).Return(new Exception[0]); oldRelatedEndPointMock.Expect(mock => mock.CreateRemoveCommand(_domainObject)).Return(fakeRemoveCommand); oldRelatedEndPointMock.Replay(); // newOrder.OrderItems.Add (orderItem); var fakeAddCommand = MockRepository.GenerateStub <IDataManagementCommand>(); fakeAddCommand.Stub(stub => stub.GetAllExceptions()).Return(new Exception[0]); newRelatedEndPointMock.Expect(mock => mock.CreateAddCommand(_domainObject)).Return(fakeAddCommand); newRelatedEndPointMock.Replay(); var bidirectionalModification = _command.ExpandToAllRelatedObjects(); oldRelatedEndPointMock.VerifyAllExpectations(); newRelatedEndPointMock.VerifyAllExpectations(); var steps = bidirectionalModification.GetNestedCommands(); Assert.That(steps.Count, Is.EqualTo(3)); // orderItem.Order = newOrder; Assert.That(steps[0], Is.SameAs(_command)); // newOrder.OrderItems.Add (orderItem); Assert.That(steps[1], Is.SameAs(fakeAddCommand)); // oldOrder.OrderItems.Remove (orderItem) Assert.That(steps[2], Is.SameAs(fakeRemoveCommand)); }
/// <summary> /// Synchronizes the given relation property with its opposite relation property/properties. /// </summary> /// <param name="clientTransaction">The <see cref="ClientTransaction"/> to synchronize the relation property in. In a transaction hierarchy, /// <see cref="Synchronize"/> affects the whole hierarchy, no matter to which transaction (root or sub-transaction) it is applied. </param> /// <param name="endPointID">The ID of the relation property to synchronize. This contains the ID of the originating object and the /// relation property to check.</param> /// <exception cref="ArgumentException"> /// <paramref name="endPointID"/> denotes a unidirectional (or anonymous) relation property. /// </exception> /// <exception cref="InvalidOperationException"> /// The relation property denoted by <paramref name="endPointID"/> has not yet been fully loaded into the given <paramref name="clientTransaction"/>. /// </exception> /// <remarks> /// <para> /// If <paramref name="endPointID"/> denotes an object-valued end-point that is out-of-sync with an opposite collection (eg., OrderItem.Order), /// the opposite collection /// (eg., Order.OrderItems) is adjusted to match the foreign key value. This results in the item being added to the collection. /// If <paramref name="endPointID"/> denotes a collection-valued end-point that is out-of-sync (eg., Order.OrderItems), the collection is /// synchronized with the opposite foreign key values. This results in all items being removed from the collection that do not have a foreign /// key value pointing at the collection. /// </para> /// <para> /// If the relation is already synchronized, this method does nothing. /// </para> /// <para> /// When a relation involving a <see cref="DomainObjectCollection"/> is synchronized, its current and original contents may be changed. /// For these changes, the <see cref="BidirectionalRelationAttribute.SortExpression"/> is not re-executed, the /// <see cref="DomainObjectCollection.Adding"/>/<see cref="DomainObjectCollection.Added"/> events are not raised (and the /// <see cref="DomainObjectCollection.OnAdding"/>/<see cref="DomainObjectCollection.OnAdded"/> methods not called), and no relation change /// events are raised. Because synchronization affects current and original relation value alike, the <see cref="DomainObject.State"/> of the /// <see cref="DomainObjects"/> involved in the relation is not changed. /// </para> /// </remarks> public static void Synchronize(ClientTransaction clientTransaction, RelationEndPointID endPointID) { ArgumentUtility.CheckNotNull("endPointID", endPointID); CheckNotUnidirectional(endPointID, "endPointID"); var currentTransaction = clientTransaction.RootTransaction; var endPoint = GetAndCheckLoadedEndPoint(endPointID, currentTransaction); while (endPoint != null) { endPoint.Synchronize(); currentTransaction = currentTransaction.SubTransaction; endPoint = currentTransaction != null?GetEndPoint(currentTransaction, endPointID) : null; } }
public void GetOwnedEndPointIDs() { var dataContainer = DataContainer.CreateNew(DomainObjectIDs.Order1); var result = (IEnumerable <RelationEndPointID>)PrivateInvoke.InvokeNonPublicMethod(_agent, "GetOwnedEndPointIDs", dataContainer); Assert.That( result, Is.EquivalentTo( new[] { RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderTicket"), RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderItems"), RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "Official"), RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "Customer") })); }
private OrderCollection CreateAssociatedCollectionWithEndPointStub() { var collectionEndPointStub = MockRepository.GenerateStub <ICollectionEndPoint> (); var endPointDataStub = new ReadOnlyCollectionDataDecorator(new DomainObjectCollectionData()); collectionEndPointStub.Stub(stub => stub.GetData()).Return(endPointDataStub); var virtualEndPointProviderStub = MockRepository.GenerateStub <IVirtualEndPointProvider>(); var endPointID = RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders"); virtualEndPointProviderStub.Stub(stub => stub.GetOrCreateVirtualEndPoint(endPointID)).Return(collectionEndPointStub); var delegatingStrategy = new EndPointDelegatingCollectionData(endPointID, virtualEndPointProviderStub); var associatedCollection = new OrderCollection(new ModificationCheckingCollectionDataDecorator(typeof(Order), delegatingStrategy)); Assert.That(DomainObjectCollectionDataTestHelper.GetAssociatedEndPoint(associatedCollection), Is.SameAs(collectionEndPointStub)); return(associatedCollection); }
public void UnloadVirtualEndPoint_ObjectEndPoint_EnsureDataComplete() { var order = DomainObjectIDs.Order1.GetObject <Order> (); _subTransaction.EnsureDataComplete(RelationEndPointID.Resolve(order, o => o.OrderTicket)); CheckVirtualEndPoint(_subTransaction, order, "OrderTicket", true); UnloadService.UnloadVirtualEndPoint(_subTransaction, RelationEndPointID.Resolve(order, o => o.OrderTicket)); CheckVirtualEndPoint(_subTransaction, order, "OrderTicket", false); CheckVirtualEndPoint(_subTransaction.ParentTransaction, order, "OrderTicket", false); _subTransaction.EnsureDataComplete(RelationEndPointID.Resolve(order, o => o.OrderTicket)); CheckVirtualEndPoint(_subTransaction, order, "OrderTicket", true); CheckVirtualEndPoint(_subTransaction.ParentTransaction, order, "OrderTicket", true); }
protected void CheckVirtualEndPointExistsAndComplete(RelationEndPointID endPointID, bool shouldEndPointExist, bool shouldDataBeComplete) { ArgumentUtility.CheckNotNull("endPointID", endPointID); CheckEndPointExists(endPointID, shouldEndPointExist); if (shouldEndPointExist) { var endPoint = DataManagementService.GetDataManager(ClientTransaction.Current).GetRelationEndPointWithoutLoading(endPointID); if (shouldDataBeComplete) { Assert.That(endPoint.IsDataComplete, Is.True, "End point '{0}' should have complete data.", endPoint.ID); } else { Assert.That(endPoint.IsDataComplete, Is.False, "End point '{0}' should not have complete data.", endPoint.ID); } } }
private void CheckClassIDForVirtualEndPoint( RelationEndPointID relationEndPointID, DataContainer oppositeDataContainer) { var oppositeEndPointDefinition = (RelationEndPointDefinition)relationEndPointID.Definition.GetOppositeEndPointDefinition(); var objectID = (ObjectID)oppositeDataContainer.GetValueWithoutEvents(oppositeEndPointDefinition.PropertyDefinition, ValueAccess.Current); if (relationEndPointID.ObjectID.ClassID != objectID.ClassID) { throw CreatePersistenceException( "The property '{0}' of the loaded DataContainer '{1}'" + " refers to ClassID '{2}', but the actual ClassID is '{3}'.", oppositeEndPointDefinition.PropertyName, oppositeDataContainer.ID, objectID.ClassID, relationEndPointID.ObjectID.ClassID); } }
public void GetRelatedObjectOverVirtualEndPoint() { DomainObject order = TestableClientTransaction.GetObject(DomainObjectIDs.Order1, false); _eventReceiver.Clear(); DomainObject orderTicket = TestableClientTransaction.GetRelatedObject( RelationEndPointID.Create(order.ID, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket")); Assert.That(orderTicket, Is.Not.Null); Assert.That(orderTicket.ID, Is.EqualTo(DomainObjectIDs.OrderTicket1)); 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(orderTicket)); }
public void VirtualEndPointQuery_OneOne_Consistent_RealEndPointLoadedFirst() { var orderTicket1 = DomainObjectIDs.OrderTicket1.GetObject <OrderTicket> (); var order1 = DomainObjectIDs.Order1.GetObject <Order> (); Assert.That(orderTicket1.Order, Is.SameAs(order1)); Assert.That(order1.OrderTicket, Is.SameAs(orderTicket1)); CheckSyncState(orderTicket1, oi => oi.Order, true); CheckSyncState(orderTicket1.Order, o => o.OrderTicket, true); // these do nothing BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current, RelationEndPointID.Resolve(orderTicket1, oi => oi.Order)); BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current, RelationEndPointID.Resolve(orderTicket1.Order, o => o.OrderTicket)); CheckSyncState(orderTicket1, oi => oi.Order, true); CheckSyncState(orderTicket1.Order, o => o.OrderTicket, true); }
public void CollectionItems_Synchronized_WithUnload() { var orderItem = DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); var endPointID = RelationEndPointID.Resolve(orderItem, oi => oi.Order); var endPoint = (RealObjectEndPoint)TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID); Assert.That(endPoint, Is.Not.Null); Assert.That(RealObjectEndPointTestHelper.GetSyncState(endPoint), Is.TypeOf(typeof(UnknownRealObjectEndPointSyncState))); orderItem.Order.OrderItems.EnsureDataComplete(); Assert.That(RealObjectEndPointTestHelper.GetSyncState(endPoint), Is.TypeOf(typeof(SynchronizedRealObjectEndPointSyncState))); UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, orderItem.Order.OrderItems.AssociatedEndPointID); Assert.That(RealObjectEndPointTestHelper.GetSyncState(endPoint), Is.TypeOf(typeof(UnknownRealObjectEndPointSyncState))); }
public void SetDataFromSubTransaction_TouchesEndPoint_IfSourceWasTouched() { var sourceID = RelationEndPointID.Create(DomainObjectIDs.OrderItem2, _endPointID.Definition); ObjectEndPoint source = RelationEndPointObjectMother.CreateObjectEndPoint(sourceID, DomainObjectIDs.OrderTicket2); source.Touch(); Assert.That(source.HasBeenTouched, Is.True); _endPointPartialMock.Stub(stub => stub.OppositeObjectID).Return(DomainObjectIDs.OrderTicket1); _endPointPartialMock.Stub(stub => stub.HasBeenTouched).Return(false); _endPointPartialMock.Stub(stub => stub.CallSetOppositeObjectDataFromSubTransaction(source)); _endPointPartialMock.Expect(mock => mock.Touch()); _endPointPartialMock.Replay(); _endPointPartialMock.SetDataFromSubTransaction(source); _endPointPartialMock.VerifyAllExpectations(); }
public void UnloadVirtualEndPoint_Object() { var order = DomainObjectIDs.Order1.GetObject <Order> (); var orderTicket = order.OrderTicket; CheckVirtualEndPointExistsAndComplete(order, "OrderTicket", true, true); UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, RelationEndPointID.Resolve(order, o => o.OrderTicket)); CheckDataContainerExists(order, true); CheckDataContainerExists(orderTicket, true); CheckEndPointExists(orderTicket, "Order", true); CheckVirtualEndPointExistsAndComplete(order, "OrderTicket", true, false); Assert.That(order.State, Is.EqualTo(StateType.Unchanged)); Assert.That(orderTicket.State, Is.EqualTo(StateType.Unchanged)); }
public void CreateSetCommand_OneMany() { var oldRelatedObject = DomainObjectMother.CreateFakeObject <Customer> (); var newRelatedObject = DomainObjectMother.CreateFakeObject <Customer> (); _endPointMock.Stub(stub => stub.Definition).Return(_orderCustomerEndPointDefinition); _endPointMock.Stub(stub => stub.GetDomainObject()).Return(_order); _endPointMock.Stub(stub => stub.IsNull).Return(false); _endPointMock.Stub(stub => stub.OppositeObjectID).Return(oldRelatedObject.ID); _endPointMock.Stub(stub => stub.GetOppositeObject()).Return(oldRelatedObject); var oldOppositeEndPointStub = MockRepository.GenerateStub <IVirtualEndPoint> (); var newOppositeEndPointStub = MockRepository.GenerateStub <IVirtualEndPoint> (); var oldOppositeEndPointID = RelationEndPointID.CreateOpposite(_orderCustomerEndPointDefinition, oldRelatedObject.ID); var newOppositeEndPointID = RelationEndPointID.CreateOpposite(_orderCustomerEndPointDefinition, newRelatedObject.ID); _endPointProviderStub .Stub(stub => stub.GetRelationEndPointWithLazyLoad(oldOppositeEndPointID)) .Return(oldOppositeEndPointStub); _endPointProviderStub .Stub(stub => stub.GetRelationEndPointWithLazyLoad(newOppositeEndPointID)) .Return(newOppositeEndPointStub); var command = _state.CreateSetCommand(_endPointMock, newRelatedObject, _fakeSetter); Assert.That(command, Is.TypeOf(typeof(RealObjectEndPointRegistrationCommandDecorator))); var decorator = (RealObjectEndPointRegistrationCommandDecorator)command; Assert.That(decorator.RealObjectEndPoint, Is.SameAs(_endPointMock)); Assert.That(decorator.OldRelatedEndPoint, Is.SameAs(oldOppositeEndPointStub)); Assert.That(decorator.NewRelatedEndPoint, Is.SameAs(newOppositeEndPointStub)); Assert.That(decorator.DecoratedCommand, Is.TypeOf(typeof(ObjectEndPointSetOneManyCommand))); var decoratedCommand = (ObjectEndPointSetOneManyCommand)decorator.DecoratedCommand; Assert.That(decoratedCommand, Is.TypeOf(typeof(ObjectEndPointSetOneManyCommand))); Assert.That(decoratedCommand.ModifiedEndPoint, Is.SameAs(_endPointMock)); Assert.That(decoratedCommand.NewRelatedObject, Is.SameAs(newRelatedObject)); Assert.That(decoratedCommand.OldRelatedObject, Is.SameAs(oldRelatedObject)); Assert.That(decoratedCommand.EndPointProvider, Is.SameAs(_endPointProviderStub)); Assert.That(GetOppositeObjectIDSetter(decoratedCommand), Is.SameAs(_fakeSetter)); }
public override void SetUp() { base.SetUp(); _employee1 = Employee.NewObject(); _computer1 = Computer.NewObject(); _computer2 = Computer.NewObject(); _employee1.Computer = _computer1; TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope(); _employee1.Computer.EnsureDataAvailable(); _virtualObjectEndPoint = (VirtualObjectEndPoint)GetEndPoint <StateUpdateRaisingVirtualObjectEndPointDecorator> (RelationEndPointID.Resolve(_employee1, o => o.Computer)).InnerEndPoint; _computer1EndPoint = GetEndPoint <RealObjectEndPoint> (RelationEndPointID.Resolve(_computer1, oi => oi.Employee)); _computer2EndPoint = GetEndPoint <RealObjectEndPoint> (RelationEndPointID.Resolve(_computer2, oi => oi.Employee)); }
public override void SetUp() { base.SetUp(); _definition = Configuration.GetTypeDefinition(typeof(Customer)).GetRelationEndPointDefinition(typeof(Customer).FullName + ".Orders"); _virtualEndPointMock = MockRepository.GenerateStrictMock <IVirtualEndPoint <object> > (); _dataManagerMock = MockRepository.GenerateStrictMock <IVirtualEndPointDataManager>(); _dataManagerMock.Stub(stub => stub.EndPointID).Return(RelationEndPointID.Create(DomainObjectIDs.Customer1, _definition)); _endPointProviderStub = MockRepository.GenerateStub <IRelationEndPointProvider>(); _transactionEventSinkWithMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>(); _loadState = new TestableCompleteVirtualEndPointLoadState(_dataManagerMock, _endPointProviderStub, _transactionEventSinkWithMock); _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); }
public void UnloadCollectionEndPoint_WithReferences_LeavesIncompleteEndPoint() { var customer = DomainObjectIDs.Customer1.GetObject <Customer> (); var customerOrders = customer.Orders; customerOrders.EnsureDataComplete(); Assert.That(customer.Orders, Is.Not.Empty); var virtualEndPointID = RelationEndPointID.Resolve(customer, c => c.Orders); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.True); UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, virtualEndPointID); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.False); Assert.That(customerOrders, Is.SameAs(customer.Orders)); }
public virtual ILoadedObjectData GetOrLoadRelatedObject(RelationEndPointID relationEndPointID) { ArgumentUtility.CheckNotNull("relationEndPointID", relationEndPointID); if (!relationEndPointID.Definition.IsVirtual) { throw new ArgumentException("GetOrLoadRelatedObject can only be used with virtual end points.", "relationEndPointID"); } if (relationEndPointID.Definition.Cardinality != CardinalityType.One) { throw new ArgumentException("GetOrLoadRelatedObject can only be used with one-valued end points.", "relationEndPointID"); } var loadedObjectData = _persistenceStrategy.ResolveObjectRelationData(relationEndPointID, _loadedObjectDataProvider); _loadedObjectDataRegistrationAgent.RegisterIfRequired(new[] { loadedObjectData }, true); return(loadedObjectData); }
public void RegisterEndPoint_RealEndPoint_PointingToNonNull_Unidirectional() { var endPointMock = MockRepository.GenerateStrictMock <IRealObjectEndPoint> (); var unidirectionalEndPointID = RelationEndPointID.Create(DomainObjectIDs.Location1, typeof(Location), "Client"); endPointMock.Stub(stub => stub.ID).Return(unidirectionalEndPointID); endPointMock.Stub(stub => stub.Definition).Return(unidirectionalEndPointID.Definition); endPointMock.Stub(stub => stub.OriginalOppositeObjectID).Return(DomainObjectIDs.Client1); endPointMock.Expect(mock => mock.MarkSynchronized()); endPointMock.Replay(); _virtualEndPointProviderMock.Replay(); _agent.RegisterEndPoint(endPointMock, _map); endPointMock.VerifyAllExpectations(); Assert.That(_map, Has.Member(endPointMock)); }
public void SynchronizeOppositeEndPoint() { // Prepare an item in unsynchronized state Order unsynchronizedOrder = PrepareUnsynchronizedOrder(DomainObjectIDs.Order4, _customer.ID); var orderCollection = _customer.Orders; orderCollection.EnsureDataComplete(); _eventReceiverMock .Expect(mock => mock.OnReplaceData()) .WhenCalled(mi => Assert.That(orderCollection, Is.EqualTo(new[] { _itemA, _itemB, unsynchronizedOrder }))); _eventReceiverMock.Replay(); _customer.Orders.SetEventReceiver(_eventReceiverMock); BidirectionalRelationSyncService.Synchronize(TestableClientTransaction, RelationEndPointID.Resolve(unsynchronizedOrder, o => o.Customer)); _eventReceiverMock.VerifyAllExpectations(); }
public void Synchronize_InTransactionHierarchy_StopsWhenEndPointNotLoadedInSub() { 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(); BidirectionalRelationSyncService.Synchronize(subTransaction, endPointID); endPointMockInParent.VerifyAllExpectations(); }
public void TryUnloadVirtualEndPointAndItemData_Success_Object() { var order = DomainObjectIDs.Order1.GetObject <Order> (); var endPointID = RelationEndPointID.Resolve(order, o => o.OrderTicket); EnsureEndPointLoadedAndComplete(endPointID); var orderTicket = order.OrderTicket; Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID), Is.Not.Null); Assert.That(orderTicket, Is.Not.Null); var result = UnloadService.TryUnloadVirtualEndPointAndItemData(TestableClientTransaction, endPointID); Assert.That(result, Is.True); Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID), Is.Null); Assert.That(orderTicket.State, Is.EqualTo(StateType.NotLoadedYet)); Assert.That(order.State, Is.EqualTo(StateType.Unchanged)); }
public void CreateUnregisterCommandForDataContainer_WithUnregisterableEndPoint() { 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(true); RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPoint); 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" + "Relation end-point " + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer' has changed. " + "Only unchanged relation end-points can be unregistered.")); }
public void UnloadCollectionEndPoint_WithoutReferences_CausesEndPointToBeRemoved_ButKeepsDomainObjectCollectionInMemory() { var customer = DomainObjectIDs.Customer2.GetObject <Customer> (); var customerOrders = customer.Orders; customer.Orders.EnsureDataComplete(); Assert.That(customer.Orders, Is.Empty); var virtualEndPointID = RelationEndPointID.Resolve(customer, c => c.Orders); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.True); UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, virtualEndPointID); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Null); // But DomainObjectCollection stays valid Assert.That(customerOrders, Is.SameAs(customer.Orders)); }
protected void PrepareInconsistentState_OneOne_ObjectNotReturned_ThatLocallyPointsToHere(out Computer computer, out Employee employee, out Employee employee2) { SetDatabaseModifyable(); employee = DomainObjectIDs.Employee1.GetObject <Employee> (); employee2 = DomainObjectIDs.Employee2.GetObject <Employee> (); computer = CreateComputerAndSetEmployeeInOtherTransaction(employee2.ID).GetObject <Computer> (); Assert.That(computer.Employee, Is.SameAs(employee2)); // 1:1 relations automatically cause virtual end-points to be marked loaded when the foreign key object is loaded, so unload the virtual side UnloadService.UnloadVirtualEndPoint(ClientTransaction.Current, RelationEndPointID.Resolve(employee2, e => e.Computer)); SetEmployeeInOtherTransaction(computer.ID, DomainObjectIDs.Employee1); // Resolve virtual end point - the database says that computer points to employee1, but the transaction says computer points to employee2! Dev.Null = employee2.Computer; // Resolve virtual end point - the database says that computer points to employee1, but the transaction says computer points to employee2! Dev.Null = employee.Computer; }
// ReSharper disable UnusedMember.Local private CollectionEndPointDataManager(FlattenedDeserializationInfo info) { ArgumentUtility.CheckNotNull("info", info); _endPointID = info.GetValueForHandle <RelationEndPointID>(); _changeDetectionStrategy = info.GetValueForHandle <ICollectionEndPointChangeDetectionStrategy>(); _changeCachingCollectionData = info.GetValue <ChangeCachingCollectionDataDecorator>(); _originalOppositeEndPoints = new HashSet <IRealObjectEndPoint>(); info.FillCollection(_originalOppositeEndPoints); _originalItemsWithoutEndPoint = new HashSet <DomainObject>(); info.FillCollection(_originalItemsWithoutEndPoint); var currentOppositeEndPoints = new List <IRealObjectEndPoint>(); info.FillCollection(currentOppositeEndPoints); _currentOppositeEndPoints = currentOppositeEndPoints.ToDictionary(ep => ep.ObjectID); }
public void IsSynchronized_CalledFromSubTransaction_UsesRootTransaction() { var endPointID = RelationEndPointID.Create(DomainObjectIDs.OrderItem1, typeof(OrderItem), "Order"); var endPointStub = MockRepository.GenerateStub <IRelationEndPoint> (); endPointStub.Stub(stub => stub.ID).Return(endPointID); endPointStub.Stub(stub => stub.Definition).Return(endPointID.Definition); endPointStub.Stub(stub => stub.IsDataComplete).Return(true); endPointStub.Stub(stub => stub.IsSynchronized).Return(true).Repeat.Once(); endPointStub.Stub(stub => stub.IsSynchronized).Return(false).Repeat.Once(); RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub); var subTransaction = _transaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { Assert.That(BidirectionalRelationSyncService.IsSynchronized(subTransaction, endPointID), Is.True); Assert.That(BidirectionalRelationSyncService.IsSynchronized(subTransaction, endPointID), Is.False); } }
public override void SetUp() { base.SetUp(); _parentTransactionContextMock = MockRepository.GenerateStrictMock <IParentTransactionContext> (); _unlockedParentTransactionContextMock = MockRepository.GenerateStrictMock <IUnlockedParentTransactionContext> (); _persistenceStrategy = new SubPersistenceStrategy(_parentTransactionContextMock); _queryStub = MockRepository.GenerateStub <IQuery>(); _orderNumberPropertyDefinition = GetPropertyDefinition(typeof(Order), "OrderNumber"); _fileNamePropertyDefinition = GetPropertyDefinition(typeof(OrderTicket), "FileName"); _productPropertyDefinition = GetPropertyDefinition(typeof(OrderItem), "Product"); _virtualObjectRelationEndPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, GetEndPointDefinition(typeof(Order), "OrderTicket")); _collectionEndPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, GetEndPointDefinition(typeof(Order), "OrderItems")); _nonVirtualEndPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, GetEndPointDefinition(typeof(Order), "Customer")); _alreadyLoadedObjectDataProviderMock = MockRepository.GenerateStrictMock <ILoadedObjectDataProvider>(); }
public void GetRelatedObjectForAlreadyLoadedObjects() { DomainObject order = TestableClientTransaction.GetObject(DomainObjectIDs.Order1, false); DomainObject orderTicket = TestableClientTransaction.GetObject(DomainObjectIDs.OrderTicket1, false); _eventReceiver.Clear(); Assert.That( TestableClientTransaction.GetRelatedObject( RelationEndPointID.Create(order.ID, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket")), Is.SameAs(orderTicket)); Assert.That(_eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(0)); Assert.That( TestableClientTransaction.GetRelatedObject( RelationEndPointID.Create(orderTicket.ID, "Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderTicket.Order")), Is.SameAs(order)); Assert.That(_eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(0)); }
public void VirtualEndPointQuery_OneMany_Consistent_CollectionLoadedFirst() { var order1 = DomainObjectIDs.Order1.GetObject <Order> (); order1.OrderItems.EnsureDataComplete(); var orderItem1 = DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); Assert.That(orderItem1.Order, Is.SameAs(order1)); Assert.That(order1.OrderItems, Has.Member(orderItem1)); CheckSyncState(orderItem1, oi => oi.Order, true); CheckSyncState(orderItem1.Order, o => o.OrderItems, true); // these do nothing BidirectionalRelationSyncService.Synchronize(TestableClientTransaction, RelationEndPointID.Resolve(orderItem1, oi => oi.Order)); BidirectionalRelationSyncService.Synchronize(TestableClientTransaction, RelationEndPointID.Resolve(orderItem1.Order, o => o.OrderItems)); CheckSyncState(orderItem1, oi => oi.Order, true); CheckSyncState(orderItem1.Order, o => o.OrderItems, true); }
public void CreateCollectionEndPoint() { var endPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderItems"); var endPoint = _factory.CreateCollectionEndPoint(endPointID); Assert.That(endPoint, Is.TypeOf <CollectionEndPoint> ()); Assert.That(endPoint.ClientTransaction, Is.SameAs(_clientTransaction)); Assert.That(endPoint.ID, Is.EqualTo(endPointID)); Assert.That( ((CollectionEndPoint)endPoint).CollectionManager, Is.TypeOf <CollectionEndPointCollectionManager>() .With.Property <CollectionEndPointCollectionManager> (p => p.CollectionProvider).SameAs(_collectionEndPointCollectionProviderStub) .And.Property <CollectionEndPointCollectionManager> (p => p.DataStrategyFactory).SameAs(_associatedCollectionStrategyFactoryStub)); Assert.That(((CollectionEndPoint)endPoint).LazyLoader, Is.SameAs(_lazyLoaderStub)); Assert.That(((CollectionEndPoint)endPoint).EndPointProvider, Is.SameAs(_endPointProviderStub)); Assert.That(((CollectionEndPoint)endPoint).TransactionEventSink, Is.SameAs(_transactionEventSinkStub)); Assert.That(((CollectionEndPoint)endPoint).DataManagerFactory, Is.SameAs(_collectionEndPointDataManagerFactoryStub)); Assert.That(endPoint.IsDataComplete, Is.False); }