コード例 #1
0
        /// <summary>
        /// Initializes an instance of <see cref="InconclusiveTestCase"/>.
        /// </summary>
        /// <param name="testCase">Original test case.</param>
        public InconclusiveTestCase(NUnitTestMethod testCase)
            : base(testCase.Method)
        {
            NUnitFramework.ApplyCommonAttributes(testCase.Method, this);
            NUnitFramework.ApplyExpectedExceptionAttribute(testCase.Method, this);

            // Copy all the attributes of the original test
            this.BuilderException   = testCase.BuilderException;
            this.Categories         = testCase.Categories;
            this.Description        = testCase.Description;
            this.ExceptionProcessor = testCase.ExceptionProcessor;
            this.Fixture            = testCase.Fixture;
            this.IgnoreReason       = testCase.IgnoreReason;
            this.Parent             = testCase.Parent;
            this.Properties         = testCase.Properties;
            this.RunState           = testCase.RunState;
            this.TestName.Name      = testCase.TestName.Name;
            this.TestName.FullName  = testCase.TestName.FullName;
            this.TestName.RunnerID  = testCase.TestName.RunnerID;
            this.TestName.TestID    = testCase.TestName.TestID;

            this.setUpMethods    = GetFieldValue <MethodInfo[]>(typeof(TestMethod), testCase, "setUpMethods");
            this.tearDownMethods = GetFieldValue <MethodInfo[]>(typeof(TestMethod), testCase, "tearDownMethods");
            this.actions         = GetFieldValue <TestAction[]>(typeof(TestMethod), testCase, "actions");
            this.suiteActions    = GetFieldValue <TestAction[]>(typeof(TestMethod), testCase, "suiteActions");

            this.SetFieldValue("arguments", GetFieldValue <object[]>(typeof(TestMethod), testCase, "arguments"));
            this.SetFieldValue("expectedResult", GetFieldValue <object>(typeof(TestMethod), testCase, "expectedResult"));
            this.SetFieldValue("hasExpectedResult", GetFieldValue <bool>(typeof(TestMethod), testCase, "hasExpectedResult"));
        }
コード例 #2
0
        ////private MethodInfo _methodinfo;

        /// <summary>
        /// Constructor to map method with this class.
        /// </summary>
        /// <param name="method">Method in test fixture without parameters.</param>
        public WalmartTestMethod(MethodInfo method)
            : base(method)
        {
            NUnitFramework.ApplyCommonAttributes(method, this);
            NUnitFramework.ApplyExpectedExceptionAttribute(method, this);

            var categories = new List <string>();
            var className  = method.DeclaringType;

            categories.ForEach(c => Categories.Add(c));

            var notReadyAttr = method.GetCustomAttributes(typeof(NotReadyAttribute), true);

            if (notReadyAttr.Any())
            {
                Categories.Add("NotReady");
            }

            ////Add EUAT as Category
            var regressionAttr = method.GetCustomAttributes(typeof(RegressionAttribute), true);

            if (regressionAttr.Any())
            {
                Categories.Add("Regression");
            }

            ////Add ToFix as Category
            var tofixAttr = method.GetCustomAttributes(typeof(ToFixAttribute), true);

            if (tofixAttr.Any())
            {
                Categories.Add("ToFix");
            }
        }
コード例 #3
0
        /// <summary>
        /// Builds a single NUnitTestMethod, either as a child of the fixture
        /// or as one of a set of test cases under a ParameterizedTestMethodSuite.
        /// </summary>
        /// <param name="method">The MethodInfo from which to construct the TestMethod</param>
        /// <param name="parms">The ParameterSet to be used, or null</param>
        /// <returns></returns>
        public static NUnitTestMethod BuildSingleTestMethod(MethodInfo method, ParameterSet parms)
        {
            NUnitTestMethod testMethod = new NUnitTestMethod(method);

            if (CheckTestMethodSignature(testMethod, parms))
            {
                NUnitFramework.ApplyCommonAttributes(method, testMethod);
                NUnitFramework.ApplyExpectedExceptionAttribute(method, testMethod);
            }

            if (parms != null)
            {
                // NOTE: After the call to CheckTestMethodSignature, the Method
                // property of testMethod may no longer be the same as the
                // original MethodInfo, so we reassign it here.
                method = testMethod.Method;
                if (parms.TestName != null)
                {
                    testMethod.TestName.Name     = parms.TestName;
                    testMethod.TestName.FullName = method.ReflectedType.FullName + "." + parms.TestName;
                }
                else if (parms.Arguments != null)
                {
                    string name = MethodHelper.GetDisplayName(method, parms.Arguments);
                    testMethod.TestName.Name     = name;
                    testMethod.TestName.FullName = method.ReflectedType.FullName + "." + name;
                }

                if (parms.ExpectedExceptionName != null)
                {
                    testMethod.exceptionProcessor = new ExpectedExceptionProcessor(testMethod, parms);
                }

                foreach (string key in parms.Properties.Keys)
                {
                    testMethod.Properties.Add(key, parms.Properties[key]);
                }

                // Description is stored in parms.Properties
                if (parms.Description != null)
                {
                    testMethod.Description = parms.Description;
                }
            }

            return(testMethod);
        }
コード例 #4
0
 /// <summary>
 /// Set additional properties of the newly created test case based
 /// on its attributes. As implemented, the method sets the test's
 /// RunState,  Description, Categories and Properties.
 /// </summary>
 /// <param name="method">A MethodInfo for the method being used as a test method</param>
 /// <param name="testCase">The test case being constructed</param>
 protected override void SetTestProperties(MethodInfo method, TestCase testCase)
 {
     NUnitFramework.ApplyCommonAttributes(method, testCase);
     NUnitFramework.ApplyExpectedExceptionAttribute(method, (TestMethod)testCase);
 }
コード例 #5
0
        /// <summary>
        /// Builds a single NUnitTestMethod, either as a child of the fixture
        /// or as one of a set of test cases under a ParameterizedTestMethodSuite.
        /// </summary>
        /// <param name="method">The MethodInfo from which to construct the TestMethod</param>
        /// <param name="parms">The ParameterSet to be used, or null</param>
        /// <returns></returns>
        public static NUnitTestMethod BuildSingleTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms)
        {
            NUnitTestMethod testMethod = new NUnitTestMethod(method);

            string prefix = method.ReflectedType.FullName;

            if (parentSuite != null)
            {
                prefix = parentSuite.TestName.FullName;
                testMethod.TestName.FullName = prefix + "." + testMethod.TestName.Name;
            }

            if (CheckTestMethodSignature(testMethod, parms))
            {
                if (parms == null)
                {
                    NUnitFramework.ApplyCommonAttributes(method, testMethod);
                }
                NUnitFramework.ApplyExpectedExceptionAttribute(method, testMethod);
            }

            if (parms != null)
            {
                // NOTE: After the call to CheckTestMethodSignature, the Method
                // property of testMethod may no longer be the same as the
                // original MethodInfo, so we reassign it here.
                method = testMethod.Method;

                if (parms.TestName != null)
                {
                    testMethod.TestName.Name     = parms.TestName;
                    testMethod.TestName.FullName = prefix + "." + parms.TestName;
                }
                else if (parms.OriginalArguments != null)
                {
                    string name = MethodHelper.GetDisplayName(method, parms.OriginalArguments);
                    testMethod.TestName.Name     = name;
                    testMethod.TestName.FullName = prefix + "." + name;
                }

                if (parms.Ignored)
                {
                    testMethod.RunState     = RunState.Ignored;
                    testMethod.IgnoreReason = parms.IgnoreReason;
                }
                else if (parms.Explicit)
                {
                    testMethod.RunState = RunState.Explicit;
                }

                if (parms.ExpectedExceptionName != null)
                {
                    testMethod.exceptionProcessor = new ExpectedExceptionProcessor(testMethod, parms);
                }

                foreach (string key in parms.Properties.Keys)
                {
                    testMethod.Properties[key] = parms.Properties[key];
                }

                // Description is stored in parms.Properties
                if (parms.Description != null)
                {
                    testMethod.Description = parms.Description;
                }
            }

            //if (testMethod.BuilderException != null && testMethod.RunState != RunState.NotRunnable)
            //{
            //    testMethod.RunState = RunState.NotRunnable;
            //    testMethod.IgnoreReason = testMethod.BuilderException.Message;
            //}

            if (parentSuite != null)
            {
                if (parentSuite.RunState == RunState.NotRunnable && testMethod.RunState != RunState.NotRunnable)
                {
                    testMethod.RunState     = RunState.NotRunnable;
                    testMethod.IgnoreReason = parentSuite.IgnoreReason;
                }

                if (parentSuite.RunState == RunState.Ignored && testMethod.RunState != RunState.Ignored && testMethod.RunState != RunState.NotRunnable)
                {
                    testMethod.RunState     = RunState.Ignored;
                    testMethod.IgnoreReason = parentSuite.IgnoreReason;
                }
            }

            return(testMethod);
        }
コード例 #6
0
        public TestMethodExtension BuildSingleTestMethod(MethodInfo method, Test parentSuite, ParameterSet parms, ScreenCapture screenCapture, IDictionary properties)
        {
            //TODO : Here it doesn't support  Async Await Method, BTW, the Async Await just be supported from .net 4.5
            TestMethodExtension testMethod = new TestMethodExtension(method, screenCapture);

            string prefix = method.ReflectedType.FullName;

            if (parentSuite != null)
            {
                testMethod.Properties = properties;
                prefix = parentSuite.TestName.FullName;
                testMethod.TestName.FullName = prefix + "." + testMethod.TestName.Name;
            }

            if (CheckTestMethodSignature(testMethod, parms))
            {
                if (parms == null)
                {
                    NUnitFramework.ApplyCommonAttributes(method, testMethod);
                }
                NUnitFramework.ApplyExpectedExceptionAttribute(method, testMethod);
            }

            if (parms != null)
            {
                method = testMethod.Method;

                if (parms.TestName != null)
                {
                    testMethod.TestName.Name     = parms.TestName;
                    testMethod.TestName.FullName = prefix + "." + parms.TestName;
                }
                else if (parms.OriginalArguments != null)
                {
                    string name = MethodHelper.GetDisplayName(method, parms.OriginalArguments);
                    testMethod.TestName.Name     = name;
                    testMethod.TestName.FullName = prefix + "." + name;
                }

                if (parms.Ignored)
                {
                    testMethod.RunState     = RunState.Ignored;
                    testMethod.IgnoreReason = parms.IgnoreReason;
                }
                else if (parms.Explicit)
                {
                    testMethod.RunState = RunState.Explicit;
                }

                foreach (string key in parms.Properties.Keys)
                {
                    testMethod.Properties[key] = parms.Properties[key];
                }

                if (parms.Description != null)
                {
                    testMethod.Description = parms.Description;
                }
            }

            if (parentSuite != null)
            {
                if (parentSuite.RunState == RunState.NotRunnable && testMethod.RunState != RunState.NotRunnable)
                {
                    testMethod.RunState     = RunState.NotRunnable;
                    testMethod.IgnoreReason = parentSuite.IgnoreReason;
                }

                if (parentSuite.RunState == RunState.Ignored && testMethod.RunState != RunState.Ignored && testMethod.RunState != RunState.NotRunnable)
                {
                    testMethod.RunState     = RunState.Ignored;
                    testMethod.IgnoreReason = parentSuite.IgnoreReason;
                }
            }

            return(testMethod);
        }