ClassLib_Test.MyClass2.TestGetCustomAttributes2 C# (CSharp) Method

TestGetCustomAttributes2() public method

public TestGetCustomAttributes2 ( MemberInfo mem ) : bool
mem System.Reflection.MemberInfo
return bool
 override public bool TestGetCustomAttributes2 (MemberInfo mem)
   {
   Util.print ("\n\n" + this.GetType ().ToString () + " - TestGetCustomAttributes2() started.");
   Util.print ("For: " + mem.GetType ().ToString () + "\n");
   string strLoc="L_16_000";
   Object[] attrs = null;
   try  
     {
     do
       {
       iCountTestcases++;
       strLoc="L_16_001";
       if (mem == null) {
       iCountErrors++;
       Util.printerr ("E_75yhg - mem == null");
       return false;
       }
       iCountTestcases++;
       strLoc="L_16_001.1.1";
       attrs = mem.GetCustomAttributes (false);
       if (attrs == null) {
       iCountErrors++;
       Util.printerr ("E_16_dkd3 - attrs == null");
       return false;
       }
        
       if (attrs.Length != (iCountTotalAttrs-2)) {
       iCountErrors++;
       Util.printerr ("E_16_499s - attrs.Length != iCountTotalAttrs-2");
       Util.print ("Expected: " + (iCountTotalAttrs-2) + ";Returned: " + attrs.Length);
       Util.print (mem);
       
       }
       iCountTestcases++;
       strLoc="L_16_001.2";
       attrs = mem.GetCustomAttributes (true);
       if (attrs == null) {
       iCountErrors++;
       Util.printerr ("E_gfh4 - attrs == null");
       return false;
       }
       iCountTestcases++;
       strLoc="L_16_001.3";
       if ((mem is System.Reflection.FieldInfo) || (mem is System.Reflection.ConstructorInfo)
       || (mem is System.Reflection.PropertyInfo) || (mem is System.Reflection.EventInfo)) { 
            if (attrs.Length != (iCountTotalAttrs-2)) {
                iCountErrors++;
                Util.printerr ("E_16_fk25 - attrs.Length != iCountTotalAttrs-2");
                Util.print ("Expected: " + (iCountTotalAttrs-2) + ";Returned: " + attrs.Length);                    
        }
        }
       
        else
        {
         
        if (attrs.Length != iCountTotalAttrs) {
            iCountErrors++;
            Util.printerr ("E_16_jhd4 - attrs.Length != iCountTotalAttrs");
            Util.print ("Expected: " + iCountTotalAttrs + "; Returned: " + attrs.Length);
        
        }
       }
       iCountTestcases++;
       strLoc="L_16_001.3";
       TestAttributes (attrs, mem);
       } while ( false );
     }
   catch( Exception exc_runTest ) {
   ++iCountErrors;
   Util.printerr ("E_16_888un! - Uncaught Exception caught in TestGetCustomAttributes(); strLoc == " + strLoc);
   Util.printexc (exc_runTest);
   Util.print (exc_runTest.StackTrace);
   }
   if ( iCountErrors == 0 ) {   return true; }
   else {
   return false;
   }
   }
 override public bool TestAttributes (Attribute[] attrs, MemberInfo mem)

Usage Example

Example #1
0
        public bool RunTest()
        {
            print(strPath + strTest + "  RunTest() started.");
            string     strLoc   = "L_000";
            MyClass    myclass  = new MyClass();
            MyClass2   myclass2 = new MyClass2();
            MemberInfo mem      = null;
            MemberInfo mem2     = null;

            Attribute[] attrs  = null;
            Attribute[] attrs2 = null;
            Type        type   = null;
            Type        type2  = null;

            try
            {
                strLoc = "L_100_001";
                iCountTestcases++;
                strLoc = "L_100_001.4";
                try {
                    attrs = Attribute.GetCustomAttributes((MemberInfo)null, true);
                    iCountErrors++;
                    Util.printerr("E_100_duo21 - Should 've thrown ArgNullExc");
                }
                catch (ArgumentException) {
                }
                iCountTestcases++;
                strLoc = "L_100_001.4.2";
                type   = myclass.GetType();
                mem    = type.GetMethod("TestGetCustomAttributes");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_jkjs - mem == null");
                }
                iCountTestcases++;
                strLoc = "L_100_001.5";
                attrs  = Attribute.GetCustomAttributes(mem, true);
                if (attrs == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_iudo - attrs == null");
                    return(false);
                }
                iCountTestcases++;
                strLoc = "L_100_001.6";
                if (attrs.Length != 0 + 1)
                {
                    iCountErrors++;
                    Util.printerr("E_100_f3fw - attrs.Length != 1");
                    Util.print(attrs.Length);
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.4.2";
                type2  = myclass2.GetType();
                mem2   = type2.GetMethod("TestGetCustomAttributes");
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_jkjs - mem2 == null");
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.5";
                attrs2 = Attribute.GetCustomAttributes(mem2, true);
                if (attrs2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_iudo - attrs2 == null");
                    return(false);
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.6";
                if (attrs2.Length != 0 + 1)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_f3fw - attrs2.Length != 1");
                    Util.print(attrs2.Length);
                }
                iCountTestcases++;
                strLoc = "L_100_001.7";
                type   = myclass.GetType();
                mem    = type;
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_001.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_001.8";
                mem    = type.GetConstructor(Type.EmptyTypes);
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_001.8_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_001.8.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_002";
                mem    = type.GetMethod("MyMethod");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_002_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_002.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_003";
                mem    = type.GetField("MyField");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_003_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_003.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_004";
                mem    = type.GetProperty("MyProp");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_004_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_004.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_100_005";
                mem    = type.GetEvent("MyEvent");
                if (mem == null)
                {
                    iCountErrors++;
                    Util.printerr("E_100_005_skj2 - mem == null");
                }
                else
                {
                    myclass.TestGetCustomAttributes(mem);
                    iCountTestcases++;
                    strLoc = "L_100_005.7.2";
                    myclass.TestGetCustomAttributes2(mem);
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.7";
                type2  = myclass2.GetType();
                mem2   = type2;
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_001.7.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_001.8";
                mem2   = type2.GetConstructor(Type.EmptyTypes);
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_001.8_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_001.8.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_002";
                mem2   = type2.GetMethod("MyMethod");
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_002_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_002.7.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_003";
                mem2   = type2.GetField("MyField", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_003_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_003.7.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_004";
                mem2   = type2.GetProperty("MyProp");
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_004_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_004.7.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
                iCountTestcases++;
                strLoc = "L_2_100_005";
                mem2   = type2.GetEvent("MyEvent");
                if (mem2 == null)
                {
                    iCountErrors++;
                    Util.printerr("E_2_100_005_skj2 - mem2 == null");
                }
                else
                {
                    myclass2.TestGetCustomAttributes(mem2);
                    iCountTestcases++;
                    strLoc = "L_2_100_005.7.2";
                    myclass2.TestGetCustomAttributes2(mem2);
                }
            }
            catch (Exception exc_runTest) {
                ++myclass2.iCountErrors;
                printerr("Err_888un! - Uncaught Exception caught in runTest(); strLoc == " + strLoc);
                printexc(exc_runTest);
                print(exc_runTest.StackTrace);
            }
            iCountErrors    = myclass.iCountErrors + myclass2.iCountErrors;
            iCountTestcases = myclass.iCountTestcases + myclass2.iCountTestcases;
            if (iCountErrors == 0)
            {
                return(true);
            }
            else
            {
                print("Related Bugs: " + strBug);
                print("FAiL!   " + strPath + strTest + "  iCountErrors==" + iCountErrors.ToString());
                return(false);
            }
        }
All Usage Examples Of ClassLib_Test.MyClass2::TestGetCustomAttributes2