Exemple #1
0
        public void DeepCopyEntity_ToNewParent_CopiesEntity_IncludingRelations()
        {
            // Arrange
            var originalParent = HiveModelCreationHelper.MockTypedEntity(true);

            originalParent.RelationProxies.LazyLoadDelegate = x => new RelationProxyBucket();
            var originalChild = HiveModelCreationHelper.MockTypedEntity(true);

            originalChild.RelationProxies.LazyLoadDelegate = x => new RelationProxyBucket();

            var newContainer1 = HiveModelCreationHelper.MockTypedEntity(true);
            var newContainer2 = HiveModelCreationHelper.MockTypedEntity(true);

            originalParent.RelationProxies.EnlistChild(
                originalChild,
                FixedRelationTypes.DefaultRelationType,
                0,
                new RelationMetaDatum("testkey", "testvalue"));

            originalChild.RelationProxies.EnlistParent(
                originalParent,
                FixedRelationTypes.DefaultRelationType,
                0,
                new RelationMetaDatum("testkey", "testvalue"));

            // Guard against bad test data
            foreach (var attribute in originalParent.Attributes)
            {
                Assert.AreNotEqual(HiveId.Empty, attribute.Id);
                Assert.NotNull(attribute.AttributeDefinition);
                Assert.AreNotEqual(HiveId.Empty, attribute.AttributeDefinition.Id);
            }

            Thread.Sleep(250); // Ensure copy dates are newer

            //Act & Assert
            var copyLeft = EntityExtensions.CreateDeepCopyToNewParent(originalParent, newContainer1, FixedRelationTypes.DefaultRelationType, 0);

            DoAssertDeepCopiedEntityToNewParent(copyLeft, originalParent, newContainer1);
            DoAssertDeepCopiedEntityChildren(copyLeft, originalParent);

            var copyRight = EntityExtensions.CreateDeepCopyToNewParent(originalChild, newContainer2, FixedRelationTypes.DefaultRelationType, 0);

            DoAssertDeepCopiedEntityToNewParent(copyRight, originalChild, newContainer2);
            DoAssertDeepCopiedEntityChildren(copyRight, originalChild);
        }