Exemple #1
0
        public void Copy_MustCopyParentReference()
        {
            // Arrange
            var testClassParentOriginal = new ParentTestClass();

            testClassParentOriginal.Child = new ChildTestClass()
            {
                ParentReference = testClassParentOriginal,
            };

            var testClassParentCopy = new ParentTestClass();

            // Act
            this.testCandidate.Copy(
                testClassParentOriginal,
                testClassParentCopy,
                new List <IBaseAdditionalProcessing>());

            // Assert
            // Make sure original and copy of the parent object are not the same.
            testClassParentCopy.Should().NotBeSameAs(testClassParentOriginal);

            // Check if the Child's new reference is correctly set to the copied parent's reference.
            testClassParentCopy.Should().BeSameAs(testClassParentCopy.Child.ParentReference);
        }
Exemple #2
0
        public void Copy_MustCopyEmptyCollection()
        {
            // Arrange
            var testClassParentOriginal = new ParentTestClass();

            var testClassParentCopy = new ParentTestClass();

            // Act
            this.testCandidate.Copy(
                testClassParentOriginal,
                testClassParentCopy,
                new List <IBaseAdditionalProcessing>());

            // Assert
            // Make sure original and copy of the parent object are not the same.
            // Also make sure the parent test class children collection, which is empty, was copied.
            testClassParentCopy.Should().NotBeSameAs(testClassParentOriginal);
            testClassParentCopy.Children.Should().NotBeSameAs(testClassParentOriginal.Children);
            testClassParentCopy.Should().NotBeNull();
        }
Exemple #3
0
        public void MustUseStrategyWhenCopying()
        {
            // Arrange
            var testClassParentOriginal = new ParentTestClass();

            testClassParentOriginal.AddChild(new ChildTestClass()
            {
                TestValue = 1, Parent = testClassParentOriginal
            });
            testClassParentOriginal.AddChild(new ChildTestClass()
            {
                TestValue = 2, Parent = testClassParentOriginal
            });
            testClassParentOriginal.AddChild(new ChildTestClass()
            {
                TestValue = 3, Parent = testClassParentOriginal
            });

            var testClassParentCopy = new ParentTestClass();

            // Act
            this.testCandidate.Copy(
                testClassParentOriginal,
                testClassParentCopy,
                new List <IBaseAdditionalProcessing>());

            var testClassParentCopyChildren   = testClassParentCopy.Children.Cast <ChildTestClass>().ToList();
            var testClassParentOriginchildren = testClassParentOriginal.Children.Cast <ChildTestClass>().ToList();

            // Assert
            // Make sure original and copy of the parent object are not the same.
            testClassParentCopy.Should().NotBeSameAs(testClassParentOriginal);

            testClassParentCopyChildren.Count.Should().Be(3);

            testClassParentCopyChildren.ElementAt(0).TestValue.Should().Be(testClassParentOriginchildren.ElementAt(0).TestValue * 2);
            testClassParentCopyChildren.ElementAt(1).TestValue.Should().Be(testClassParentOriginchildren.ElementAt(1).TestValue * 2);
            testClassParentCopyChildren.ElementAt(2).TestValue.Should().Be(testClassParentOriginchildren.ElementAt(2).TestValue * 2);

            foreach (var copiedChild in testClassParentCopyChildren)
            {
                foreach (var originalChild in testClassParentOriginal.Children)
                {
                    originalChild.Should().NotBeSameAs(copiedChild);
                }
            }

            // Check for the correct referential reverse relation copy.
            foreach (var child in testClassParentCopyChildren)
            {
                child.Parent.Should().BeSameAs(testClassParentCopy);
            }
        }
Exemple #4
0
        public void Copy_MustCopyInheritedChildrenWhenIntercepted()
        {
            // Arrange
            var testClassParentOriginal = new ParentTestClass();

            testClassParentOriginal.AddChild(new ChildTestClass()
            {
                ParentReference = testClassParentOriginal,
            });
            testClassParentOriginal.AddChild(new ChildTestClass2()
            {
                ParentReference = testClassParentOriginal,
            });
            testClassParentOriginal.AddChild(new ChildTestClass()
            {
                ParentReference = testClassParentOriginal,
            });

            var testClassParentCopy = new ParentTestClass();

            // Act
            this.testCandidate.Copy(
                testClassParentOriginal,
                testClassParentCopy,
                new List <IBaseAdditionalProcessing>
            {
                new GenericContinueCopyInterception <IChildTestClass2>(obj => false),
            });

            var testClassParentCopyChildren = testClassParentCopy.Children.Cast <ChildTestClass>().ToList();

            // Assert
            // Make sure original and copy of the parent object are not the same.
            testClassParentCopy.Should().NotBeSameAs(testClassParentOriginal);

            testClassParentOriginal.Children.Count.Should().Be(3);

            foreach (var childhild in testClassParentCopyChildren)
            {
                childhild.ParentReference.Should().BeSameAs(testClassParentCopy);
            }
        }
        public void Copy_MustCopyParentReference()
        {
            // Arrange
            var testClassParentOriginal = new ParentTestClass();

            testClassParentOriginal.AddChild(new ChildTestClass()
            {
                ParentReference = testClassParentOriginal,
            });
            testClassParentOriginal.AddChild(new ChildTestClass()
            {
                ParentReference = testClassParentOriginal,
            });
            testClassParentOriginal.AddChild(new ChildTestClass()
            {
                ParentReference = testClassParentOriginal,
            });

            var testClassParentCopy = new ParentTestClass();

            // Act
            this.testCandidate.Copy(
                testClassParentOriginal,
                testClassParentCopy,
                new List <IBaseAdditionalProcessing>());

            var testClassParentCopyChildren = testClassParentCopy.Children.OfType <ChildTestClass>().ToList();

            // Assert
            // Make sure original and copy of the parent object are not the same.
            testClassParentCopy.Should().NotBeSameAs(testClassParentOriginal);

            // Don't forget to do this! Since the Children are a Collection the above wy of
            // retrieving the ist is not typesafe and some objects could fall between chairs and table.
            testClassParentCopyChildren.Count.Should().Be(3);

            foreach (var child in testClassParentCopyChildren)
            {
                child.ParentReference.Should().BeSameAs(testClassParentCopy);
            }
        }
Exemple #6
0
        public void Copy_MustNotFailWhenChildIsNull()
        {
            // Arrange
            var testClassParentOriginal = new ParentTestClass
            {
                Child = null,
            };

            var testClassParentCopy = new ParentTestClass();

            // Act
            this.testCandidate.Copy(
                testClassParentOriginal,
                testClassParentCopy,
                new List <IBaseAdditionalProcessing>());

            // Assert
            // Make sure original and copy of the parent object are not the same.
            testClassParentCopy.Should().NotBeSameAs(testClassParentOriginal);

            // Check if the Child of the copied class is null
            testClassParentCopy.Child.Should().BeNull();
        }