public void AbstractMethods()
        {
            TypeDefinition type = GetTest("AbstractMethodsClass");

            foreach (MethodDefinition method in type.Methods)
            {
                if (method.IsConstructor)
                {
                    continue;
                }
                Assert.AreEqual(RuleResult.Success, runner.CheckMethod(method), method.ToString());
            }
        }
Esempio n. 2
0
        private void AssertClass <T> ()
        {
            TestRunner runner;
            bool       failed = false;
            RuleResult result;

            //
            // We assert that exactly 1 error is raised among all the methods in the class
            //

            runner = new TestRunner(new DelegatesPassedToNativeCodeMustIncludeExceptionHandlingRule());

            foreach (MethodDefinition method in DefinitionLoader.GetTypeDefinition <T> ().Methods)
            {
                result = runner.CheckMethod(method);
                if (result == RuleResult.Failure)
                {
                    Assert.IsFalse(failed);
                    Assert.AreEqual(1, runner.Defects.Count);
                    failed = true;
                }
            }

            Assert.IsTrue(failed);
        }
Esempio n. 3
0
        public void TestNotImplemented()
        {
            MethodDefinition method = GetTest("NotImplemented");

            Assert.AreEqual(RuleResult.Failure, runner.CheckMethod(method), "NotImplemented failure test");

            method = GetTest("NotImplementedLocal");
            Assert.AreEqual(RuleResult.Success, runner.CheckMethod(method), "NotImplementedLocal success test");
        }
Esempio n. 4
0
        /// <summary>
        /// Runs the rule, depending on its type.
        /// </summary>
        private RuleResult RunRule(TMetadataToken token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            MethodDefinition md = (token as MethodDefinition);

            if (md != null)
            {
                if (FireEvents)
                {
                    runner.OnAssembly(md.DeclaringType.Module.Assembly);
                    runner.OnType(md.DeclaringType);
                    runner.OnMethod(md);
                }
                return(runner.CheckMethod(token as MethodDefinition));
            }

            TypeDefinition td = (token as TypeDefinition);

            if (td != null)
            {
                if (FireEvents)
                {
                    runner.OnAssembly(md.DeclaringType.Module.Assembly);
                    runner.OnType(md.DeclaringType);
                }
                return(runner.CheckType(td));
            }

            AssemblyDefinition ad = (token as AssemblyDefinition);

            if (ad != null)
            {
                if (FireEvents)
                {
                    runner.OnAssembly(td.Module.Assembly);
                }
                return(runner.CheckAssembly(ad));
            }

            throw new NotImplementedException(token.GetType().ToString());
        }
Esempio n. 5
0
        private void AssertTest(string name, int expectedCount)
        {
            TestRunner       runner;
            MethodDefinition method;
            RuleResult       result;
            RuleResult       expected = name.Contains("OK") ? RuleResult.Success : RuleResult.Failure;

            if (expected == RuleResult.Success)
            {
                expectedCount = 0;
            }

            // Since the rule only reports errors once for each method, and these tests reuse methods,
            // we need a new test runner for each test.

            runner = new TestRunner(new DelegatesPassedToNativeCodeMustIncludeExceptionHandlingRule());
            runner.Rules.Clear();
            method = DefinitionLoader.GetMethodDefinition <DelegatesPassedToNativeCodeMustIncludeExceptionHandlingTest> (name);
            result = runner.CheckMethod(method);

            Assert.AreEqual(expected, result);
            Assert.AreEqual(expectedCount, runner.Defects.Count, "DefectCount");
        }
Esempio n. 6
0
        public void TestEmptyMethod()
        {
            MethodDefinition method = GetTest("EmptyMethod");

            Assert.AreEqual(RuleResult.DoesNotApply, runner.CheckMethod(method));
        }
Esempio n. 7
0
        public void TestNothing()
        {
            MethodDefinition method = GetTest("CallNothing");

            Assert.AreEqual(RuleResult.Success, runner.CheckMethod(method));
        }
Esempio n. 8
0
        public void TestDirectThrow()
        {
            MethodDefinition method = GetTest("DirectThrow");

            Assert.AreEqual(RuleResult.Success, runner.CheckMethod(method), "RuleResult");
            Assert.AreEqual(0, runner.Defects.Count, "Count");
        }
Esempio n. 9
0
 public void TestEnvSetBadExitCodeFromNonExecutable()
 {
     // get method from this assembly, not generated one
     Assert.AreEqual(RuleResult.Failure, runner.CheckMethod(GetMethod(assembly.MainModule.GetType("Test.Rules.Portability.EnvSetExitCodeTester"), "SetTooBigExitCode")));
 }