src/GenFx.Components.Tests/TreeEntityBaseTest.cs
/// <summary>
/// Tests that the SetRootNode method works correctly.
/// </summary>
Tests that the SetRootNode method works correctly.
Tests that the SetRootNode method works correctly .
[Fact]
        public void TreeEntityBase_SetRootNode()
        {
            GeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                PopulationSeed = new MockPopulation(),
                SelectionOperator = new MockSelectionOperator(),
                FitnessEvaluator = new MockFitnessEvaluator(),
                GeneticEntitySeed = new TestTreeEntity()
            };
            TestTreeEntity entity = new TestTreeEntity();
            entity.Initialize(algorithm);
            TreeNode node = new TreeNode();
            TreeNode childNode = new TreeNode();
            PrivateObject nodeAccessor = new PrivateObject(childNode);
            nodeAccessor.SetField("parentNode", node);
            TreeNode grandChildNode = new TreeNode();
            node.ChildNodes.Add(childNode);
            childNode.ChildNodes.Add(grandChildNode);
            entity.SetRootNode(childNode);
            Assert.Same(childNode, entity.RootNode);
            Assert.Null(childNode.ParentNode);
            Assert.Same(entity, childNode.Tree);
            Assert.Same(entity, grandChildNode.Tree);
        }
[ Fact ] public void TreeEntityBase_SetRootNode ( ) { GeneticAlgorithm algorithm = new MockGeneticAlgorithm { PopulationSeed = new MockPopulation ( ) , SelectionOperator = new MockSelectionOperator ( ) , FitnessEvaluator = new MockFitnessEvaluator ( ) , GeneticEntitySeed = new TestTreeEntity ( ) } ; TestTreeEntity entity = new TestTreeEntity ( ) ; entity . Initialize ( algorithm ) ; TreeNode node = new TreeNode ( ) ; TreeNode childNode = new TreeNode ( ) ; PrivateObject nodeAccessor = new PrivateObject ( childNode ) ; nodeAccessor . SetField ( " " , node ) ; TreeNode grandChildNode = new TreeNode ( ) ; node . ChildNodes . Add ( childNode ) ; childNode . ChildNodes . Add ( grandChildNode ) ; entity . SetRootNode ( childNode ) ; Assert . Same ( childNode , entity . RootNode ) ; Assert . Null ( childNode . ParentNode ) ; Assert . Same ( entity , childNode . Tree ) ; Assert . Same ( entity , grandChildNode . Tree ) ; }
Tests that the SetRootNode method works correctly.
Tests that the SetRootNode method works correctly .