Unity3D_TestSuite.AddAll C# (CSharp) Method

AddAll() public method

public AddAll ( TestCase test ) : void
test TestCase
return void
    public void AddAll(TestCase test)
    {
        // If test invalid
        if (null == test)
            {
                // Error
                throw new Exception("Invalid test case encountered.");
            }

        // For each method in the test case
        Type type = test.GetType();
        foreach (MethodInfo method in type.GetMethods())
            {
                // For each unit test attribute
                foreach (object obj in method.GetCustomAttributes(typeof(UnitTest), false))
                    {
                        // If attribute is valid
                        Attribute testAtt = obj as Attribute;
                        if (null != testAtt)
                            {
                                // If type has constructors
                                ConstructorInfo[] ci= type.GetConstructors();
                                if (0 < ci.Length)
                                    {
                                        // Add the test
                                        TestCase tmp = ci[0].Invoke(null) as TestCase;
                                        tmp.SetTestMethod(method.Name);
                                        m_tests.Add(tmp);
                                    }
                            }
                    }
            }
    }

Same methods

Unity3D_TestSuite::AddAll ( UnityTestCase test ) : void

Usage Example

 protected virtual void AddCompornents(Unity3D_TestSuite suite)
 {
     // For each assembly in this app domain
     foreach (Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
     {
         // For each type in the assembly
         foreach (Type type in assem.GetTypes())
         {
             // If this is a valid test case
             // i.e. derived from TestCase and instantiable
             if (typeof(UnityTestCase).IsAssignableFrom(type) &&
                 type != typeof(UnityTestCase) && !type.IsAbstract)
             {
                 // Add tests to suite
                 UnityTestCase test = gameObject.AddComponent(type.Name) as UnityTestCase;
                 suite.AddAll(test);
             } else if (typeof(TestCase).IsAssignableFrom(type) &&
                 type != typeof(TestCase) &&
                 !type.IsAbstract)
             {
                 suite.AddAll(type.GetConstructor(new Type[0]).Invoke(new object[0]) as TestCase);
             }
         }
     }
 }
All Usage Examples Of Unity3D_TestSuite::AddAll