private void AddStrategyTestCases(NUnitTestFixture fixture, AutoTestSettings testSettings)
        {
            var strategyTest = (StrategyTest)Reflect.Construct(userFixtureType, new object[] { testSettings });

            foreach (var modelName in strategyTest.GetModelNames())
            {
                var paramaterizedTest = new ParameterizedMethodSuite(modelName);
                fixture.Add(paramaterizedTest);
                var parms = new ParameterSet();
                parms.Arguments = new object[] { modelName };
                var methods = strategyTest.GetType().GetMethods();
                foreach (var method in methods)
                {
                    var parameters = method.GetParameters();
                    if (!method.IsSpecialName && method.IsPublic && parameters.Length == 1 && parameters[0].ParameterType == typeof(string))
                    {
                        if (CheckIgnoreMethod(testSettings.IgnoreTests, method.Name))
                        {
                            continue;
                        }
                        var testCase = NUnitTestCaseBuilder.BuildSingleTestMethod(method, parms);
                        testCase.TestName.Name     = method.Name;
                        testCase.TestName.FullName = fixture.Parent.Parent.TestName.Name + "." +
                                                     fixture.Parent.TestName.Name + "." +
                                                     fixture.TestName.Name + "." +
                                                     modelName + "." +
                                                     method.Name;
                        paramaterizedTest.Add(testCase);
                    }
                }
            }
        }
Example #2
0
        public static NUnitTestFixture MakeFixture(object fixture)
        {
            NUnitTestFixture suite = (NUnitTestFixture)suiteBuilder.BuildFrom(fixture.GetType());

            suite.Fixture = fixture;
            return(suite);
        }
        private Test BuildSingleFixture(Type type, Attribute attr)
        {
            object[] arguments = null;

            if (attr != null)
            {
                arguments = (object[])Reflect.GetPropertyValue(attr, "Arguments");
#if NET_2_0
                if (type.ContainsGenericParameters)
                {
                    Type[] typeArgs = (Type[])Reflect.GetPropertyValue(attr, "TypeArgs");
                    if (typeArgs.Length > 0 ||
                        TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs))
                    {
                        type = TypeHelper.MakeGenericType(type, typeArgs);
                    }
                }
#endif
            }

            this.fixture = new NUnitTestFixture(type, arguments);
            CheckTestFixtureIsValid(fixture);

            NUnitFramework.ApplyCommonAttributes(type, fixture);

            AddTestCases(type);

            if (this.fixture.RunState != RunState.NotRunnable && this.fixture.TestCount == 0)
            {
                this.fixture.RunState     = RunState.NotRunnable;
                this.fixture.IgnoreReason = fixture.TestName.Name + " does not have any tests";
            }

            return(this.fixture);
        }
        private void AddSymbolTestCases(NUnitTestFixture fixture, AutoTestSettings testSettings)
        {
            var strategyTest = (StrategyTest)Reflect.Construct(userFixtureType, new object[] { testSettings });

            foreach (var symbol in strategyTest.GetSymbols())
            {
                var paramaterizedTest = new ParameterizedMethodSuite(symbol.Symbol);
                fixture.Add(paramaterizedTest);
                var parms = new ParameterSet();
                parms.Arguments = new object[] { symbol };
                var methods = strategyTest.GetType().GetMethods();
                foreach (var method in methods)
                {
                    var parameters = method.GetParameters();
                    if (!method.IsSpecialName && method.IsPublic && parameters.Length == 1 && parameters[0].ParameterType == typeof(SymbolInfo))
                    {
                        var testCase = NUnitTestCaseBuilder.BuildSingleTestMethod(method, parms);
                        testCase.TestName.Name     = method.Name;
                        testCase.TestName.FullName = fixture.Parent.Parent.TestName.Name + "." +
                                                     fixture.Parent.TestName.Name + "." +
                                                     fixture.TestName.Name + "." +
                                                     symbol + "." +
                                                     method.Name;
                        paramaterizedTest.Add(testCase);
                    }
                }
            }
        }
Example #5
0
        private Test BuildSingleFixture(Type type, Attribute attr)
        {
            object[] arguments  = null;
            IList    categories = null;

            if (attr != null)
            {
                arguments = (object[])Reflect.GetPropertyValue(attr, "Arguments");

                categories = Reflect.GetPropertyValue(attr, "Categories") as IList;
#if CLR_2_0 || CLR_4_0
                if (type.ContainsGenericParameters)
                {
                    Type[] typeArgs = (Type[])Reflect.GetPropertyValue(attr, "TypeArgs");
                    if (typeArgs.Length > 0 ||
                        TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs))
                    {
                        type = TypeHelper.MakeGenericType(type, typeArgs);
                    }
                }
#endif
            }

            this.fixture = new NUnitTestFixture(type, arguments);
            CheckTestFixtureIsValid(fixture);

            NUnitFramework.ApplyCommonAttributes(type, fixture);

            if (categories != null)
            {
                foreach (string category in categories)
                {
                    fixture.Categories.Add(category);
                }
            }

            if (fixture.RunState == RunState.Runnable && attr != null)
            {
                object objIgnore = Reflect.GetPropertyValue(attr, "Ignore");
                if (objIgnore != null && (bool)objIgnore == true)
                {
                    fixture.RunState     = RunState.Ignored;
                    fixture.IgnoreReason = (string)Reflect.GetPropertyValue(attr, "IgnoreReason");
                }
            }

            AddTestCases(type);

            return(this.fixture);
        }
Example #6
0
        public NUnitTestRunner(Settings settings)
        {
            _settings = settings;

            _fixtures = new List<NUnitTestFixture>();
            foreach (var type in settings.TestsAssembly.GetTypes())
            {
                object[] attrs = type.GetCustomAttributes(typeof(IntegrationFixtureAttribute), false);
                if (attrs.Length == 0)
                    continue;

                var fixture = new NUnitTestFixture(type, ((IntegrationFixtureAttribute)attrs[0]).Sequence);
                _fixtures.Add(fixture);
            }

            _fixtures.Sort((f1, f2) => f1.Sequence.CompareTo(f2.Sequence));
        }
Example #7
0
        private RowTestCase CreateRowTestCase(TestClass fixture, string methodName, params object[] arguments)
        {
            MethodInfo method = GetTestClassMethod(methodName);

            NUnitTestFixture nunitTestFixture = new NUnitTestFixture(fixture.GetType());

            nunitTestFixture.Fixture = fixture;

            TestSuite suite = new TestSuite(nunitTestFixture.TestName.Name, method.Name);

            suite.Parent  = nunitTestFixture;
            suite.Fixture = fixture;

            RowTestCase testCase = new RowTestCase(method, method.Name, arguments);

            testCase.Fixture = fixture;
            suite.Add(testCase);

            return(testCase);
        }
Example #8
0
        private void AddDynamicTestFixtures(TestSuite mainSuite, IAutoTestFixture autoTestFixture, AutoTestMode autoTestMode)
        {
            var suite = new TestSuite(autoTestMode.ToString());

            mainSuite.Add(suite);
            foreach (var testSettings in autoTestFixture.GetAutoTestSettings())
            {
                if ((testSettings.Mode & autoTestMode) != autoTestMode)
                {
                    continue;
                }
                testSettings.Mode = autoTestMode;
                var fixture = new NUnitTestFixture(userFixtureType, new object[] { testSettings.Name, testSettings });
                foreach (var category in testSettings.Categories)
                {
                    fixture.Categories.Add(category);
                }
                fixture.Categories.Add(Enum.GetName(typeof(AutoTestMode), autoTestMode));
                fixture.TestName.Name = testSettings.Name;
                suite.Add(fixture);
                AddStrategyTestCases(fixture, testSettings);
            }
        }
        private void AddDynamicTestFixtures(TestSuite mainSuite, IAutoTestFixture autoTestFixture, AutoTestMode autoTestMode)
        {
            var suite = new TestSuite(autoTestMode.ToString());

            mainSuite.Add(suite);
            foreach (var testSettings in autoTestFixture.GetAutoTestSettings())
            {
                if ((testSettings.Mode & autoTestMode) != autoTestMode)
                {
                    continue;
                }
                testSettings.Mode = autoTestMode;
//				testSettings.StoreKnownGood = testSettings.StoreKnownGood && testSettings.Mode == AutoTestMode.Historical;
                var fixture = new NUnitTestFixture(userFixtureType, new object[] { testSettings });
                fixture.TestName.Name = testSettings.Name;
                suite.Add(fixture);
                AddStrategyTestCases(fixture, testSettings);
                if (testSettings.Mode == AutoTestMode.SimulateRealTime)
                {
                    AddSymbolTestCases(fixture, testSettings);
                }
            }
        }
        private Test BuildSingleFixture(Type type, Attribute attr)
        {
            object[] arguments = null;

            if (attr != null)
            {
                arguments = (object[])Reflect.GetPropertyValue(attr, "Arguments");
#if NET_2_0
                if (type.ContainsGenericParameters)
                {
                    Type[] typeArgs = (Type[])Reflect.GetPropertyValue(attr, "TypeArgs");
                    if( typeArgs.Length > 0 || 
                        TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs))
                    {
                        type = TypeHelper.MakeGenericType(type, typeArgs);
                    }
                }
#endif
            }

            this.fixture = new NUnitTestFixture(type, arguments);
            CheckTestFixtureIsValid(fixture);

            NUnitFramework.ApplyCommonAttributes(type, fixture);

            if (fixture.RunState == RunState.Runnable && attr != null)
            {
                object objIgnore = Reflect.GetPropertyValue(attr, "Ignore");
                if (objIgnore != null && (bool)objIgnore == true)
                {
                    fixture.RunState = RunState.Ignored;
                    fixture.IgnoreReason = (string)Reflect.GetPropertyValue(attr, "IgnoreReason");
                }
            }

            AddTestCases(type);

            return this.fixture;
        }
        private Test BuildSingleFixture(Type type, Attribute attr)
        {
            object[] arguments  = null;
            IList    categories = null;

            if (attr != null)
            {
                arguments = GetArgsFromAttribute(attr);

                categories = Reflect.GetPropertyValue(attr, "Categories") as IList;
#if CLR_2_0 || CLR_4_0
                if (type.ContainsGenericParameters)
                {
                    Type[] typeArgs = GetTypeArgsFromAttribute(attr);
                    if (typeArgs == null)
                    {
                        int cnt = 0;
                        foreach (object o in arguments)
                        {
                            if (o is Type)
                            {
                                cnt++;
                            }
                            else
                            {
                                break;
                            }
                        }

                        typeArgs = new Type[cnt];
                        for (int i = 0; i < cnt; i++)
                        {
                            typeArgs[i] = (Type)arguments[i];
                        }

                        if (cnt > 0)
                        {
                            object[] args = new object[arguments.Length - cnt];
                            for (int i = 0; i < args.Length; i++)
                            {
                                args[i] = arguments[cnt + i];
                            }

                            arguments = args;
                        }
                    }

                    if (typeArgs.Length > 0 ||
                        TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs))
                    {
                        type = TypeHelper.MakeGenericType(type, typeArgs);
                    }
                }
#endif
            }

            this.fixture = new NUnitTestFixture(type, arguments);
            CheckTestFixtureIsValid(fixture);

            NUnitFramework.ApplyCommonAttributes(type, fixture);

            if (categories != null)
            {
                foreach (string category in categories)
                {
                    fixture.Categories.Add(category);
                }
            }

            if (fixture.RunState == RunState.Runnable && attr != null)
            {
                object objIgnore = Reflect.GetPropertyValue(attr, "Ignore");
                if (objIgnore != null && (bool)objIgnore == true)
                {
                    fixture.RunState     = RunState.Ignored;
                    fixture.IgnoreReason = (string)Reflect.GetPropertyValue(attr, "IgnoreReason");
                }
            }

            AddTestCases(type);

            return(this.fixture);
        }
Example #12
0
 private void ExecuteFixture(NUnitTestFixture fixture, TestRunEventListener listener)
 {
     var fixtureInstance = _settings.TestFixtureFactory.InstantiateFixture(fixture.Type);
     foreach (var method in fixture.Tests)
         InvokeTest(fixtureInstance, fixture.Name, method, listener);
 }
Example #13
0
 private object InstantiateFixture(NUnitTestFixture fixture)
 {
     try
     {
         return Activator.CreateInstance(fixture.Type);
     }
     catch (Exception e)
     {
         throw new InvalidOperationException("Could not instantiate IntegrationFixture " + fixture.Type.FullName, e);
     }
 }
        private Test BuildSingleFixture(Type type, Attribute attr)
        {
            object[] arguments = null;

            if (attr != null)
            {
                arguments = (object[])Reflect.GetPropertyValue(attr, "Arguments");
#if NET_2_0
                if (type.ContainsGenericParameters)
                {
                    Type[] typeArgs = (Type[])Reflect.GetPropertyValue(attr, "TypeArgs");
                    if( typeArgs.Length > 0 || 
                        TypeHelper.CanDeduceTypeArgsFromArgs(type, arguments, ref typeArgs))
                    {
                        type = TypeHelper.MakeGenericType(type, typeArgs);
                    }
                }
#endif
            }

            this.fixture = new NUnitTestFixture(type, arguments);
            CheckTestFixtureIsValid(fixture);

            NUnitFramework.ApplyCommonAttributes(type, fixture);

            AddTestCases(type);

            if (this.fixture.RunState != RunState.NotRunnable && this.fixture.TestCount == 0)
            {
                this.fixture.RunState = RunState.NotRunnable;
                this.fixture.IgnoreReason = fixture.TestName.Name + " does not have any tests";
            }

            return this.fixture;
        }