Exemplo n.º 1
0
    public bool runTest()
    {
        //////////// Global Variables used for all tests
        int iCountErrors    = 0;
        int iCountTestcases = 0;

        MyDictionaryBase mycol1;
        MyDictionaryBase mycol2;
        FooKey           fk1;
        FooValue         fv1;

        FooKey[]              arrFK1;
        FooValue[]            arrFV1;
        IDictionaryEnumerator enu1;
        Int32 iCount;

        DictionaryEntry[] arrDicEnt1;
        DictionaryEntry   dicEnt1;
        Object            obj1;

        //		ICollection icol1;
        try
        {
            do
            {
                /////////////////////////  START TESTS ////////////////////////////

                //[]DictionaryBase implements IDictionary (which means both ICollection and IEnumerator as well :-()
                //To test this class, we will implement our own strongly typed DictionaryBase and call its methods
                iCountTestcases++;

                //[] Count property
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                if (mycol1.Count != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count);
                }
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                if (mycol1.Count != 100)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count);
                }
                //[]CopyTo
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                arrDicEnt1 = new DictionaryEntry[100];
                mycol1.CopyTo(arrDicEnt1, 0);
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                for (int i = 0; i < 100; i++)
                {
                    arrFK1[i] = (FooKey)arrDicEnt1[i].Key;
                    arrFV1[i] = (FooValue)arrDicEnt1[i].Value;
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);

                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_93765dg_" + i + "! Expected value not returned");
                    }
                }


                //Argument checking
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                arrDicEnt1 = new DictionaryEntry[100];
                try
                {
                    mycol1.CopyTo(arrDicEnt1, 50);

                    iCountErrors++;
                    Console.WriteLine("Err_2075dfgv! Exception not thrown");
                }
                catch (ArgumentException)
                {
                }
                catch (Exception ex)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name);
                }

                try
                {
                    mycol1.CopyTo(arrDicEnt1, -1);

                    iCountErrors++;
                    Console.WriteLine("Err_2075dfgv! Exception not thrown");
                }
                catch (ArgumentException)
                {
                }
                catch (Exception ex)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name);
                }

                arrDicEnt1 = new DictionaryEntry[200];
                mycol1.CopyTo(arrDicEnt1, 100);
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                for (int i = 0; i < 100; i++)
                {
                    arrFK1[i] = (FooKey)arrDicEnt1[i + 100].Key;
                    arrFV1[i] = (FooValue)arrDicEnt1[i + 100].Value;
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);

                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_974gd_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2075sg_" + i + "! Expected value not returned");
                    }
                }

                //[]GetEnumerator
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }

                enu1 = mycol1.GetEnumerator();
                //Calling current should throw here
                try
                {
                    //Calling current should throw here
                    dicEnt1 = (DictionaryEntry)enu1.Current;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //Calling Key should throw here
                try
                {
                    //Calling current should throw here
                    fk1 = (FooKey)enu1.Key;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //Calling Value should throw here
                try
                {
                    //Calling current should throw here
                    fv1 = (FooValue)enu1.Value;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                iCount = 0;
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                while (enu1.MoveNext())
                {
                    dicEnt1 = (DictionaryEntry)enu1.Current;

                    arrFK1[iCount] = (FooKey)dicEnt1.Key;
                    arrFV1[iCount] = (FooValue)dicEnt1.Value;

                    fk1 = (FooKey)enu1.Key;
                    if (fk1 != arrFK1[iCount])
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue);
                    }

                    fv1 = (FooValue)enu1.Value;
                    if (fv1 != arrFV1[iCount])
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_29075gd_" + iCount + "! Expected value not returned, " + arrFV1[iCount].IValue);
                    }

                    iCount++;
                }
                if (iCount != 100)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_87543! doesnot match");
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);

                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_275g_" + i + "! Expected value not returned");
                    }
                }

                try
                {
                    //Calling current should throw here
                    dicEnt1 = (DictionaryEntry)enu1.Current;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //Calling Key should throw here
                try
                {
                    //Calling current should throw here
                    fk1 = (FooKey)enu1.Key;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //Calling Value should throw here
                try
                {
                    //Calling current should throw here
                    fv1 = (FooValue)enu1.Value;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //[] IEnumerable.GetEnumerator
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }

                IEnumerator iEnumerator1 = ((IEnumerable)mycol1).GetEnumerator();
                //Calling current should throw here
                try
                {
                    //Calling current should throw here
                    dicEnt1 = (DictionaryEntry)iEnumerator1.Current;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                iCount = 0;
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                while (iEnumerator1.MoveNext())
                {
                    dicEnt1 = (DictionaryEntry)iEnumerator1.Current;

                    arrFK1[iCount] = (FooKey)dicEnt1.Key;
                    arrFV1[iCount] = (FooValue)dicEnt1.Value;

                    if (mycol1[arrFK1[iCount]] != arrFV1[iCount])
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue);
                    }

                    iCount++;
                }
                if (iCount != 100)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_87543! doesnot match");
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);

                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_275g_" + i + "! Expected value not returned");
                    }
                }

                try
                {
                    //Calling current should throw here
                    dicEnt1 = (DictionaryEntry)iEnumerator1.Current;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //[]IsSynchronized
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                if (mycol1.IsSynchronized)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_275eg! Expected value not returned, " + mycol1.IsSynchronized);
                }

                //[]SyncRoot
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                obj1   = mycol1.SyncRoot;
                mycol2 = mycol1;
                if (obj1 != mycol2.SyncRoot)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9745sg! Expected value not returned");
                }

                //End of ICollection and IEnumerator methods
                //Now to IDictionary methods
                //[]Add, this, Contains, Remove, Clear
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                for (int i = 0; i < 100; i++)
                {
                    if ((mycol1[new FooKey(i, i.ToString())].IValue != i) || (mycol1[new FooKey(i, i.ToString())].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned");
                    }
                }
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Remove(new FooKey(i, i.ToString()));
                    if ((mycol1.Count != (99 - i)))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned");
                    }
                    if ((mycol1.Contains(new FooKey(i, i.ToString()))))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_975wg_" + i + "! Expected value not returned");
                    }
                }

                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                mycol1.Clear();
                if (mycol1.Count != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count);
                }

                //[]Rest of the IList methods: this-set, IsFixedSize, IsReadOnly, Keys, Values
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                if (mycol1.IsFixedSize)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize);
                }
                if (mycol1.IsReadOnly)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly);
                }
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                for (int i = 0, j = 100; i < 100; i++, j--)
                {
                    mycol1[new FooKey(i, i.ToString())] = new FooValue(j, j.ToString());
                }
                for (int i = 0, j = 100; i < 100; i++, j--)
                {
                    if ((mycol1[new FooKey(i, i.ToString())].IValue != j) || (mycol1[new FooKey(i, i.ToString())].SValue != j.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned");
                    }
                }

                mycol1 = new MyDictionaryBase();
                mycol1.Add(new FooKey(), new FooValue());
                ///////////////////////////////////////////////////////////////////
                /////////////////////////// END TESTS /////////////////////////////
            } while (false);
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString());
        }

        ////  Finish Diagnostics
        if (iCountErrors == 0)
        {
            return(true);
        }
        else
        {
            Console.WriteLine("Fail!  iCountErrors==" + iCountErrors);
            return(false);
        }
    }
    public bool runTest()
    {
        //////////// Global Variables used for all tests
        int iCountErrors    = 0;
        int iCountTestcases = 0;

        MyDictionaryBase myDict;
        Foo    f, newF;
        string expectedExceptionMessage;

        try
        {
            do
            {
                /////////////////////////  START TESTS ////////////////////////////
                ///////////////////////////////////////////////////////////////////

                /***********************************************************************************************************************
                *               Add
                ***********************************************************************************************************************/

                //[] Vanilla Add
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f      = new Foo();
                myDict.Add(f, 0.ToString());
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnInsertCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_4072ayps OnInsertComplete was never called");
                }
                else if (!myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0181salh Item was added");
                }

                //[] Add where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnValidateThrow   = true;
                expectedExceptionMessage = "OnValidate";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    iCountErrors++;
                    Console.WriteLine("Err_1570pyqa Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2708apsa Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnInsertCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_56707awwaps OnInsert was called");
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2708apsa Expected Empty Collection actual {0} elements", myDict.Count);
                }

                //[] Add where OnInsert throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnInsertThrow     = true;
                expectedExceptionMessage = "OnInsert";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    iCountErrors++;
                    Console.WriteLine("Err_35208asdo Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_30437sfdah Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnInsertCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_370asjhs OnInsertComplete was called");
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_3y07aza Expected Empty Collection actual {0} elements", myDict.Count);
                }

                //[] Add where OnInsertComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnInsertCompleteThrow = true;
                expectedExceptionMessage     = "OnInsertComplete";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    iCountErrors++;
                    Console.WriteLine("Err_2548ashz Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2708alkw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_3680ahksd Expected Empty Collection actual {0} elements", myDict.Count);
                }

                /***********************************************************************************************************************
                *               Remove
                ***********************************************************************************************************************/

                //[] Vanilla Remove
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f      = new Foo();

                myDict.Add(f, 0.ToString());
                myDict.Remove(f);
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnRemoveCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_348awq OnRemoveComplete was never called");
                }
                else if (myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0824answ  Item was not removed");
                }

                //[] Remove where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                expectedExceptionMessage = "OnValidate";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.OnValidateThrow = true;
                    myDict.Remove(f);
                    iCountErrors++;
                    Console.WriteLine("Err_08207hnas Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_87082aspz Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnRemoveCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_7207snmqla OnRemove was called");
                }
                else if (!myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_7270pahnz Element was actually removed {0}", myDict.Contains(f));
                }

                //[] Remove where OnRemove throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnRemoveThrow     = true;
                expectedExceptionMessage = "OnRemove";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.Remove(f);
                    iCountErrors++;
                    Console.WriteLine("Err_7708aqyy Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_08281naws Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnRemoveCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_10871aklsj OnRemoveComplete was called");
                }
                else if (!myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2081aslkjs Element was actually removed {0}", myDict.Contains(f));
                }

                //[] Remove where OnRemoveComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnRemoveCompleteThrow = true;
                expectedExceptionMessage     = "OnRemoveComplete";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.Remove(f);
                    iCountErrors++;
                    Console.WriteLine("Err_10981nlskj Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_20981askjs Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_20909assfd Element was actually removed {0}", myDict.Contains(f));
                }

                /***********************************************************************************************************************
                *               Clear
                ***********************************************************************************************************************/

                //[] Vanilla Clear
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f      = new Foo();

                myDict.Add(f, 0.ToString());
                myDict.Clear();
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnClearCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2136sdf OnClearComplete was never called");
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9494aswa  Items were not Cleared");
                }

                //[] Clear where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                expectedExceptionMessage = "OnValidate";
                f = new Foo();

                myDict.Add(f, 0.ToString());
                myDict.OnValidateThrow = true;
                myDict.Clear();

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnClearCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6549asff OnClearComplete was not called");
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_4649awajm Items were Cleared");
                }

                //[] Clear where OnClear throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnClearThrow      = true;
                expectedExceptionMessage = "OnClear";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.Clear();
                    iCountErrors++;
                    Console.WriteLine("Err_9444sjpjnException was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_78941joaException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnClearCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_94944awfuu OnClearComplete was called");
                }
                else if (1 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6498  Items were not Cleared");
                }

                //[] Clear where OnClearComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnClearCompleteThrow = true;
                expectedExceptionMessage    = "OnClearComplete";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.Clear();
                    iCountErrors++;
                    Console.WriteLine("Err_64977awad Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_0877asaw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_1081lkajs  Items were not Cleared");
                }


                /***********************************************************************************************************************
                *               Set that adds an item
                ***********************************************************************************************************************/

                //[] Vanilla Set
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f      = new Foo(1, "1");
                newF   = new Foo(2, "2");

                myDict.Add(f, 1.ToString());
                myDict[newF] = 2.ToString();
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnSetCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_1698asdf OnSetComplete was never called");
                }
                else if (!myDict.Contains(f) || !myDict.Contains(newF))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9494safs  Item was not Set");
                }

                //[] Set where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                expectedExceptionMessage = "OnValidate";
                f    = new Foo(1, "1");
                newF = new Foo(2, "2");
                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict.OnValidateThrow = true;
                    myDict[newF]           = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_611awwa Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_69498hph Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnSetCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_94887jio OnSet was called");
                }
                else if (!myDict.Contains(f) || myDict.Contains(newF))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6549ihyopiu Element was actually Set {0}", myDict.Contains(f));
                }

                //[] Set where OnSet throws
                iCountTestcases++;
                myDict                   = new MyDictionaryBase();
                myDict.OnSetThrow        = true;
                expectedExceptionMessage = "OnSet";
                f    = new Foo(1, "1");
                newF = new Foo(2, "2");
                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict[newF] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_61518haiosd Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_196198sdklhsException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnSetCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6548dasfs OnSetComplete was called");
                }
                else if (!myDict.Contains(f) || myDict.Contains(newF))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2797sah Element was actually Set {0}", myDict.Contains(f));
                }

                //[] Set where OnSetComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnSetCompleteThrow = true;
                expectedExceptionMessage  = "OnSetComplete";
                f    = new Foo(1, "1");
                newF = new Foo(2, "2");
                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict[newF] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_56498hkashException was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_13168hsaiuh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.Contains(f) || myDict.Contains(newF))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_64198ahihos Element was actually Set {0}", myDict.Contains(f));
                }

                /***********************************************************************************************************************
                *               Set that sets an existing item
                ***********************************************************************************************************************/

                //[] Vanilla Set
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f      = new Foo(1, "1");

                myDict.Add(f, 1.ToString());
                myDict[f] = 2.ToString();
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnSetCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_1698asdf OnSetComplete was never called");
                }
                else if (!myDict.Contains(f) || myDict[f] != "2")
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9494safs  Item was not Set");
                }

                //[] Set where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                expectedExceptionMessage = "OnValidate";
                f = new Foo(1, "1");
                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict.OnValidateThrow = true;
                    myDict[f] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_611awwa Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_69498hph Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnSetCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_94887jio OnSet was called");
                }
                else if (!myDict.Contains(f) || myDict[f] != "1")
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6549ihyopiu Element was actually Set {0}", myDict.Contains(f));
                }

                //[] Set where OnSet throws
                iCountTestcases++;
                myDict                   = new MyDictionaryBase();
                myDict.OnSetThrow        = true;
                expectedExceptionMessage = "OnSet";
                f = new Foo(1, "1");

                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict[f] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_61518haiosd Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_196198sdklhsException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnSetCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6548dasfs OnSetComplete was called");
                }
                else if (!myDict.Contains(f) || myDict[f] != "1")
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2797sah Element was actually Set {0}", myDict.Contains(f));
                }

                //[] Set where OnSetComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnSetCompleteThrow = true;
                expectedExceptionMessage  = "OnSetComplete";
                f = new Foo(1, "1");

                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict[f] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_56498hkashException was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_13168hsaiuh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.Contains(f) || myDict[f] != "1")
                {
                    iCountErrors++;
                    Console.WriteLine("Err_64198ahihos Element was actually Set {0}", myDict.Contains(f));
                }
                /////////////////////////// END TESTS /////////////////////////////
            } while (false);
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString());
        }


        ////  Finish Diagnostics
        if (iCountErrors == 0)
        {
            return(true);
        }
        else
        {
            Console.WriteLine("Fail iCountErrors==" + iCountErrors);
            return(false);
        }
    }
Exemplo n.º 3
0
    public bool runTest()
    {

        //////////// Global Variables used for all tests
        int iCountErrors = 0;
        int iCountTestcases = 0;

        MyDictionaryBase mycol1;
        MyDictionaryBase mycol2;
        FooKey fk1;
        FooValue fv1;
        FooKey[] arrFK1;
        FooValue[] arrFV1;
        IDictionaryEnumerator enu1;
        Int32 iCount;

        DictionaryEntry[] arrDicEnt1;
        DictionaryEntry dicEnt1;
        Object obj1;

        //		ICollection icol1;
        try
        {
            do
            {
                /////////////////////////  START TESTS ////////////////////////////

                //[]DictionaryBase implements IDictionary (which means both ICollection and IEnumerator as well :-()
                //To test this class, we will implement our own strongly typed DictionaryBase and call its methods
                iCountTestcases++;

                //[] Count property
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                if (mycol1.Count != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count);
                }
                for (int i = 0; i < 100; i++)
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                if (mycol1.Count != 100)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count);
                }
                //[]CopyTo
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                arrDicEnt1 = new DictionaryEntry[100];
                mycol1.CopyTo(arrDicEnt1, 0);
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                for (int i = 0; i < 100; i++)
                {
                    arrFK1[i] = (FooKey)arrDicEnt1[i].Key;
                    arrFV1[i] = (FooValue)arrDicEnt1[i].Value;
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);

                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_93765dg_" + i + "! Expected value not returned");
                    }
                }


                //Argument checking
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                arrDicEnt1 = new DictionaryEntry[100];
                try
                {
                    mycol1.CopyTo(arrDicEnt1, 50);

                    iCountErrors++;
                    Console.WriteLine("Err_2075dfgv! Exception not thrown");
                }
                catch (ArgumentException)
                {
                }
                catch (Exception ex)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name);
                }

                try
                {
                    mycol1.CopyTo(arrDicEnt1, -1);

                    iCountErrors++;
                    Console.WriteLine("Err_2075dfgv! Exception not thrown");
                }
                catch (ArgumentException)
                {
                }
                catch (Exception ex)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name);
                }

                arrDicEnt1 = new DictionaryEntry[200];
                mycol1.CopyTo(arrDicEnt1, 100);
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                for (int i = 0; i < 100; i++)
                {
                    arrFK1[i] = (FooKey)arrDicEnt1[i + 100].Key;
                    arrFV1[i] = (FooValue)arrDicEnt1[i + 100].Value;
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);

                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_974gd_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2075sg_" + i + "! Expected value not returned");
                    }
                }

                //[]GetEnumerator
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));

                enu1 = mycol1.GetEnumerator();
                //Calling current should throw here
                try
                {
                    //Calling current should throw here
                    dicEnt1 = (DictionaryEntry)enu1.Current;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //Calling Key should throw here
                try
                {
                    //Calling current should throw here
                    fk1 = (FooKey)enu1.Key;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //Calling Value should throw here
                try
                {
                    //Calling current should throw here
                    fv1 = (FooValue)enu1.Value;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                iCount = 0;
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                while (enu1.MoveNext())
                {
                    dicEnt1 = (DictionaryEntry)enu1.Current;

                    arrFK1[iCount] = (FooKey)dicEnt1.Key;
                    arrFV1[iCount] = (FooValue)dicEnt1.Value;

                    fk1 = (FooKey)enu1.Key;
                    if (fk1 != arrFK1[iCount])
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue);
                    }

                    fv1 = (FooValue)enu1.Value;
                    if (fv1 != arrFV1[iCount])
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_29075gd_" + iCount + "! Expected value not returned, " + arrFV1[iCount].IValue);
                    }

                    iCount++;
                }
                if (iCount != 100)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_87543! doesnot match");
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);

                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_275g_" + i + "! Expected value not returned");
                    }
                }

                try
                {
                    //Calling current should throw here
                    dicEnt1 = (DictionaryEntry)enu1.Current;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //Calling Key should throw here
                try
                {
                    //Calling current should throw here
                    fk1 = (FooKey)enu1.Key;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //Calling Value should throw here
                try
                {
                    //Calling current should throw here
                    fv1 = (FooValue)enu1.Value;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //[] IEnumerable.GetEnumerator
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));

                IEnumerator iEnumerator1 = ((IEnumerable)mycol1).GetEnumerator();
                //Calling current should throw here
                try
                {
                    //Calling current should throw here
                    dicEnt1 = (DictionaryEntry)iEnumerator1.Current;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                iCount = 0;
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                while (iEnumerator1.MoveNext())
                {
                    dicEnt1 = (DictionaryEntry)iEnumerator1.Current;

                    arrFK1[iCount] = (FooKey)dicEnt1.Key;
                    arrFV1[iCount] = (FooValue)dicEnt1.Value;

                    if (mycol1[arrFK1[iCount]] != arrFV1[iCount])
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue);
                    }

                    iCount++;
                }
                if (iCount != 100)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_87543! doesnot match");
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);

                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_275g_" + i + "! Expected value not returned");
                    }
                }

                try
                {
                    //Calling current should throw here
                    dicEnt1 = (DictionaryEntry)iEnumerator1.Current;

                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }

                //[]IsSynchronized
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                if (mycol1.IsSynchronized)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_275eg! Expected value not returned, " + mycol1.IsSynchronized);
                }

                //[]SyncRoot
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                obj1 = mycol1.SyncRoot;
                mycol2 = mycol1;
                if (obj1 != mycol2.SyncRoot)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9745sg! Expected value not returned");
                }

                //End of ICollection and IEnumerator methods
                //Now to IDictionary methods
                //[]Add, this, Contains, Remove, Clear
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                for (int i = 0; i < 100; i++)
                {
                    if ((mycol1[new FooKey(i, i.ToString())].IValue != i) || (mycol1[new FooKey(i, i.ToString())].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned");
                    }
                }
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Remove(new FooKey(i, i.ToString()));
                    if ((mycol1.Count != (99 - i)))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned");
                    }
                    if ((mycol1.Contains(new FooKey(i, i.ToString()))))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_975wg_" + i + "! Expected value not returned");
                    }
                }

                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                mycol1.Clear();
                if (mycol1.Count != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count);
                }

                //[]Rest of the IList methods: this-set, IsFixedSize, IsReadOnly, Keys, Values
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                if (mycol1.IsFixedSize)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize);
                }
                if (mycol1.IsReadOnly)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly);
                }
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                for (int i = 0, j = 100; i < 100; i++, j--)
                    mycol1[new FooKey(i, i.ToString())] = new FooValue(j, j.ToString());
                for (int i = 0, j = 100; i < 100; i++, j--)
                {
                    if ((mycol1[new FooKey(i, i.ToString())].IValue != j) || (mycol1[new FooKey(i, i.ToString())].SValue != j.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned");
                    }
                }

                mycol1 = new MyDictionaryBase();
                mycol1.Add(new FooKey(), new FooValue());
                ///////////////////////////////////////////////////////////////////
                /////////////////////////// END TESTS /////////////////////////////


            } while (false);
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString());
        }

        ////  Finish Diagnostics
        if (iCountErrors == 0)
        {
            return true;
        }
        else
        {
            Console.WriteLine("Fail!  iCountErrors==" + iCountErrors);
            return false;
        }

    }
Exemplo n.º 4
0
    public bool runTest()
    {
        Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
        int              iCountErrors    = 0;
        int              iCountTestcases = 0;
        String           strLoc          = "Loc_000oo";
        MyDictionaryBase mycol1;
        MyDictionaryBase mycol2;
        FooKey           fk1;
        FooValue         fv1;

        FooKey[]              arrFK1;
        FooValue[]            arrFV1;
        IDictionaryEnumerator enu1;
        Int32 iCount;

        DictionaryEntry[] arrDicEnt1;
        DictionaryEntry   dicEnt1;
        Object            obj1;

        try
        {
            do
            {
                iCountTestcases++;
                iCountTestcases++;
                strLoc = "Loc_001oo";
                mycol1 = new MyDictionaryBase();
                if (mycol1.Count != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count);
                }
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                if (mycol1.Count != 100)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count);
                }
                iCountTestcases++;
                strLoc = "Loc_002oo";
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                arrDicEnt1 = new DictionaryEntry[100];
                mycol1.CopyTo(arrDicEnt1, 0);
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                for (int i = 0; i < 100; i++)
                {
                    arrFK1[i] = (FooKey)arrDicEnt1[i].Key;
                    arrFV1[i] = (FooValue)arrDicEnt1[i].Value;
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);
                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_93765dg_" + i + "! Expected value not returned");
                    }
                }
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                arrDicEnt1 = new DictionaryEntry[100];
                try
                {
                    mycol1.CopyTo(arrDicEnt1, 50);
                    iCountErrors++;
                    Console.WriteLine("Err_2075dfgv! Exception not thrown");
                }
                catch (ArgumentException)
                {
                }
                catch (Exception ex)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name);
                }
                try
                {
                    mycol1.CopyTo(arrDicEnt1, -1);
                    iCountErrors++;
                    Console.WriteLine("Err_2075dfgv! Exception not thrown");
                }
                catch (ArgumentException)
                {
                }
                catch (Exception ex)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name);
                }
                arrDicEnt1 = new DictionaryEntry[200];
                mycol1.CopyTo(arrDicEnt1, 100);
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                for (int i = 0; i < 100; i++)
                {
                    arrFK1[i] = (FooKey)arrDicEnt1[i + 100].Key;
                    arrFV1[i] = (FooValue)arrDicEnt1[i + 100].Value;
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);
                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_974gd_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2075sg_" + i + "! Expected value not returned");
                    }
                }
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                enu1 = mycol1.GetEnumerator();
                try
                {
                    dicEnt1 = (DictionaryEntry)enu1.Current;
                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }
                try
                {
                    fk1 = (FooKey)enu1.Key;
                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }
                try
                {
                    fv1 = (FooValue)enu1.Value;
                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }
                iCount = 0;
                arrFK1 = new FooKey[100];
                arrFV1 = new FooValue[100];
                while (enu1.MoveNext())
                {
                    dicEnt1        = (DictionaryEntry)enu1.Current;
                    arrFK1[iCount] = (FooKey)dicEnt1.Key;
                    arrFV1[iCount] = (FooValue)dicEnt1.Value;
                    fk1            = (FooKey)enu1.Key;
                    if (fk1 != arrFK1[iCount])
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue);
                    }
                    fv1 = (FooValue)enu1.Value;
                    if (fv1 != arrFV1[iCount])
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_29075gd_" + iCount + "! Expected value not returned, " + arrFV1[iCount].IValue);
                    }
                    iCount++;
                }
                if (iCount != 100)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_87543! doesnot match");
                }
                Array.Sort(arrFK1);
                Array.Sort(arrFV1);
                for (int i = 0; i < 100; i++)
                {
                    if ((arrFK1[i].IValue != i) || (arrFK1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                    }
                    if ((arrFV1[i].IValue != i) || (arrFV1[i].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_275g_" + i + "! Expected value not returned");
                    }
                }
                try
                {
                    dicEnt1 = (DictionaryEntry)enu1.Current;
                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }
                try
                {
                    fk1 = (FooKey)enu1.Key;
                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }
                try
                {
                    fv1 = (FooValue)enu1.Value;
                    iCountErrors++;
                    Console.WriteLine("Err_87543! Exception not thrown");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception ex)
                {
                    Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
                }
                strLoc = "Loc_004oo";
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                if (mycol1.IsSynchronized)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_275eg! Expected value not returned, " + mycol1.IsSynchronized);
                }
                iCountTestcases++;
                strLoc = "Loc_005oo";
                mycol1 = new MyDictionaryBase();
                obj1   = mycol1.SyncRoot;
                mycol2 = mycol1;
                if (obj1 != mycol2.SyncRoot)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9745sg! Expected value not returned");
                }
                strLoc = "Loc_006oo";
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                for (int i = 0; i < 100; i++)
                {
                    if ((mycol1[new FooKey(i, i.ToString())].IValue != i) || (mycol1[new FooKey(i, i.ToString())].SValue != i.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned");
                    }
                }
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Remove(new FooKey(i, i.ToString()));
                    if ((mycol1.Count != (99 - i)))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned");
                    }
                    if ((mycol1.Contains(new FooKey(i, i.ToString()))))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_975wg_" + i + "! Expected value not returned");
                    }
                }
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                mycol1.Clear();
                if (mycol1.Count != 0)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count);
                }
                strLoc = "Loc_006oo";
                iCountTestcases++;
                mycol1 = new MyDictionaryBase();
                if (mycol1.IsFixedSize)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize);
                }
                if (mycol1.IsReadOnly)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly);
                }
                mycol1 = new MyDictionaryBase();
                for (int i = 0; i < 100; i++)
                {
                    mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
                }
                for (int i = 0, j = 100; i < 100; i++, j--)
                {
                    mycol1[new FooKey(i, i.ToString())] = new FooValue(j, j.ToString());
                }
                for (int i = 0, j = 100; i < 100; i++, j--)
                {
                    if ((mycol1[new FooKey(i, i.ToString())].IValue != j) || (mycol1[new FooKey(i, i.ToString())].SValue != j.ToString()))
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned");
                    }
                }
                mycol1 = new MyDictionaryBase();
                mycol1.Add(new FooKey(), new FooValue());
            } while (false);
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine(s_strTFAbbrev + " : Error Err_8888yyy!  strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString());
        }
        if (iCountErrors == 0)
        {
            Console.WriteLine("paSs.   " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases);
            return(true);
        }
        else
        {
            Console.WriteLine("FAiL!   " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums);
            return(false);
        }
    }
Exemplo n.º 5
0
    public bool runTest()
    {
        //////////// Global Variables used for all tests
        int iCountErrors = 0;
        int iCountTestcases = 0;

        MyDictionaryBase myDict;
        Foo f, newF;
        string expectedExceptionMessage;

        try
        {
            do
            {
                /////////////////////////  START TESTS ////////////////////////////
                ///////////////////////////////////////////////////////////////////

                /***********************************************************************************************************************
				Add
				***********************************************************************************************************************/

                //[] Vanilla Add
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f = new Foo();
                myDict.Add(f, 0.ToString());
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnInsertCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_4072ayps OnInsertComplete was never called");
                }
                else if (!myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0181salh Item was added");
                }

                //[] Add where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnValidateThrow = true;
                expectedExceptionMessage = "OnValidate";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    iCountErrors++;
                    Console.WriteLine("Err_1570pyqa Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2708apsa Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnInsertCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_56707awwaps OnInsert was called");
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2708apsa Expected Empty Collection actual {0} elements", myDict.Count);
                }

                //[] Add where OnInsert throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnInsertThrow = true;
                expectedExceptionMessage = "OnInsert";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    iCountErrors++;
                    Console.WriteLine("Err_35208asdo Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_30437sfdah Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnInsertCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_370asjhs OnInsertComplete was called");
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_3y07aza Expected Empty Collection actual {0} elements", myDict.Count);
                }

                //[] Add where OnInsertComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnInsertCompleteThrow = true;
                expectedExceptionMessage = "OnInsertComplete";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    iCountErrors++;
                    Console.WriteLine("Err_2548ashz Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_2708alkw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_3680ahksd Expected Empty Collection actual {0} elements", myDict.Count);
                }

                /***********************************************************************************************************************
				Remove
				***********************************************************************************************************************/

                //[] Vanilla Remove
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f = new Foo();

                myDict.Add(f, 0.ToString());
                myDict.Remove(f);
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnRemoveCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_348awq OnRemoveComplete was never called");
                }
                else if (myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_0824answ  Item was not removed");
                }

                //[] Remove where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                expectedExceptionMessage = "OnValidate";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.OnValidateThrow = true;
                    myDict.Remove(f);
                    iCountErrors++;
                    Console.WriteLine("Err_08207hnas Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_87082aspz Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnRemoveCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_7207snmqla OnRemove was called");
                }
                else if (!myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_7270pahnz Element was actually removed {0}", myDict.Contains(f));
                }

                //[] Remove where OnRemove throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnRemoveThrow = true;
                expectedExceptionMessage = "OnRemove";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.Remove(f);
                    iCountErrors++;
                    Console.WriteLine("Err_7708aqyy Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_08281naws Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnRemoveCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_10871aklsj OnRemoveComplete was called");
                }
                else if (!myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2081aslkjs Element was actually removed {0}", myDict.Contains(f));
                }

                //[] Remove where OnRemoveComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnRemoveCompleteThrow = true;
                expectedExceptionMessage = "OnRemoveComplete";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.Remove(f);
                    iCountErrors++;
                    Console.WriteLine("Err_10981nlskj Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_20981askjs Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.Contains(f))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_20909assfd Element was actually removed {0}", myDict.Contains(f));
                }

                /***********************************************************************************************************************
				Clear
				***********************************************************************************************************************/

                //[] Vanilla Clear
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f = new Foo();

                myDict.Add(f, 0.ToString());
                myDict.Clear();
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnClearCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2136sdf OnClearComplete was never called");
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9494aswa  Items were not Cleared");
                }

                //[] Clear where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                expectedExceptionMessage = "OnValidate";
                f = new Foo();

                myDict.Add(f, 0.ToString());
                myDict.OnValidateThrow = true;
                myDict.Clear();

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnClearCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6549asff OnClearComplete was not called");
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_4649awajm Items were Cleared");
                }

                //[] Clear where OnClear throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnClearThrow = true;
                expectedExceptionMessage = "OnClear";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.Clear();
                    iCountErrors++;
                    Console.WriteLine("Err_9444sjpjnException was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_78941joaException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnClearCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_94944awfuu OnClearComplete was called");
                }
                else if (1 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6498  Items were not Cleared");
                }

                //[] Clear where OnClearComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnClearCompleteThrow = true;
                expectedExceptionMessage = "OnClearComplete";
                f = new Foo();
                try
                {
                    myDict.Add(f, 0.ToString());
                    myDict.Clear();
                    iCountErrors++;
                    Console.WriteLine("Err_64977awad Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_0877asaw Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (0 != myDict.Count)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_1081lkajs  Items were not Cleared");
                }


                /***********************************************************************************************************************
				Set that adds an item
				***********************************************************************************************************************/

                //[] Vanilla Set
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f = new Foo(1, "1");
                newF = new Foo(2, "2");

                myDict.Add(f, 1.ToString());
                myDict[newF] = 2.ToString();
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnSetCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_1698asdf OnSetComplete was never called");
                }
                else if (!myDict.Contains(f) || !myDict.Contains(newF))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9494safs  Item was not Set");
                }

                //[] Set where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                expectedExceptionMessage = "OnValidate";
                f = new Foo(1, "1");
                newF = new Foo(2, "2");
                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict.OnValidateThrow = true;
                    myDict[newF] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_611awwa Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_69498hph Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnSetCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_94887jio OnSet was called");
                }
                else if (!myDict.Contains(f) || myDict.Contains(newF))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6549ihyopiu Element was actually Set {0}", myDict.Contains(f));
                }

                //[] Set where OnSet throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnSetThrow = true;
                expectedExceptionMessage = "OnSet";
                f = new Foo(1, "1");
                newF = new Foo(2, "2");
                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict[newF] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_61518haiosd Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_196198sdklhsException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnSetCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6548dasfs OnSetComplete was called");
                }
                else if (!myDict.Contains(f) || myDict.Contains(newF))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2797sah Element was actually Set {0}", myDict.Contains(f));
                }

                //[] Set where OnSetComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnSetCompleteThrow = true;
                expectedExceptionMessage = "OnSetComplete";
                f = new Foo(1, "1");
                newF = new Foo(2, "2");
                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict[newF] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_56498hkashException was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_13168hsaiuh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.Contains(f) || myDict.Contains(newF))
                {
                    iCountErrors++;
                    Console.WriteLine("Err_64198ahihos Element was actually Set {0}", myDict.Contains(f));
                }

                /***********************************************************************************************************************
				Set that sets an existing item
				***********************************************************************************************************************/

                //[] Vanilla Set
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                f = new Foo(1, "1");

                myDict.Add(f, 1.ToString());
                myDict[f] = 2.ToString();
                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.OnSetCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_1698asdf OnSetComplete was never called");
                }
                else if (!myDict.Contains(f) || myDict[f] != "2")
                {
                    iCountErrors++;
                    Console.WriteLine("Err_9494safs  Item was not Set");
                }

                //[] Set where Validate throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                expectedExceptionMessage = "OnValidate";
                f = new Foo(1, "1");
                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict.OnValidateThrow = true;
                    myDict[f] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_611awwa Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_69498hph Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnSetCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_94887jio OnSet was called");
                }
                else if (!myDict.Contains(f) || myDict[f] != "1")
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6549ihyopiu Element was actually Set {0}", myDict.Contains(f));
                }

                //[] Set where OnSet throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnSetThrow = true;
                expectedExceptionMessage = "OnSet";
                f = new Foo(1, "1");

                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict[f] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_61518haiosd Exception was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_196198sdklhsException message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (myDict.OnSetCompleteCalled)
                {
                    iCountErrors++;
                    Console.WriteLine("Err_6548dasfs OnSetComplete was called");
                }
                else if (!myDict.Contains(f) || myDict[f] != "1")
                {
                    iCountErrors++;
                    Console.WriteLine("Err_2797sah Element was actually Set {0}", myDict.Contains(f));
                }

                //[] Set where OnSetComplete throws
                iCountTestcases++;
                myDict = new MyDictionaryBase();
                myDict.OnSetCompleteThrow = true;
                expectedExceptionMessage = "OnSetComplete";
                f = new Foo(1, "1");

                try
                {
                    myDict.Add(f, 1.ToString());
                    myDict[f] = 2.ToString();
                    iCountErrors++;
                    Console.WriteLine("Err_56498hkashException was not thrown");
                }
                catch (Exception e)
                {
                    if (expectedExceptionMessage != e.Message)
                    {
                        iCountErrors++;
                        Console.WriteLine("Err_13168hsaiuh Exception message was wrong expected '{0}' actual '{1}'", expectedExceptionMessage, e.Message);
                    }
                }

                if (myDict.IsError)
                {
                    iCountErrors++;
                    Console.WriteLine(myDict.ErrorMsg);
                }
                else if (!myDict.Contains(f) || myDict[f] != "1")
                {
                    iCountErrors++;
                    Console.WriteLine("Err_64198ahihos Element was actually Set {0}", myDict.Contains(f));
                }
                /////////////////////////// END TESTS /////////////////////////////


            } while (false);
        }
        catch (Exception exc_general)
        {
            ++iCountErrors;
            Console.WriteLine(" : Error Err_8888yyy! exc_general==\n" + exc_general.ToString());
        }


        ////  Finish Diagnostics
        if (iCountErrors == 0)
        {
            return true;
        }
        else
        {
            Console.WriteLine("Fail iCountErrors==" + iCountErrors);
            return false;
        }
    }
Exemplo n.º 6
0
 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     MyDictionaryBase mycol1;
     MyDictionaryBase mycol2;
     FooKey fk1;
     FooValue fv1;
     FooKey[] arrFK1;
     FooValue[] arrFV1;
     IDictionaryEnumerator enu1;
     Int32 iCount;
     DictionaryEntry[] arrDicEnt1;
     DictionaryEntry dicEnt1;
     Object obj1;
     try 
     {
         do
         {
             iCountTestcases++;
             iCountTestcases++;
             strLoc = "Loc_001oo";
             mycol1 = new MyDictionaryBase();
             if(mycol1.Count!=0)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count);
             }
             for(int i=0; i<100; i++)
                 mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
             if(mycol1.Count!=100)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_2075sg! Expected value not returned, " + mycol1.Count);
             }
             iCountTestcases++;
             strLoc = "Loc_002oo";
             mycol1 = new MyDictionaryBase();
             for(int i=0; i<100; i++)
                 mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
             arrDicEnt1 = new DictionaryEntry[100];
             mycol1.CopyTo(arrDicEnt1, 0);
             arrFK1 = new FooKey[100];
             arrFV1 = new FooValue[100];
             for(int i=0; i<100; i++)
             {
                 arrFK1[i] = (FooKey)arrDicEnt1[i].Key;
                 arrFV1[i] = (FooValue)arrDicEnt1[i].Value;
             }
             Array.Sort(arrFK1);
             Array.Sort(arrFV1);
             for(int i=0; i<100; i++)
             {
                 if((arrFK1[i].IValue != i) || (arrFK1[i].SValue!= i.ToString()) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_2874sf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                 }
                 if((arrFV1[i].IValue != i) || (arrFV1[i].SValue!= i.ToString()) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_93765dg_" + i + "! Expected value not returned");
                 }
             }
             iCountTestcases++;
             mycol1 = new MyDictionaryBase();
             for(int i=0; i<100; i++)
                 mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
             arrDicEnt1 = new DictionaryEntry[100];
             try
             {
                 mycol1.CopyTo(arrDicEnt1, 50);
                 iCountErrors++;
                 Console.WriteLine("Err_2075dfgv! Exception not thrown");
             }
             catch(ArgumentException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name);
             }
             try
             {
                 mycol1.CopyTo(arrDicEnt1, -1);
                 iCountErrors++;
                 Console.WriteLine("Err_2075dfgv! Exception not thrown");
             }
             catch(ArgumentException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_854732f! Unexception not thrown, " + ex.GetType().Name);
             }
             arrDicEnt1 = new DictionaryEntry[200];
             mycol1.CopyTo(arrDicEnt1, 100);
             arrFK1 = new FooKey[100];
             arrFV1 = new FooValue[100];
             for(int i=0; i<100; i++)
             {
                 arrFK1[i] = (FooKey)arrDicEnt1[i+100].Key;
                 arrFV1[i] = (FooValue)arrDicEnt1[i+100].Value;
             }
             Array.Sort(arrFK1);
             Array.Sort(arrFV1);
             for(int i=0; i<100; i++)
             {
                 if((arrFK1[i].IValue != i) || (arrFK1[i].SValue!= i.ToString()) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_974gd_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                 }
                 if((arrFV1[i].IValue != i) || (arrFV1[i].SValue!= i.ToString()) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_2075sg_" + i + "! Expected value not returned");
                 }
             }
             iCountTestcases++;
             mycol1 = new MyDictionaryBase();
             for(int i=0; i<100; i++)
                 mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
             enu1 = mycol1.GetEnumerator();
             try
             {
                 dicEnt1 = (DictionaryEntry)enu1.Current;
                 iCountErrors++;
                 Console.WriteLine("Err_87543! Exception not thrown");
             }
             catch(InvalidOperationException)
             {
             }
             catch(Exception ex)
             {
                 Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
             }
             try
             {
                 fk1 = (FooKey)enu1.Key;
                 iCountErrors++;
                 Console.WriteLine("Err_87543! Exception not thrown");
             }
             catch(InvalidOperationException)
             {
             }
             catch(Exception ex)
             {
                 Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
             }
             try
             {
                 fv1 = (FooValue)enu1.Value;
                 iCountErrors++;
                 Console.WriteLine("Err_87543! Exception not thrown");
             }
             catch(InvalidOperationException)
             {
             }
             catch(Exception ex)
             {
                 Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
             }
             iCount=0;
             arrFK1 = new FooKey[100];
             arrFV1 = new FooValue[100];
         while( enu1.MoveNext() )
         {			
             dicEnt1 = (DictionaryEntry)enu1.Current;
             arrFK1[iCount] = (FooKey)dicEnt1.Key;
             arrFV1[iCount] = (FooValue)dicEnt1.Value;
             fk1 = (FooKey)enu1.Key;
             if(fk1!=arrFK1[iCount])
             {
                 iCountErrors++;
                 Console.WriteLine("Err_8543s_" + iCount + "! Expected value not returned, " + arrFK1[iCount].IValue);
             }
             fv1 = (FooValue)enu1.Value;
             if(fv1!=arrFV1[iCount])
             {
                 iCountErrors++;
                 Console.WriteLine("Err_29075gd_" + iCount + "! Expected value not returned, " + arrFV1[iCount].IValue);
             }
             iCount++;
         }
             if(iCount!=100)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_87543! doesnot match");
             }
             Array.Sort(arrFK1);
             Array.Sort(arrFV1);
             for(int i=0; i<100; i++)
             {
                 if((arrFK1[i].IValue != i) || (arrFK1[i].SValue!= i.ToString()) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_89275sgf_" + i + "! Expected value not returned, " + arrFK1[i].IValue);
                 }
                 if((arrFV1[i].IValue != i) || (arrFV1[i].SValue!= i.ToString()) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_275g_" + i + "! Expected value not returned");
                 }
             }
             try
             {
                 dicEnt1 = (DictionaryEntry)enu1.Current;
                 iCountErrors++;
                 Console.WriteLine("Err_87543! Exception not thrown");
             }
             catch(InvalidOperationException)
             {
             }
             catch(Exception ex)
             {
                 Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
             }
             try
             {
                 fk1 = (FooKey)enu1.Key;
                 iCountErrors++;
                 Console.WriteLine("Err_87543! Exception not thrown");
             }
             catch(InvalidOperationException)
             {
             }
             catch(Exception ex)
             {
                 Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
             }
             try
             {
                 fv1 = (FooValue)enu1.Value;
                 iCountErrors++;
                 Console.WriteLine("Err_87543! Exception not thrown");
             }
             catch(InvalidOperationException)
             {
             }
             catch(Exception ex)
             {
                 Console.WriteLine("fail, should throw InvalidOperationException, thrown, " + ex.GetType().Name);
             }
             strLoc = "Loc_004oo";
             iCountTestcases++;
             mycol1 = new MyDictionaryBase();
             if(mycol1.IsSynchronized)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_275eg! Expected value not returned, " + mycol1.IsSynchronized);
             }
             iCountTestcases++;
             strLoc = "Loc_005oo";
             mycol1 = new MyDictionaryBase();
             obj1 = mycol1.SyncRoot;
             mycol2 = mycol1;
             if(obj1 != mycol2.SyncRoot)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_9745sg! Expected value not returned");
             }
             strLoc = "Loc_006oo";
             iCountTestcases++;
             mycol1 = new MyDictionaryBase();
             for(int i=0; i<100; i++)
                 mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
             for(int i=0; i<100; i++)
             {
                 if((mycol1[new FooKey(i, i.ToString())].IValue != i) || (mycol1[new FooKey(i, i.ToString())].SValue!= i.ToString()) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_2974swsg_" + i + "! Expected value not returned");
                 }
             }
             for(int i=0; i<100; i++)
             {
                 mycol1.Remove(new FooKey(i, i.ToString()));
                 if((mycol1.Count != (99-i)) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_2975sg_" + i + "! Expected value not returned");
                 }
                 if((mycol1.Contains(new FooKey(i, i.ToString()))) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_975wg_" + i + "! Expected value not returned");
                 }
             }				
             mycol1 = new MyDictionaryBase();
             for(int i=0; i<100; i++)
                 mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
             mycol1.Clear();
             if(mycol1.Count!=0)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_234dnvf! Expected value not returned, " + mycol1.Count);
             }
             strLoc = "Loc_006oo";
             iCountTestcases++;
             mycol1 = new MyDictionaryBase();
             if(mycol1.IsFixedSize)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_9753sfg! Expected value not returned, " + mycol1.IsFixedSize);
             }
             if(mycol1.IsReadOnly)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_834sg! Expected value not returned, " + mycol1.IsReadOnly);
             }
             mycol1 = new MyDictionaryBase();
             for(int i=0; i<100; i++)
                 mycol1.Add(new FooKey(i, i.ToString()), new FooValue(i, i.ToString()));
             for(int i=0, j=100; i<100; i++, j--)
                 mycol1[new FooKey(i, i.ToString())] = new FooValue(j, j.ToString());
             for(int i=0, j=100; i<100; i++, j--)
             {
                 if((mycol1[new FooKey(i, i.ToString())].IValue != j) || (mycol1[new FooKey(i, i.ToString())].SValue!= j.ToString()) )
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_7342rfg_" + i + "! Expected value not returned");
                 }
             }
             mycol1 = new MyDictionaryBase();
             mycol1.Add(new FooKey(), new FooValue());
         } while (false);
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }