コード例 #1
0
        public void TestCoverage()
        {
            /* Search the current assembly for unit tests. */
            var alltypes        = GetType().Assembly.GetTypes();
            var unitTestMethods = new List <MethodBase>();

            foreach (var t in alltypes)
            {
                CoverageTester.CollectTestMethods(t, unitTestMethods);
            }

            /* Search the assembly that Autodesk.Fbx.Globals is in to find classes in
             * the FbxSdk namespace to test. */
            alltypes = typeof(Autodesk.Fbx.Globals).Assembly.GetTypes();
            var methodsToCover = new List <MethodBase>();

            foreach (var t in alltypes)
            {
                if (t.Namespace != "Autodesk.Fbx")
                {
                    continue;
                }

                /* don't take in delegates; we can't properly track coverage,
                 * so just avoid the false negative */
                if (t.IsSubclassOf(typeof(System.Delegate)))
                {
                    continue;
                }

                /* take in the PINVOKE class but skip its helper classes */
                bool skip = false;
                for (var u = t.DeclaringType; u != null; u = u.DeclaringType)
                {
                    if (u.TypeHandle.Value == s_PINVOKEtype.TypeHandle.Value)
                    {
                        skip = true;
                        break;
                    }
                }
                if (skip)
                {
                    continue;
                }

                CoverageTester.CollectMethodsToCover(t, methodsToCover);
            }

            List <MethodBase> hitMethods    = new List <MethodBase>();
            List <MethodBase> missedMethods = new List <MethodBase>();
            var ok = CoverageTester.TestCoverage(methodsToCover, unitTestMethods, out hitMethods, out missedMethods);

            NUnit.Framework.Assert.That(
                () => ok,
                () => CoverageTester.MakeCoverageMessage(hitMethods, missedMethods));
        }