Ejemplo n.º 1
0
        //Get all immediate children.
        //If recursive = true will recursively find grandchildren.
        List <ISignalContent> ISignalContainer.GetChildren(List <ISignalContent> collectorArray, bool recursive)
        {
            //ensure we have a collector array - create one otherwise
            if (collectorArray == null)
            {
                collectorArray = new List <ISignalContent>();
            }

            //save our list of children onto the collector array
            collectorArray.AddRange(contents);

            //Recursively append children if requested
            if (recursive)
            {
                //access children as ISignalContainer and propagate request only to fitting children
                foreach (ISignalContent child in contents)
                {
                    ISignalContainer containerChild = child as ISignalContainer;
                    if (containerChild != null)
                    {
                        containerChild.GetChildren(collectorArray, recursive);
                    }
                }
            }
            //finally return a reference to the collector array
            return(collectorArray);
        }
        public void UTSignalFragmentRemoveChildren2()
        {
            ISignalContainer testItem1 = (new SignalFragment(
                                              new List <ISignalContent> {
                new Wave(1, 0),
                new Wave(1, 2),
                new SignalFragment(0, new List <ISignalContent> {
                    new Wave(1, 1)
                }),
                new SignalFragment(3, new List <ISignalContent> {
                    new Wave(1, 8),
                }),
            }
                                              ) as ISignalContainer);

            Assert.AreEqual(testItem1.GetChildren(recursive: false).Count, 4);
            testItem1.RemoveChildren();
            Assert.AreEqual(testItem1.GetChildren(recursive: false).Count, 0);
        }
        public void UTSignalFragmentRemoveChildren1()
        {
            List <ISignalContent> testItemList = new List <ISignalContent> {
                new Wave(1, 0), new Wave(1, 2)
            };
            ISignalContainer testItem1 = (new SignalFragment(
                                              new List <ISignalContent> {
                testItemList[0],
                new SignalFragment(0, new List <ISignalContent> {
                    new Wave(1, 1)
                }),
                new SignalFragment(3, new List <ISignalContent> {
                    new Wave(1, 8),
                }),
                testItemList[1],
            }
                                              ) as ISignalContainer);

            Assert.AreEqual(testItem1.GetChildren(recursive: false).Count, 4);
            testItem1.RemoveChildren(testItemList);
            Assert.AreEqual(testItem1.GetChildren(recursive: false).Count, 2);
        }
        public void UTSignalFragmentRemoveChild1()
        {
            Wave             waveTestItem  = new Wave(1, 0);
            Wave             waveTestItem2 = new Wave(1, 0);
            ISignalContainer testItem1     = (new SignalFragment(
                                                  new List <ISignalContent> {
                waveTestItem,
                waveTestItem2,
                new SignalFragment(0, new List <ISignalContent> {
                    new Wave(1, 1)
                }),
                new SignalFragment(3, new List <ISignalContent> {
                    new Wave(1, 8),
                }),
                waveTestItem2,
            }
                                                  ) as ISignalContainer);

            Assert.AreEqual(testItem1.GetChildren(recursive: false).Count, 5);
            testItem1.RemoveChild(waveTestItem as ISignalContent);
            Assert.AreEqual(testItem1.GetChildren(recursive: false).Count, 4);
            testItem1.RemoveChild(waveTestItem2 as ISignalContent);
            Assert.AreEqual(testItem1.GetChildren(recursive: false).Count, 2);
        }