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 CollectionEndPointIsFlattenedSerializable() { CollectionEndPoint deserializedEndPoint = FlattenedSerializer.SerializeAndDeserialize(_endPoint); Assert.That(deserializedEndPoint, Is.Not.Null); Assert.That(deserializedEndPoint, Is.Not.SameAs(_endPoint)); }
public void Initialize() { var endPoint = new CollectionEndPoint( TestableClientTransaction, _customerEndPointID, _collectionManagerMock, _lazyLoaderMock, _endPointProviderStub, _transactionEventSinkStub, _dataManagerFactoryStub); Assert.That(endPoint.ID, Is.EqualTo(_customerEndPointID)); Assert.That(endPoint.CollectionManager, Is.SameAs(_collectionManagerMock)); Assert.That(endPoint.LazyLoader, Is.SameAs(_lazyLoaderMock)); Assert.That(endPoint.EndPointProvider, Is.SameAs(_endPointProviderStub)); Assert.That(endPoint.TransactionEventSink, Is.SameAs(_transactionEventSinkStub)); Assert.That(endPoint.DataManagerFactory, Is.SameAs(_dataManagerFactoryStub)); var loadState = CollectionEndPointTestHelper.GetLoadState(endPoint); Assert.That(loadState, Is.TypeOf(typeof(IncompleteCollectionEndPointLoadState))); Assert.That(((IncompleteCollectionEndPointLoadState)loadState).DataManagerFactory, Is.SameAs(_dataManagerFactoryStub)); Assert.That( ((IncompleteCollectionEndPointLoadState)loadState).EndPointLoader, Is.TypeOf <CollectionEndPoint.EndPointLoader>().With.Property <CollectionEndPoint.EndPointLoader> (l => l.LazyLoader).SameAs(_lazyLoaderMock)); }
public static CollectionEndPoint CreateCollectionEndPoint( RelationEndPointID endPointID, IEnumerable <DomainObject> initialContents, ClientTransaction clientTransaction = null) { clientTransaction = clientTransaction ?? ClientTransactionScope.CurrentTransaction; var dataManager = ClientTransactionTestHelper.GetDataManager(clientTransaction); var changeDetectionStrategy = new RootCollectionEndPointChangeDetectionStrategy(); var dataStrategyFactory = new AssociatedCollectionDataStrategyFactory(dataManager); var collectionEndPoint = new CollectionEndPoint( clientTransaction, endPointID, new CollectionEndPointCollectionManager(endPointID, new CollectionEndPointCollectionProvider(dataStrategyFactory), dataStrategyFactory), dataManager, dataManager, ClientTransactionTestHelper.GetEventBroker(clientTransaction), new CollectionEndPointDataManagerFactory(changeDetectionStrategy)); if (initialContents != null) { CollectionEndPointTestHelper.FillCollectionEndPointWithInitialContents(collectionEndPoint, initialContents); } return(collectionEndPoint); }
public void CollectionEndPoint_Touched() { _endPoint.Touch(); CollectionEndPoint deserializedEndPoint = FlattenedSerializer.SerializeAndDeserialize(_endPoint); Assert.That(deserializedEndPoint.HasBeenTouched, Is.True); }
public override void SetUp() { base.SetUp(); Dev.Null = DomainObjectIDs.Order1.GetObject <Order> ().OrderItems; var endPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, ReflectionMappingHelper.GetPropertyName(typeof(Order), "OrderItems")); _endPoint = (CollectionEndPoint) ((StateUpdateRaisingCollectionEndPointDecorator)TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID)).InnerEndPoint; }
public void ExpandToAllRelatedObjects() { Assert.That(_order1.Customer, Is.SameAs(CollectionEndPoint.GetDomainObject())); Assert.That(_order2.Customer, Is.SameAs(CollectionEndPoint.GetDomainObject())); var customer3 = DomainObjectIDs.Customer3.GetObject <Customer> (Transaction); Assert.That(_order3.Customer, Is.SameAs(customer3)); var bidirectionalModification = _command.ExpandToAllRelatedObjects(); // DomainObject.Orders = _newCollection var steps = bidirectionalModification.GetNestedCommands(); Assert.That(steps.Count, Is.EqualTo(4)); // order2.Customer = null; // order3.Customer.Orders.Remove (order3); // order3.Customer = DomainObject; // DomainObject.Orders = _newCollection // order2.Customer = null; Assert.That(steps[0], Is.InstanceOf(typeof(RealObjectEndPointRegistrationCommandDecorator))); var setOrder5CustomerCommand = ((ObjectEndPointSetCommand)((RealObjectEndPointRegistrationCommandDecorator)steps[0]).DecoratedCommand); Assert.That(setOrder5CustomerCommand.ModifiedEndPoint.ID.Definition.PropertyName, Is.EqualTo(typeof(Order).FullName + ".Customer")); Assert.That(setOrder5CustomerCommand.ModifiedEndPoint.ID.ObjectID, Is.EqualTo(_order2.ID)); Assert.That(setOrder5CustomerCommand.OldRelatedObject, Is.SameAs(DomainObject)); Assert.That(setOrder5CustomerCommand.NewRelatedObject, Is.Null); // order3.Customer.Orders.Remove (order3); Assert.That(steps[1], Is.TypeOf <VirtualEndPointStateUpdatedRaisingCommandDecorator> ()); var order2CustomerOrdersRemoveCommand = ((CollectionEndPointRemoveCommand)((VirtualEndPointStateUpdatedRaisingCommandDecorator)steps[1]).DecoratedCommand); Assert.That(order2CustomerOrdersRemoveCommand.ModifiedEndPoint.ID.Definition.PropertyName, Is.EqualTo(typeof(Customer).FullName + ".Orders")); Assert.That(order2CustomerOrdersRemoveCommand.ModifiedEndPoint.ID.ObjectID, Is.EqualTo(customer3.ID)); Assert.That(order2CustomerOrdersRemoveCommand.OldRelatedObject, Is.SameAs(_order3)); Assert.That(order2CustomerOrdersRemoveCommand.NewRelatedObject, Is.Null); // order3.Customer = DomainObject Assert.That(steps[2], Is.InstanceOf(typeof(RealObjectEndPointRegistrationCommandDecorator))); var setOrder2CustomerCommand = ((ObjectEndPointSetCommand)((RealObjectEndPointRegistrationCommandDecorator)steps[2]).DecoratedCommand); Assert.That(setOrder2CustomerCommand.ModifiedEndPoint.ID.Definition.PropertyName, Is.EqualTo(typeof(Order).FullName + ".Customer")); Assert.That(setOrder2CustomerCommand.ModifiedEndPoint.ID.ObjectID, Is.EqualTo(_order3.ID)); Assert.That(setOrder2CustomerCommand.OldRelatedObject, Is.SameAs(customer3)); Assert.That(setOrder2CustomerCommand.NewRelatedObject, Is.SameAs(DomainObject)); // DomainObject.Orders = _newCollection Assert.That(steps[3], Is.SameAs(_command)); }
public static void FillCollectionEndPointWithInitialContents(CollectionEndPoint endPoint, IEnumerable <DomainObject> initialContents) { var dataManager = ClientTransactionTestHelper.GetDataManager(endPoint.ClientTransaction); var domainObjects = initialContents.ToArray(); foreach (var domainObject in domainObjects) { var oppositeEndPointID = RelationEndPointID.Create(domainObject.ID, endPoint.Definition.GetOppositeEndPointDefinition()); var oppositeEndPoint = (IRealObjectEndPoint)dataManager.GetRelationEndPointWithLazyLoad(oppositeEndPointID); endPoint.RegisterOriginalOppositeEndPoint(oppositeEndPoint); } endPoint.MarkDataComplete(domainObjects); }
public override void SetUp() { base.SetUp(); _order1 = DomainObjectIDs.Order1.GetObject <Order> (); _order2 = DomainObjectIDs.Order2.GetObject <Order> (); _order3 = DomainObjectIDs.Order3.GetObject <Order> (); var stateUpdateRaisingEndPointDecorator = (StateUpdateRaisingCollectionEndPointDecorator) TestableClientTransaction.DataManager.GetRelationEndPointWithLazyLoad( RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders")); _customerEndPoint = (CollectionEndPoint)stateUpdateRaisingEndPointDecorator.InnerEndPoint; }
public void CollectionEndPoint_Content() { _endPoint.Collection.Add(DomainObjectIDs.OrderItem5.GetObject <OrderItem>()); CollectionEndPoint deserializedEndPoint = FlattenedSerializer.SerializeAndDeserialize(_endPoint); Assert.That(deserializedEndPoint.Definition, Is.SameAs(_endPoint.Definition)); Assert.That(deserializedEndPoint.HasBeenTouched, Is.True); Assert.That(deserializedEndPoint.Collection.Count, Is.EqualTo(3)); Assert.That(deserializedEndPoint.Collection.Contains(DomainObjectIDs.OrderItem1), Is.True); Assert.That(deserializedEndPoint.Collection.Contains(DomainObjectIDs.OrderItem2), Is.True); Assert.That(deserializedEndPoint.Collection.Contains(DomainObjectIDs.OrderItem5), Is.True); Assert.That(deserializedEndPoint.Collection.IsReadOnly, Is.False); Assert.That(deserializedEndPoint.GetCollectionWithOriginalData().Count, Is.EqualTo(2)); Assert.That(deserializedEndPoint.GetCollectionWithOriginalData().Contains(DomainObjectIDs.OrderItem1), Is.True); Assert.That(deserializedEndPoint.GetCollectionWithOriginalData().Contains(DomainObjectIDs.OrderItem2), Is.True); Assert.That(deserializedEndPoint.GetCollectionWithOriginalData().IsReadOnly, Is.True); }
public void CollectionEndPoint_ReplacedCollection() { var newOpposites = _endPoint.Collection.Clone(); _endPoint.CreateSetCollectionCommand(newOpposites).ExpandToAllRelatedObjects().NotifyAndPerform(); CollectionEndPoint deserializedEndPoint = FlattenedSerializer.SerializeAndDeserialize(_endPoint); Assert.That(deserializedEndPoint.HasChanged, Is.True); var deserializedNewOpposites = deserializedEndPoint.Collection; deserializedEndPoint.Rollback(); Assert.That(deserializedEndPoint.HasChanged, Is.False); var deserializedOldOpposites = deserializedEndPoint.Collection; Assert.That(deserializedOldOpposites, Is.Not.SameAs(deserializedNewOpposites)); Assert.That(deserializedOldOpposites, Is.Not.Null); }
public override void SetUp() { base.SetUp(); _folder1 = Folder.NewObject(); _fileSystemItem1 = FileSystemItem.NewObject(); _fileSystemItem2 = FileSystemItem.NewObject(); _fileSystemItem3 = FileSystemItem.NewObject(); _folder1.FileSystemItems.Add(_fileSystemItem1); _folder1.FileSystemItems.Add(_fileSystemItem2); TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope(); _folder1.FileSystemItems.EnsureDataComplete(); _collectionEndPoint = (CollectionEndPoint)GetEndPoint <StateUpdateRaisingCollectionEndPointDecorator> (RelationEndPointID.Resolve(_folder1, o => o.FileSystemItems)).InnerEndPoint; _fileSystemItem1EndPoint = GetEndPoint <RealObjectEndPoint> (RelationEndPointID.Resolve(_fileSystemItem1, oi => oi.ParentFolder)); _fileSystemItem2EndPoint = GetEndPoint <RealObjectEndPoint> (RelationEndPointID.Resolve(_fileSystemItem2, oi => oi.ParentFolder)); _fileSystemItem3EndPoint = GetEndPoint <RealObjectEndPoint> (RelationEndPointID.Resolve(_fileSystemItem3, oi => oi.ParentFolder)); }
public override void SetUp() { base.SetUp(); _transaction = ClientTransaction.CreateRootTransaction(); _domainObject = DomainObjectIDs.Customer1.GetObject <Customer> (_transaction); _order1 = DomainObjectIDs.Order1.GetObject <Order> (_transaction); _order2 = DomainObjectIDs.Order2.GetObject <Order> (_transaction); _relationEndPointID = RelationEndPointID.Create(DomainObject.ID, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders"); _collectionEndPoint = RelationEndPointObjectMother.CreateCollectionEndPoint( _relationEndPointID, new[] { _order1, _order2 }, _transaction); _collectionMockEventReceiver = MockRepository.GenerateStrictMock <DomainObjectCollectionMockEventReceiver> (_collectionEndPoint.Collection); _collectionDataMock = new MockRepository().StrictMock <IDomainObjectCollectionData> (); CollectionDataMock.Replay(); _endPointProviderStub = MockRepository.GenerateStub <IRelationEndPointProvider>(); _transactionEventSinkMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>(); }
public void Serialization_InjectedObjects() { var endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Customer1, "Orders"); var originalEndPoint = new CollectionEndPoint( ClientTransaction.Current, endPointID, new SerializableCollectionEndPointCollectionManagerFake(), new SerializableLazyLoaderFake(), new SerializableRelationEndPointProviderFake(), new SerializableClientTransactionEventSinkFake(), new SerializableCollectionEndPointDataManagerFactoryFake()); var deserializedEndPoint = FlattenedSerializer.SerializeAndDeserialize(originalEndPoint); var deserializedLoadState = PrivateInvoke.GetNonPublicField(deserializedEndPoint, "_loadState"); Assert.That(deserializedLoadState, Is.Not.Null); Assert.That(deserializedEndPoint.CollectionManager, Is.Not.Null); Assert.That(deserializedEndPoint.LazyLoader, Is.Not.Null); Assert.That(deserializedEndPoint.EndPointProvider, Is.Not.Null); Assert.That(deserializedEndPoint.TransactionEventSink, Is.Not.Null); Assert.That(deserializedEndPoint.DataManagerFactory, Is.Not.Null); }
private void SetCollectionAndNotify(CollectionEndPoint collectionEndPoint, DomainObjectCollection newCollection) { collectionEndPoint.CreateSetCollectionCommand(newCollection).ExpandToAllRelatedObjects().NotifyAndPerform(); }
public static void SetLoadState(CollectionEndPoint collectionEndPoint, ICollectionEndPointLoadState loadState) { PrivateInvoke.SetNonPublicField(collectionEndPoint, "_loadState", loadState); }
public void CollectionEndPoint_ClientTransaction() { CollectionEndPoint deserializedEndPoint = FlattenedSerializer.SerializeAndDeserialize(_endPoint); Assert.That(deserializedEndPoint.ClientTransaction, Is.Not.Null); }
public void CollectionEndPoint_Untouched() { CollectionEndPoint deserializedEndPoint = FlattenedSerializer.SerializeAndDeserialize(_endPoint); Assert.That(deserializedEndPoint.HasBeenTouched, Is.False); }
public static ICollectionEndPointLoadState GetLoadState(CollectionEndPoint collectionEndPoint) { return((ICollectionEndPointLoadState)PrivateInvoke.GetNonPublicField(collectionEndPoint, "_loadState")); }