public void TestInsertAndIndexOf()
        {
            TVerificationResult           res0, res1, res2, res3, res4;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            // insert in the middle
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Noncritical);
            coll.Add(res1);
            res3 = new TVerificationResult(null, "test3", TResultSeverity.Resv_Noncritical);
            coll.Add(res3);
            Assert.AreEqual(0, coll.IndexOf(res1), "res1 should be at position 0");
            Assert.AreEqual(1, coll.IndexOf(res3), "res3 should be at position 1");
            res2 = new TVerificationResult(null, "test2", TResultSeverity.Resv_Noncritical);
            coll.Insert(1, res2);
            Assert.AreEqual(0, coll.IndexOf(res1), "res1 should be at position 0");
            Assert.AreEqual(1, coll.IndexOf(res2), "res2 should be at position 1");
            Assert.AreEqual(2, coll.IndexOf(res3), "res3 should be at position 2");

            // insert at the front
            res0 = new TVerificationResult(null, "test0", TResultSeverity.Resv_Noncritical);
            coll.Insert(0, res0);
            Assert.AreEqual(0, coll.IndexOf(res0), "res0 should be at position 0");
            Assert.AreEqual(1, coll.IndexOf(res1), "res1 should be at position 1");
            Assert.AreEqual(2, coll.IndexOf(res2), "res2 should be at position 2");
            Assert.AreEqual(3, coll.IndexOf(res3), "res3 should be at position 3");

            // insert at the back
            res4 = new TVerificationResult(null, "test4", TResultSeverity.Resv_Noncritical);
            coll.Insert(4, res4);
            Assert.AreEqual(0, coll.IndexOf(res0), "res0 should be at position 0");
            Assert.AreEqual(1, coll.IndexOf(res1), "res1 should be at position 1");
            Assert.AreEqual(2, coll.IndexOf(res2), "res2 should be at position 2");
            Assert.AreEqual(3, coll.IndexOf(res3), "res3 should be at position 3");
            Assert.AreEqual(4, coll.IndexOf(res4), "res4 should be at position 4");
        }
        public void TestRemove()
        {
            TVerificationResult           res0, res1, res4, res5, res6, res7;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            res0 = new TVerificationResult(null, "test0", TResultSeverity.Resv_Noncritical);
            coll.Add(res0);
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Noncritical);
            coll.Add(res1);
            DataColumn col = new DataColumn("test", typeof(int));

            res4 = new TScreenVerificationResult(null, col, "test4", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res4);
            DataTable  tab  = new DataTable("test");
            DataColumn col2 = new DataColumn("test2", typeof(string));

            tab.Columns.Add(col2);
            DataColumn col3 = new DataColumn("test3", typeof(string));

            tab.Columns.Add(col3);
            res5 = new TScreenVerificationResult(null, col2, "test5", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res5);
            res6 = new TScreenVerificationResult(null, col, "test6", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res6);
            res7 = new TScreenVerificationResult(null, col3, "test7", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res7);

            Assert.AreEqual(6, coll.Count, "should be 6 elements at the start of the test");

            // Remove(DataColumn)
            coll.Remove(col);
            Assert.AreEqual(5, coll.Count, "only one element should be removed, even if there are 2 results with column col");
            Assert.AreEqual(2, coll.IndexOf(res5), "res4 was removed");
            coll.Insert(2, res4);
            coll.Remove(new DataColumn("test"));
            Assert.AreEqual(6, coll.Count, "nothing happens when trying to remove unknown column");

            // Remove(IResultInterface value)
            coll.Remove(res1);
            Assert.AreEqual(5, coll.Count, "res1 should have been removed");
            coll.Insert(1, res1);
            Assert.Throws(typeof(ArgumentException),
                          delegate { coll.Remove(new TVerificationResult(null, "test3", TResultSeverity.Resv_Info)); },
                          "trying to remove unknown verification result throws ArgumentException");

            // Remove(String AResultColumnName)
            coll.Remove("nonexisting");
            Assert.AreEqual(6, coll.Count, "nothing happens when trying to remove unknown resultcolumnname");
            coll.Remove(col.ColumnName);
            Assert.AreEqual(5, coll.Count, "should have removed res4");
            Assert.AreEqual(res6, coll.FindBy(col), "first result with col should be res6");
            coll.Insert(4, res4);
        }
        public void TestBuildScreenVerificationResultList()
        {
            TVerificationResult           res0, res1, res2, res3, res4, res5, res6, res7, res8, res9, res10;
            TVerificationResultCollection coll = new TVerificationResultCollection();

            res0 = new TVerificationResult(null, "test0", TResultSeverity.Resv_Noncritical);
            coll.Add(res0);
            res1 = new TVerificationResult(null, "test1", TResultSeverity.Resv_Info);
            coll.Add(res1);
            TextBox tb1 = new TextBox();

            res2 = new TVerificationResult(tb1, "test2", TResultSeverity.Resv_Critical);
            coll.Add(res2);
            res3 = new TVerificationResult(tb1, "test3", TResultSeverity.Resv_Noncritical);
            coll.Add(res3);
            DataColumn col = new DataColumn("test", typeof(int));

            res4 = new TScreenVerificationResult(null, col, "test4", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res4);
            DataTable  tab  = new DataTable("test");
            DataColumn col2 = new DataColumn("test2", typeof(string));

            tab.Columns.Add(col2);
            DataColumn col3 = new DataColumn("test3", typeof(string));

            tab.Columns.Add(col3);
            res5 = new TScreenVerificationResult(null, col2, "test5", null, TResultSeverity.Resv_Status);
            coll.Add(res5);
            res6 = new TScreenVerificationResult(null, col, "test6", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res6);
            res7 = new TScreenVerificationResult(null, col3, "test7", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res7);
            res8 = new TScreenVerificationResult("test8", col3, "test8", null, TResultSeverity.Resv_Noncritical);
            coll.Add(res8);

            string  ErrorMessages;
            Control FirstControl;

            coll.BuildScreenVerificationResultList(null, out ErrorMessages, out FirstControl, true);

            Console.WriteLine(ErrorMessages);
            Console.WriteLine(ErrorMessages.Replace("\n", "\\n").Replace("\r", "\\r"));

            string expectedErrorMessages =
                "test4\r\n\r\ntest5\r\n\r\ntest6\r\n\r\ntest7\r\n\r\n";

            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "only show errors of unspecified resultcontext and of TVerificationScreenResult");

            coll.BuildScreenVerificationResultList("test8", out ErrorMessages, out FirstControl, true);

            Console.WriteLine(ErrorMessages);
            Console.WriteLine(ErrorMessages.Replace("\n", "\\n").Replace("\r", "\\r"));

            expectedErrorMessages =
                "test8\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "only show errors of resultcontext test1 and of TVerificationScreenResult");

            // test first control, but with updatefirstcontrol false
            TextBox tb2 = new TextBox();

            res9 = new TScreenVerificationResult(null, null, "test9", tb2, TResultSeverity.Resv_Critical);
            coll.Add(res9);
            TextBox tb3 = new TextBox();

            res10 = new TScreenVerificationResult(null, null, "test10", tb3, TResultSeverity.Resv_Critical);
            coll.Add(res10);
            coll.BuildScreenVerificationResultList(null, out ErrorMessages, out FirstControl, false);

            Console.WriteLine(ErrorMessages);
            Console.WriteLine(ErrorMessages.Replace("\n", "\\n").Replace("\r", "\\r"));

            expectedErrorMessages =
                "test4\r\n\r\ntest5\r\n\r\ntest6\r\n\r\ntest7\r\n\r\ntest9\r\n\r\ntest10\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "added test9 and test10");
            Assert.AreEqual(tb2, FirstControl, "expect to return tb2 as first control");
            Assert.AreEqual(null, coll.FirstErrorControl, "expect to not select tb2 as first control");

            // test updatefirstcontrol true
            coll.BuildScreenVerificationResultList(null, out ErrorMessages, out FirstControl, true);
            Assert.AreEqual(tb2, FirstControl, "expect to return tb2 as first control");
            Assert.AreEqual(tb2, coll.FirstErrorControl, "expect to select tb2 as first control");

            // remove res9, so that first control is tb3, but call with updatefirstcontrol false
            coll.Remove(res9);
            coll.BuildScreenVerificationResultList(null, out ErrorMessages, out FirstControl, false);
            Assert.AreEqual(tb3, FirstControl, "expect to return tb3 as first control");
            Assert.AreEqual(tb2, coll.FirstErrorControl, "expect tb2 to be still selected as first control");

            // test other overload of BuildScreenVerificationResult, ignorewarnings etc
            object FirstErrorContext;

            // test ignorewarnings true
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, true, null, true);

            Assert.AreEqual(null, FirstErrorContext, "FirstErrorContext is null");

            Console.WriteLine(ErrorMessages);
            Console.WriteLine(ErrorMessages.Replace("\n", "\\n").Replace("\r", "\\r"));

            expectedErrorMessages = "test1\r\n\r\ntest2\r\n\r\ntest5\r\n\r\ntest10\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "ignore warnings (ie. noncritical). Include TVerificationResults");

            // test ignorewarnings false
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, true, null, false);

            Console.WriteLine(ErrorMessages);
            Console.WriteLine(ErrorMessages.Replace("\n", "\\n").Replace("\r", "\\r"));

            expectedErrorMessages =
                "test0\r\n\r\ntest1\r\n\r\ntest2\r\n\r\ntest3\r\n\r\ntest4\r\n\r\ntest5\r\n\r\ntest6\r\n\r\ntest7\r\n\r\ntest8\r\n\r\ntest10\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "do not ignore warnings (ie. noncritical). Include TVerificationResults");

            // test ARestrictToTypeWhichRaisesError, restrict to string errorcontext
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, true, typeof(string), false);
            Console.WriteLine(ErrorMessages);
            Console.WriteLine(ErrorMessages.Replace("\n", "\\n").Replace("\r", "\\r"));

            expectedErrorMessages =
                "test8\r\n\r\n";
            Assert.AreEqual(expectedErrorMessages, ErrorMessages, "restrict to string errorcontext");

            // test AUpdateFirstErrorControl
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, true, null, false);
            // it seems that res2/tb1 is ignored, because it is not a screenverificationresult
            Assert.AreEqual(tb3, FirstControl, "first control should be tb3");
            Assert.AreEqual(tb3, coll.FirstErrorControl, "first error control should be tb3");
            // now testing with res8/tb3 inserted before tb2, and not updating first error control
            coll.Insert(3, res9);
            coll.BuildScreenVerificationResultList(out ErrorMessages, out FirstControl, out FirstErrorContext, false, null, false);
            Assert.AreEqual(tb2, FirstControl, "first control should be tb2");
            Assert.AreEqual(tb3, coll.FirstErrorControl, "first error control should still be tb3");
        }