public void Initialization_WithData() { var givenData = new DomainObjectCollectionData(); var collection = new DomainObjectCollection(givenData); Assert.That(collection.IsReadOnly, Is.False); Assert.That(collection.AssociatedEndPointID, Is.Null); var actualData = DomainObjectCollectionDataTestHelper.GetDataStrategy(collection); Assert.That(actualData, Is.SameAs(givenData)); }
public void TransformToStandAlone() { var endPoint = RelationEndPointObjectMother.CreateCollectionEndPoint_Customer1_Orders(); var collection = endPoint.Collection; var originalCollectionDataStrategy = DomainObjectCollectionDataTestHelper.GetDataStrategy(collection); var originalCollectionContents = collection.Cast <DomainObject> ().ToArray(); var result = ((IAssociatableDomainObjectCollection)collection).TransformToStandAlone(); DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, typeof(Order)); Assert.That(collection, Is.EqualTo(originalCollectionContents)); Assert.That(result, Is.SameAs(originalCollectionDataStrategy)); }
public void TransformToAssociated() { var endPointID = RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders"); var originalCollectionDataStrategy = DomainObjectCollectionDataTestHelper.GetDataStrategy(_collection); var originalCollectionContents = _collection.Cast <DomainObject> ().ToArray(); var originalEndPointContents = ((ICollectionEndPoint)TestableClientTransaction.DataManager.GetRelationEndPointWithLazyLoad(endPointID)).GetData().ToArray(); var associatedCollectionDataStrategyFactory = new AssociatedCollectionDataStrategyFactory(TestableClientTransaction.DataManager); var result = ((IAssociatableDomainObjectCollection)_collection).TransformToAssociated(endPointID, associatedCollectionDataStrategyFactory); DomainObjectCollectionDataTestHelper.CheckAssociatedCollectionStrategy(_collection, typeof(Order), endPointID); Assert.That(result, Is.SameAs(originalCollectionDataStrategy)); Assert.That(result, Is.EqualTo(originalCollectionContents)); Assert.That(_collection, Is.EqualTo(originalEndPointContents)); }
public void GetCollection() { _associatedCollectionDataStrategyFactoryMock .Expect(mock => mock.CreateDataStrategyForEndPoint(_endPointID)) .Return(_dataStrategyStub); _associatedCollectionDataStrategyFactoryMock.Replay(); _dataStrategyStub.Stub(stub => stub.AssociatedEndPointID).Return(_endPointID); var result = _provider.GetCollection(_endPointID); _associatedCollectionDataStrategyFactoryMock.VerifyAllExpectations(); Assert.That(result, Is.TypeOf <OrderCollection> ()); Assert.That(DomainObjectCollectionDataTestHelper.GetDataStrategy(result), Is.SameAs(_dataStrategyStub)); Assert.That(result, Is.SameAs(_provider.GetCollection(_endPointID))); }
public void GetCollectionWithOriginalData() { var collectionDataStub = MockRepository.GenerateStub <IDomainObjectCollectionData> (); collectionDataStub.Stub(stub => stub.RequiredItemType).Return(typeof(Order)); var readOnlyCollectionDataDecorator = new ReadOnlyCollectionDataDecorator(collectionDataStub); _loadStateMock.Stub(stub => stub.GetOriginalData(_endPoint)).Return(readOnlyCollectionDataDecorator); _loadStateMock.Replay(); var result = _endPoint.GetCollectionWithOriginalData(); Assert.That(result, Is.TypeOf(typeof(OrderCollection))); var actualCollectionData = DomainObjectCollectionDataTestHelper.GetDataStrategy(result); Assert.That(actualCollectionData, Is.SameAs(readOnlyCollectionDataDecorator)); }
public void SetCollection_DataStrategy_OfOldOpposites() { var oldOpposites = _customerEndPoint.Collection; var newOpposites = new OrderCollection { _order2 }; SetCollectionAndNotify(_customerEndPoint, newOpposites); // old collection got a stand-alone strategy... DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(oldOpposites, typeof(Order)); var dataStrategyOfOldOpposites = DomainObjectCollectionDataTestHelper.GetDataStrategy(oldOpposites); // with the data it had before! Assert.That(dataStrategyOfOldOpposites.ToArray(), Is.EqualTo(new[] { _order1, _order2 })); }
public void RollbackCollectionReference_LeavesNewCollectionAloneIfAlreadyReassociatedWithOther() { var originalCollection = RegisterAssociatedOriginalCollection(); var newCollection = new OrderCollection(); _associatedCollectionDataStrategyFactoryMock.Stub(stub => stub.CreateDataStrategyForEndPoint(_endPointID)).Return(_associatedDataStrategyStub); _manager.AssociateCollectionWithEndPoint(newCollection); Assert.That(DomainObjectCollectionDataTestHelper.GetDataStrategy(newCollection), Is.SameAs(_associatedDataStrategyStub)); DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(originalCollection, typeof(Order)); // Simulate that newCollection has already been re-associated by another rollback operation. // The Rollback operation must leave this other strategy alone. var otherStrategy = new DomainObjectCollectionData(); DomainObjectCollectionDataTestHelper.SetDataStrategy(newCollection, otherStrategy); _manager.RollbackCollectionReference(); Assert.That(DomainObjectCollectionDataTestHelper.GetDataStrategy(originalCollection), Is.SameAs(_associatedDataStrategyStub)); Assert.That(DomainObjectCollectionDataTestHelper.GetDataStrategy(newCollection), Is.SameAs(otherStrategy)); }
public void RollbackCollectionReference_UndoesAssociation() { var originalCollection = RegisterAssociatedOriginalCollection(); var newCollection = new OrderCollection(); _associatedCollectionDataStrategyFactoryMock.Stub(stub => stub.CreateDataStrategyForEndPoint(_endPointID)).Return(_associatedDataStrategyStub); _manager.AssociateCollectionWithEndPoint(newCollection); Assert.That(DomainObjectCollectionDataTestHelper.GetDataStrategy(newCollection), Is.SameAs(_associatedDataStrategyStub)); DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(originalCollection, typeof(Order)); // The Rollback operation must now transform the new collection to a standalone collection and reassociate the original collection with the end- // point being rolled back. (In addition to making the original collection the current collection again.) _manager.RollbackCollectionReference(); Assert.That(_manager.GetCurrentCollectionReference(), Is.SameAs(originalCollection)); Assert.That(_manager.GetOriginalCollectionReference(), Is.SameAs(originalCollection)); Assert.That(DomainObjectCollectionDataTestHelper.GetDataStrategy(originalCollection), Is.SameAs(_associatedDataStrategyStub)); DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(newCollection, typeof(Order)); }
private void CheckDataStrategy(DomainObjectCollection collection, IDomainObjectCollectionData expectedData) { var data = DomainObjectCollectionDataTestHelper.GetDataStrategy(collection); Assert.That(data, Is.SameAs(expectedData)); }