Ejemplo n.º 1
0
        public static SelectTestDefinition[] GetSelectTestDefinitions()
        {
            var fixture = new SelectTestDefinitionFixture();

#if !IGNORE_NC_PLNull
            var selectTest = new NC_PLNull(fixture);
#elif IGNORE_NC_PLNull && !IGNORE_NC_RDBNull
            var selectTest = new NC_RDBNull(fixture);
#endif

            var methodNames = new List <String>();
            foreach (MethodInfo methodInfo in selectTest.GetType().GetMethods().Where(m => m.GetCustomAttributes(typeof(FactAttribute), false).Count() == 1))
            {
                Func <SelectTest, Task> testMethod;
                var factAttribute = (FactAttribute)methodInfo.GetCustomAttribute(typeof(FactAttribute), false);
                if (factAttribute is TheoryAttribute)
                {
                    if (methodInfo.GetParameters().Length == 1)
                    {
                        if (methodInfo.GetParameters()[0].ParameterType == typeof(bool))
                        {
                            var methodCall = (Func <SelectTest, bool, Task>)methodInfo.CreateDelegate(typeof(Func <SelectTest, bool, Task>));
                            testMethod = i => methodCall(i, false);
                        }
                        else
                        {
                            var methodCall = (Func <SelectTest, int, Task>)methodInfo.CreateDelegate(typeof(Func <SelectTest, int, Task>));
                            testMethod = i => methodCall(i, 0);
                        }
                    }
                    else
                    {
                        var methodCall = (Func <SelectTest, int, bool, Task>)methodInfo.CreateDelegate(typeof(Func <SelectTest, int, bool, Task>));
                        testMethod = i => methodCall(i, 0, false);
                    }
                }
                else
                {
                    testMethod = (Func <SelectTest, Task>)methodInfo.CreateDelegate(typeof(Func <SelectTest, Task>));
                }

                int count = fixture.SelectTestDefinitions.Count;
                testMethod(selectTest).GetAwaiter().GetResult();
                if (fixture.SelectTestDefinitions.Count == count)
                {
                    continue;
                }

                methodNames.Add(methodInfo.Name);
            }

            for (int i = 0; i < methodNames.Count; i++)
            {
                fixture.SelectTestDefinitions[i].MethodName = methodNames[i];
            }
            return(fixture.SelectTestDefinitions.ToArray());
        }
Ejemplo n.º 2
0
        public static SelectTestDefinition[] GetSelectTestDefinitions()
        {
            var fixture    = new SelectTestDefinitionFixture();
            var selectTest = new SelectTest(fixture);

            var methodNames = new List <String>();

            foreach (MethodInfo methodInfo in selectTest.GetType().GetMethods().Where(m => m.GetCustomAttributes(typeof(FactAttribute), false).Count() == 1))
            {
                methodNames.Add(methodInfo.Name);
                var testMethod = (Func <SelectTest, Task>)methodInfo.CreateDelegate(typeof(Func <SelectTest, Task>));
                testMethod(selectTest).GetAwaiter().GetResult();
            }

            for (int i = 0; i < methodNames.Count; i++)
            {
                fixture.SelectTestDefinitions[i].MethodName = methodNames[i];
            }
            return(fixture.SelectTestDefinitions.ToArray());
        }
        public static SelectTestDefinition[] GetSelectTestDefinitions()
        {
            var fixture    = new SelectTestDefinitionFixture();
            var selectTest = new SelectTest(fixture);

            var methodNames = new List <String>();

            foreach (MethodInfo methodInfo in selectTest.GetType().GetMethods().Where(m => m.GetCustomAttributes(typeof(FactAttribute), false).Count() == 1))
            {
                Func <SelectTest, Task> testMethod;
                var factAttribute = (FactAttribute)methodInfo.GetCustomAttribute(typeof(FactAttribute), false);
                if (factAttribute is TheoryAttribute)
                {
                    var methodCall = (Func <SelectTest, bool, Task>)methodInfo.CreateDelegate(typeof(Func <SelectTest, bool, Task>));
                    testMethod = i => methodCall(i, false);
                }
                else if (factAttribute is FactAttribute)
                {
                    testMethod = (Func <SelectTest, Task>)methodInfo.CreateDelegate(typeof(Func <SelectTest, Task>));
                }
                else
                {
                    continue;
                }

                int count = fixture.SelectTestDefinitions.Count;
                testMethod(selectTest).GetAwaiter().GetResult();
                if (fixture.SelectTestDefinitions.Count == count)
                {
                    continue;
                }

                methodNames.Add(methodInfo.Name);
            }

            for (int i = 0; i < methodNames.Count; i++)
            {
                fixture.SelectTestDefinitions[i].MethodName = methodNames[i];
            }
            return(fixture.SelectTestDefinitions.ToArray());
        }