Exemplo n.º 1
0
        public void Initialization_Default()
        {
            var collection = new DomainObjectCollection();

            Assert.That(collection.IsReadOnly, Is.False);
            Assert.That(collection.AssociatedEndPointID, Is.Null);
            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, null);
        }
Exemplo n.º 2
0
        public void Initialization_WithItemType()
        {
            var collection = new DomainObjectCollection(typeof(Order));

            Assert.That(collection.IsReadOnly, Is.False);
            Assert.That(collection.AssociatedEndPointID, Is.Null);
            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, typeof(Order));
        }
Exemplo n.º 3
0
        public void Clone_BecomesStandAlone()
        {
            OrderCollection associatedCollection = CreateAssociatedCollectionWithEndPointStub();
            var             clonedCollection     = (DomainObjectCollection)associatedCollection.Clone();

            // clone is always stand-alone, even when source is associated with end point
            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(clonedCollection, associatedCollection.RequiredItemType);
        }
Exemplo n.º 4
0
        public void CreateCollection_ForStandaloneCollection()
        {
            DomainObjectCollection collection = _factory.CreateCollection(typeof(ObjectList <Order>), new[] { _orderA, _orderB }, typeof(Order));

            Assert.That(collection, Is.Not.Null);
            Assert.That(collection.RequiredItemType, Is.EqualTo(typeof(Order)));

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, typeof(Order));
        }
Exemplo n.º 5
0
        public void Clone()
        {
            var clonedCollection = _collection.Clone();

            Assert.That(clonedCollection, Is.EqualTo(new[] { _customer1, _customer2 }));
            Assert.That(clonedCollection.IsReadOnly, Is.False);
            Assert.That(clonedCollection.RequiredItemType, Is.EqualTo(_collection.RequiredItemType));

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(clonedCollection, typeof(Customer));
        }
Exemplo n.º 6
0
        public void Initialization_WithEnumerable()
        {
            var collection = new DomainObjectCollection(new[] { _customer1, _customer2 }, typeof(Customer));

            Assert.That(collection, Is.EqualTo(new[] { _customer1, _customer2 }));
            Assert.That(collection.RequiredItemType, Is.SameAs(typeof(Customer)));
            Assert.That(collection.IsReadOnly, Is.False);
            Assert.That(collection.AssociatedEndPointID, Is.Null);

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(collection, typeof(Customer));
        }
Exemplo n.º 7
0
        public void DomainObjectCollection_StandAlone_Data()
        {
            var collection = new DomainObjectCollection(typeof(Order));

            collection.Add(DomainObjectIDs.Order1.GetObject <Order> ());

            DomainObjectCollection deserializedCollection = SerializeAndDeserialize(collection);

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(deserializedCollection, typeof(Order));
            Assert.That(deserializedCollection.Count, Is.EqualTo(1));
            Assert.That(deserializedCollection[0].ID, Is.EqualTo(DomainObjectIDs.Order1));
        }
Exemplo n.º 8
0
        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 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 Commit_AfterReplace_DelegationChain()
        {
            var oldCollection = _customerEndPoint.Collection;

            var newCollection = new OrderCollection {
                _order3
            };

            SetCollectionAndNotify(_customerEndPoint, newCollection);

            Assert.That(_customerEndPoint.Collection, Is.SameAs(newCollection));
            Assert.That(newCollection.AssociatedEndPointID, Is.EqualTo(_customerEndPoint.ID));
            Assert.That(oldCollection.AssociatedEndPointID, Is.Null);

            _customerEndPoint.Commit();

            DomainObjectCollectionDataTestHelper.CheckStandAloneCollectionStrategy(oldCollection, typeof(Order));
            DomainObjectCollectionDataTestHelper.CheckAssociatedCollectionStrategy(newCollection, typeof(Order), _customerEndPoint.ID);
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        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));
        }