Exemple #1
0
 public UUnitTestContext(UUnitTestCase testInstance, Action <UUnitTestContext> testDelegate, string name)
 {
     TestInstance = testInstance;
     TestDelegate = testDelegate;
     ActiveState  = UUnitActiveState.PENDING;
     Name         = name;
 }
Exemple #2
0
        private void AddTestsForType(Type testCaseType, string filter = null)
        {
            if (_suiteState != UUnitActiveState.PENDING)
            {
                throw new Exception("Must add all tests before executing tests.");
            }

            var filterSet = AssembleFilter(filter);

            UUnitTestCase newTestCase = null;

            foreach (var constructorInfo in testCaseType.GetTypeInfo().GetConstructors())
            {
                try
                {
                    // .NET and some versions of Mono will throw an exception when the constructor is not parameterless...
                    newTestCase = (UUnitTestCase)constructorInfo.Invoke(null);
                }
                catch (Exception) { } // Ignore it and try the next one

                // ... other versions of Mono will return null instead of throwing an exception.
                // Either way, newTestCase will be null until it is successfully constructed.
                if (newTestCase != null)
                {
                    break;
                }
            }
            if (newTestCase == null)
            {
                throw new Exception(testCaseType.Name + " must have a parameter-less constructor.");
            }

            var methods        = testCaseType.GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var attributesList = new List <object>();

            foreach (var methodInfo in methods)
            {
                attributesList.Clear();
                attributesList.AddRange(methodInfo.GetCustomAttributes(typeof(UUnitTestAttribute), false));
                if (attributesList.Count == 0 || !MatchesFilters(methodInfo.Name, filterSet)) // There can only be 1, and we only care about attribute existence (no data on attribute), and it has to match the filter
                {
                    continue;
                }

                Action <UUnitTestContext> eachTestDelegate = CreateDelegate <UUnitTestContext>(testCaseType.Name, newTestCase, methodInfo);
                if (eachTestDelegate != null)
                {
                    _testContexts.Add(new UUnitTestContext(newTestCase, eachTestDelegate, methodInfo.Name));
                }
            }
        }
Exemple #3
0
        private void AddAll(Type testCaseType)
        {
            var methods = testCaseType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (MethodInfo m in methods)
            {
                var attributes = m.GetCustomAttributes(typeof(UUnitTestAttribute), false);
                if (attributes.Length > 0)
                {
                    ConstructorInfo constructor = testCaseType.GetConstructors()[0];
                    UUnitTestCase   newTestCase = (UUnitTestCase)constructor.Invoke(null);
                    newTestCase.SetTest(m.Name);
                    Add(newTestCase);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Manage the ClassSetUp and ClassTearDown functions for each UUnitTestCase
        /// </summary>
        private void ManageInstance(UUnitTestCase newtestInstance, UUnitTestCase oldTestInstance)
        {
            if (ReferenceEquals(newtestInstance, oldTestInstance))
            {
                return;
            }

            if (oldTestInstance != null)
            {
                oldTestInstance.ClassTearDown();
            }
            if (newtestInstance != null)
            {
                newtestInstance.ClassSetUp();
            }
            activeTestInstance = newtestInstance;
        }
 private void AddAll(TypeInfo testCaseType)
 {
     foreach (MethodInfo m in testCaseType.DeclaredMethods)
     {
         var attributes = m.GetCustomAttributes(typeof(UUnitTestAttribute), false);
         foreach (var attr in attributes)
         {
             var constructors = testCaseType.DeclaredConstructors;
             foreach (var constructor in constructors)
             {
                 UUnitTestCase newTestCase = (UUnitTestCase)constructor.Invoke(null);
                 newTestCase.SetTest(m.Name);
                 Add(newTestCase);
                 break; // We only want 1 constructor, if relevant
             }
             break;     // We only want 1 attribute, if relevant
         }
     }
 }
 public void Add(UUnitTestCase testCase)
 {
     tests.Add(testCase);
 }
 public void Add(UUnitTestCase testCase)
 {
     _tests.Add(testCase);
 }