Beispiel #1
0
        public void TestAdd()
        {
            List <SimpleTreeObjectCollection> testObjectList;
            SimpleTreeObjectCollection        root;

            GenerateTestTree(out root, out testObjectList);

            // Add method #1
            var addObject0 = new SimpleTreeObjectCollection()
            {
                Name = "Added Object 0", Parent = root
            };

            testContextInstance.WriteLine("TestAdd: Added: {0}", addObject0);
            testObjectList.AddRange(addObject0);

            // Add method #2
            var addObject1 = new SimpleTreeObjectCollection()
            {
                Name = "Added Object 1", Parent = null
            };

            addObject0.Children.Add(addObject1);
            testContextInstance.WriteLine("TestAdd: Added: {0}", addObject1);
            testObjectList.AddRange(addObject1);

            int matchCount = testObjectList.Count;

            foreach (var z in root)
            {
                if (testObjectList.Contains(z))
                {
                    testContextInstance.WriteLine("TestEnumerate: Found {0}", z);
                    matchCount--;
                }
            }

            if (matchCount != 0)
            {
                throw new AssertFailedException(
                          String.Format(
                              CultureInfo.InvariantCulture,
                              "TestEnumerate: Test was not able to enumerate the entire tree. {0} expected, {1} returned",
                              testObjectList.Count,
                              testObjectList.Count - matchCount));
            }
        }
Beispiel #2
0
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        #endregion

        private static void GenerateTestTree(out SimpleTreeObjectCollection root, out List <SimpleTreeObjectCollection> testObjectList)
        {
            testObjectList = new List <SimpleTreeObjectCollection>();
            root           = new SimpleTreeObjectCollection()
            {
                Name = "Root"
            };
            testObjectList.Add(root);

            var a0 = new SimpleTreeObjectCollection()
            {
                Name = "A0", Parent = root
            };

            testObjectList.Add(a0);

            var a1 = new SimpleTreeObjectCollection()
            {
                Name = "A1", Parent = a0
            };

            testObjectList.Add(a1);

            var a2 = new SimpleTreeObjectCollection()
            {
                Name = "A2", Parent = a1
            };

            testObjectList.Add(a2);

            var b1 = new SimpleTreeObjectCollection()
            {
                Name = "B1", Parent = a0
            };

            testObjectList.Add(b1);

            var b2 = new SimpleTreeObjectCollection()
            {
                Name = "B2", Parent = b1
            };

            testObjectList.Add(b2);

            ////int matchCount = testObjectList.Count;
        }