Ejemplo n.º 1
0
            public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite)
            {
                var explic = method.GetCustomAttributes <ExplicitAttribute>(true)
                             .Cast <IApplyToTest>()
                             .Union(method.GetCustomAttributes <IgnoreAttribute>(true))
                             .ToList();

                var builder = new NUnitTestCaseBuilder();

                TestMethod test    = null;
                var        hasTest = false;

                foreach (var provider in _providerNames)
                {
                    var isIgnore = !UserProviders.ContainsKey(provider);

                    var caseNumber = 0;
                    foreach (var parameters in GetParameters(provider))
                    {
                        var data = new TestCaseParameters(parameters.Item1);

                        test = builder.BuildTestMethod(method, suite, data);

                        foreach (var attr in explic)
                        {
                            attr.ApplyToTest(test);
                        }

                        test.Properties.Set(PropertyNames.Order, GetOrder(method));
                        //test.Properties.Set(PropertyNames.ParallelScope, ParallelScope);
                        test.Properties.Set(PropertyNames.Category, provider);

                        SetName(test, method, provider, false, caseNumber++, parameters.Item2);

                        if (isIgnore)
                        {
                            if (test.RunState != RunState.NotRunnable && test.RunState != RunState.Explicit)
                            {
                                test.RunState = RunState.Ignored;
                            }

                            test.Properties.Set(PropertyNames.SkipReason, "Provider is disabled. See UserDataProviders.txt");
                            continue;
                        }

                        hasTest = true;
                        yield return(test);
                    }

#if !NETSTANDARD && !MONO
                    if (!isIgnore && _includeLinqService)
                    {
                        var linqCaseNumber = 0;
                        foreach (var parameters in GetParameters(provider + ".LinqService"))
                        {
                            var data = new TestCaseParameters(parameters.Item1);
                            test = builder.BuildTestMethod(method, suite, data);

                            foreach (var attr in explic)
                            {
                                attr.ApplyToTest(test);
                            }

                            test.Properties.Set(PropertyNames.Order, GetOrder(method));
                            test.Properties.Set(PropertyNames.ParallelScope, ParallelScope);
                            test.Properties.Set(PropertyNames.Category, provider);

                            SetName(test, method, provider, true, linqCaseNumber++, parameters.Item2);

                            yield return(test);
                        }
                    }
#endif
                }

                if (!hasTest)
                {
                    yield return(test);
                }
            }
Ejemplo n.º 2
0
            public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite)
            {
                var tests = UserProviders.ContainsKey(_providerName) ?
                            new[]
                {
                    new TypeTestData("bigintDataType", 0, (n, t, c) => t.TestTypeEx <long?>             (c, n, DataType.Int64), 1000000),
                    new TypeTestData("bigintDataType", 1, (n, t, c) => t.TestTypeEx <long?>             (c, n, DataType.Int64), 1000000),
                    new TypeTestData("numericDataType", (n, t, c) => t.TestTypeEx <decimal?>          (c, n, DataType.Decimal), 9999999m),
                    new TypeTestData("smallintDataType", (n, t, c) => t.TestTypeEx <short?>            (c, n, DataType.Int16), 25555),
                    new TypeTestData("intDataType", (n, t, c) => t.TestTypeEx <int?>              (c, n, DataType.Int32), 7777777),
//						new TypeTestData("moneyDataType",       (n,t,c) => t.TestTypeEx<decimal?>          (c, n, DataType.Money),   100000m),
                    new TypeTestData("doubleDataType", (n, t, c) => t.TestTypeEx <double?>           (c, n, DataType.Double), 20.31d),
                    new TypeTestData("realDataType", (n, t, c) => t.TestTypeEx <float?>            (c, n, DataType.Single), 16.2f),

#if NPG2
                    new TypeTestData("timestampDataType", (n, t, c) => t.TestTypeEx <NpgsqlTimeStamp?>  (c, n), new NpgsqlTimeStamp(2012, 12, 12, 12, 12, 12)),
                    new TypeTestData("timestampTZDataType", (n, t, c) => t.TestTypeEx <NpgsqlTimeStampTZ?>(c, n), new NpgsqlTimeStampTZ(2012, 12, 12, 11, 12, 12, new NpgsqlTimeZone(-5, 0))),
                    new TypeTestData("timeDataType", (n, t, c) => t.TestTypeEx <NpgsqlTime?>       (c, n), new NpgsqlTime(12, 12, 12)),
                    new TypeTestData("timeTZDataType", (n, t, c) => t.TestTypeEx <NpgsqlTimeTZ?>     (c, n), new NpgsqlTimeTZ(12, 12, 12)),
                    new TypeTestData("intervalDataType", (n, t, c) => t.TestTypeEx <NpgsqlInterval?>   (c, n), new NpgsqlInterval(1, 3, 5, 20)),
                    new TypeTestData("bitDataType", (n, t, c) => t.TestTypeEx <BitString?>        (c, n), new BitString(new[] { true, false, true })),
                    new TypeTestData("macaddrDataType", (n, t, c) => t.TestTypeEx <NpgsqlMacAddress?> (c, n), new NpgsqlMacAddress("01:02:03:04:05:06")),
#else
//						new TypeTestData("timestampDataType",   (n,t,c) => t.TestTypeEx<NpgsqlTimeStamp?>  (c, n),                       new NpgsqlTimeStamp(2012, 12, 12, 12, 12, 12)),
//						new TypeTestData("timestampTZDataType", (n,t,c) => t.TestTypeEx<NpgsqlTimeStampTZ?>(c, n),                       new NpgsqlTimeStampTZ(2012, 12, 12, 11, 12, 12, new NpgsqlTimeZone(-5, 0))),
                    new TypeTestData("timeDataType", (n, t, c) => t.TestTypeEx <TimeSpan?>         (c, n), new TimeSpan(12, 12, 12)),
//						new TypeTestData("timeTZDataType",      (n,t,c) => t.TestTypeEx<NpgsqlTimeTZ?>     (c, n),                       new NpgsqlTimeTZ(12, 12, 12)),
//						new TypeTestData("intervalDataType",    (n,t,c) => t.TestTypeEx<TimeSpan?>         (c, n),                       new TimeSpan(1, 3, 5, 20)),
                    new TypeTestData("bitDataType", (n, t, c) => t.TestTypeEx <BitArray>          (c, n), new BitArray(new[] { true, false, true })),
                    new TypeTestData("varBitDataType", (n, t, c) => t.TestTypeEx <BitArray>          (c, n), new BitArray(new[] { true, false, true, true })),
                    new TypeTestData("macaddrDataType", (n, t, c) => t.TestTypeEx <PhysicalAddress>   (c, n, skipDefaultNull: true), new PhysicalAddress(new byte[] { 1, 2, 3, 4, 5, 6 })),
#endif

                    new TypeTestData("timestampDataType", (n, t, c) => t.TestTypeEx <DateTime?>         (c, n, DataType.DateTime2), new DateTime(2012, 12, 12, 12, 12, 12)),
                    new TypeTestData("timestampTZDataType", (n, t, c) => t.TestTypeEx <DateTimeOffset?>   (c, n, DataType.DateTimeOffset), new DateTimeOffset(2012, 12, 12, 11, 12, 12, new TimeSpan(-5, 0, 0))),
                    new TypeTestData("dateDataType", 0, (n, t, c) => t.TestTypeEx <NpgsqlDate?>       (c, n, skipDefaultNull: true), new NpgsqlDate(2012, 12, 12)),
                    new TypeTestData("dateDataType", 1, (n, t, c) => t.TestTypeEx <DateTime?>         (c, n, DataType.Date), new DateTime(2012, 12, 12)),

                    new TypeTestData("charDataType", 0, (n, t, c) => t.TestTypeEx <char?>             (c, n, DataType.Char), '1'),
                    new TypeTestData("charDataType", 1, (n, t, c) => t.TestTypeEx <string>            (c, n, DataType.Char, skipDefaultNull: true), "1"),
                    new TypeTestData("charDataType", 2, (n, t, c) => t.TestTypeEx <string>            (c, n, DataType.NChar, skipDefaultNull: true), "1"),
                    new TypeTestData("varcharDataType", 0, (n, t, c) => t.TestTypeEx <string>            (c, n, DataType.VarChar, skipDefaultNull: true), "234"),
                    new TypeTestData("varcharDataType", 1, (n, t, c) => t.TestTypeEx <string>            (c, n, DataType.NVarChar, skipDefaultNull: true), "234"),
                    new TypeTestData("textDataType", (n, t, c) => t.TestTypeEx <string>            (c, n, DataType.Text, skipDefaultNull: true), "567"),

                    new TypeTestData("binaryDataType", 0, (n, t, c) => t.TestTypeEx <byte[]>            (c, n, DataType.Binary), new byte[] { 42 }),
                    new TypeTestData("binaryDataType", 1, (n, t, c) => t.TestTypeEx <byte[]>            (c, n, DataType.VarBinary), new byte[] { 42 }),
                    new TypeTestData("binaryDataType", 2, (n, t, c) => t.TestTypeEx <Binary>            (c, n, DataType.VarBinary).ToArray(), new byte[] { 42 }),

                    new TypeTestData("uuidDataType", (n, t, c) => t.TestTypeEx <Guid?>             (c, n, DataType.Guid), new Guid("6F9619FF-8B86-D011-B42D-00C04FC964FF")),
                    new TypeTestData("booleanDataType", (n, t, c) => t.TestTypeEx <bool?>             (c, n, DataType.Boolean), true),
//						new TypeTestData("colorDataType",       (n,t,c) => t.TestTypeEx<string>            (c, n, skipDefaultNull:true, skipDefault:true,skipUndefined:true), "Green"),

                    new TypeTestData("pointDataType", (n, t, c) => t.TestTypeEx <NpgsqlPoint?>      (c, n, skipNull: true, skipNotNull: true), new NpgsqlPoint(1, 2)),
                    new TypeTestData("lsegDataType", (n, t, c) => t.TestTypeEx <NpgsqlLSeg?>       (c, n, skipDefaultNull: true), new NpgsqlLSeg(new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4))),
                    new TypeTestData("boxDataType", (n, t, c) => t.TestTypeEx <NpgsqlBox?>        (c, n, skipDefaultNull: true).ToString(), new NpgsqlBox(new NpgsqlPoint(3, 4), new NpgsqlPoint(1, 2)).ToString()),
                    new TypeTestData("pathDataType", (n, t, c) => t.TestTypeEx <NpgsqlPath?>       (c, n, skipDefaultNull: true), new NpgsqlPath(new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4))),
                    new TypeTestData("polygonDataType", (n, t, c) => t.TestTypeEx <NpgsqlPolygon?>    (c, n, skipNull: true, skipNotNull: true), new NpgsqlPolygon(new NpgsqlPoint(1, 2), new NpgsqlPoint(3, 4))),
                    new TypeTestData("circleDataType", (n, t, c) => t.TestTypeEx <NpgsqlCircle?>     (c, n, skipDefaultNull: true), new NpgsqlCircle(new NpgsqlPoint(1, 2), 3)),

                    new TypeTestData("inetDataType", (n, t, c) => t.TestTypeEx <NpgsqlInet?>       (c, n, skipDefaultNull: true), new NpgsqlInet(new IPAddress(new byte[] { 192, 168, 1, 1 }))),

                    new TypeTestData("xmlDataType", 0, (n, t, c) => t.TestTypeEx <string>            (c, n, DataType.Xml, skipNull: true, skipNotNull: true),
                                     "<root><element strattr=\"strvalue\" intattr=\"12345\"/></root>"),
                    new TypeTestData("xmlDataType", 1, (n, t, c) => t.TestTypeEx <XDocument>         (c, n, DataType.Xml, skipNull: true, skipNotNull: true).ToString(),
                                     XDocument.Parse("<root><element strattr=\"strvalue\" intattr=\"12345\"/></root>").ToString()),
                    new TypeTestData("xmlDataType", 2, (n, t, c) => t.TestTypeEx <XmlDocument>       (c, n, DataType.Xml, skipNull: true, skipNotNull: true).InnerXml,
                                     ConvertTo <XmlDocument> .From("<root><element strattr=\"strvalue\" intattr=\"12345\"/></root>").InnerXml),
                }
                                        :
                new[]
                {
                    new TypeTestData("ignore", (n, t, c) => t.TestTypeEx <long?>(c, n, DataType.Int64), 1000000)
                };

                var builder = new NUnitTestCaseBuilder();

                var data = tests.Select(t => new TestCaseParameters(new object[] { t.Name, t.ID, t, _providerName }));

                foreach (var item in data)
                {
                    var test = builder.BuildTestMethod(method, suite, item);

                    test.Properties.Set(PropertyNames.Category, _providerName);

                    if (!UserProviders.ContainsKey(_providerName))
                    {
                        test.RunState = RunState.Ignored;
                        test.Properties.Set(PropertyNames.SkipReason, "Provider is disabled. See UserDataProviders.txt");
                    }

                    yield return(test);
                }
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Construct one or more TestMethods from a given MethodInfo,
        /// using available parameter data.
        /// </summary>
        /// <param name="method">The MethodInfo for which tests are to be constructed.</param>
        /// <param name="suite">The suite to which the tests will be added.</param>
        /// <returns>One or more TestMethods</returns>
        public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite)
        {
            List <TestMethod> tests = new List <TestMethod>();

#if NETCF
            if (method.ContainsGenericParameters)
            {
                var genericParams    = method.GetGenericArguments();
                var numGenericParams = genericParams.Length;

                var         o       = new object();
                var         tryArgs = Enumerable.Repeat(o, numGenericParams).ToArray();
                IMethodInfo mi;

                try
                {
                    // This fails if the generic method has constraints
                    // that are not met by object.
                    mi = method.MakeGenericMethodEx(tryArgs);
                    if (mi == null)
                    {
                        return(tests);
                    }
                }
                catch
                {
                    return(tests);
                }

                var par = mi.GetParameters();

                if (par.Length == 0)
                {
                    return(tests);
                }

                var sourceData = par.Select(p => _dataProvider.GetDataFor(p)).ToArray();
                foreach (var parms in _strategy.GetTestCases(sourceData))
                {
                    mi = method.MakeGenericMethodEx(parms.Arguments);
                    if (mi == null)
                    {
                        var tm = new TestMethod(method, suite);
                        tm.RunState = RunState.NotRunnable;
                        tm.Properties.Set(PropertyNames.SkipReason, "Incompatible arguments");
                        tests.Add(tm);
                    }
                    else
                    {
                        tests.Add(_builder.BuildTestMethod(mi, suite, (TestCaseParameters)parms));
                    }
                }

                return(tests);
            }
#endif
            IParameterInfo[] parameters = method.GetParameters();

            if (parameters.Length > 0)
            {
                IEnumerable[] sources = new IEnumerable[parameters.Length];

                try
                {
                    for (int i = 0; i < parameters.Length; i++)
                    {
                        sources[i] = _dataProvider.GetDataFor(parameters[i]);
                    }
                }
                catch (InvalidDataSourceException ex)
                {
                    var parms = new TestCaseParameters();
                    parms.RunState = RunState.NotRunnable;
                    parms.Properties.Set(PropertyNames.SkipReason, ex.Message);
                    tests.Add(_builder.BuildTestMethod(method, suite, parms));
                    return(tests);
                }

                foreach (var parms in _strategy.GetTestCases(sources))
                {
                    tests.Add(_builder.BuildTestMethod(method, suite, (TestCaseParameters)parms));
                }
            }

            return(tests);
        }
        public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite)
        {
            // pick attributes that we want to apply to each configuration-specific test case
            var testAttributes = method.GetCustomAttributes <ExplicitAttribute>(true)
                                 .Cast <IApplyToTest>()
                                 .Union(method.TypeInfo.GetCustomAttributes <ExplicitAttribute>(true))
#if !NETSTANDARD1_6
                                 .Union(method.TypeInfo.Assembly.GetCustomAttributes(true).OfType <ExplicitAttribute>())
#endif
                                 .Union(method.GetCustomAttributes <IgnoreAttribute>(true))
                                 .Union(method.TypeInfo.GetCustomAttributes <IgnoreAttribute>(true))
#if !NETSTANDARD1_6
                                 .Union(method.TypeInfo.Assembly.GetCustomAttributes(true).OfType <IgnoreAttribute>())
#endif
                                 .Union(method.GetCustomAttributes <ActiveIssueAttribute>(true))
                                 .Union(method.TypeInfo.GetCustomAttributes <ActiveIssueAttribute>(true))
                                 .ToList();

            var maxTime = method.GetCustomAttributes <MaxTimeAttribute>(true).FirstOrDefault();

            testAttributes.Add(maxTime ?? new MaxTimeAttribute(10000));

//#if !NETSTANDARD1_6
//				var timeout = method.GetCustomAttributes<TimeoutAttribute>(true).FirstOrDefault();
//				explic.Add(timeout ?? new TimeoutAttribute(10000));
//#endif

            var builder = new NUnitTestCaseBuilder();

            TestMethod test    = null;
            var        hasTest = false;

            foreach (var provider in _providerNames)
            {
                var isIgnore = !TestBase.UserProviders.Contains(provider);

                var caseNumber = 0;
                foreach (var parameters in GetParameters(provider))
                {
                    var data = new TestCaseParameters(parameters.Item1);

                    test = builder.BuildTestMethod(method, suite, data);

                    test.Properties.Set(ProviderProperty, provider);
                    test.Properties.Set(ConfigurationProperty, provider);
                    test.Properties.Set(IsLinqServiceProperty, false);

                    foreach (var attr in testAttributes)
                    {
                        attr.ApplyToTest(test);
                    }

                    test.Properties.Set(PropertyNames.Order, GetOrder(method));
                    //test.Properties.Set(PropertyNames.ParallelScope, ParallelScope);

                    test.Properties.Add(PropertyNames.Category, provider);

                    SetName(test, method, provider, false, caseNumber++, parameters.Item2);

                    if (isIgnore)
                    {
                        // if (test.RunState != RunState.NotRunnable && test.RunState != RunState.Explicit)
                        test.RunState = RunState.Ignored;

#if !APPVEYOR && !TRAVIS
                        if (!test.Properties.ContainsKey(PropertyNames.SkipReason))
                        {
                            test.Properties.Set(PropertyNames.SkipReason, "Provider is disabled. See UserDataProviders.json or DataProviders.json");
                        }
#endif
                        continue;
                    }

                    if (test.RunState != RunState.Runnable)
                    {
                        test.Properties.Add(PropertyNames.Category, "Ignored");
                    }

                    hasTest = true;
                    yield return(test);
                }

#if !NETSTANDARD1_6 && !NETSTANDARD2_0 && !MONO
                if (!isIgnore && _includeLinqService)
                {
                    var linqCaseNumber = 0;
                    var providerBase   = provider;
                    foreach (var parameters in GetParameters(provider + ".LinqService"))
                    {
                        var data = new TestCaseParameters(parameters.Item1);
                        test = builder.BuildTestMethod(method, suite, data);

                        test.Properties.Set(ProviderProperty, providerBase);
                        test.Properties.Set(ConfigurationProperty, provider);
                        test.Properties.Set(IsLinqServiceProperty, true);

                        foreach (var attr in testAttributes)
                        {
                            attr.ApplyToTest(test);
                        }

                        test.Properties.Set(PropertyNames.Order, GetOrder(method));
                        test.Properties.Set(PropertyNames.ParallelScope, ParallelScope);
                        test.Properties.Add(PropertyNames.Category, provider);

                        SetName(test, method, provider, true, linqCaseNumber++, parameters.Item2);

                        yield return(test);
                    }
                }
#endif
            }

            if (!hasTest)
            {
                yield return(test);
            }
        }
Ejemplo n.º 5
0
            public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite)
            {
                var builder = new NUnitTestCaseBuilder();

                yield return(builder.BuildTestMethod(method, suite, new TestCaseParameters(new object[] { "ArgA", "ArgB" })));
            }
        /// <summary>
        /// Construct one or more TestMethods from a given MethodInfo,
        /// using available parameter data.
        /// </summary>
        /// <param name="method">The MethodInfo for which tests are to be constructed.</param>
        /// <param name="suite">The suite to which the tests will be added.</param>
        /// <returns>One or more TestMethods</returns>
        public IEnumerable <TestMethod> BuildFrom(MethodInfo method, Test suite)
        {
            List <TestMethod> tests = new List <TestMethod>();

#if NETCF
            if (method.ContainsGenericParameters)
            {
                var genericParams    = method.GetGenericArguments();
                var numGenericParams = genericParams.Length;

                var o       = new object();
                var tryArgs = Enumerable.Repeat(o, numGenericParams).ToArray();

                var mi = method.MakeGenericMethodEx(tryArgs);
                if (mi == null)
                {
                    return(tests);
                }

                var par = mi.GetParameters();
                if (par.Length == 0)
                {
                    return(tests);
                }

                var sourceData = par.Select(p => _dataProvider.GetDataFor(p)).ToArray();
                foreach (var parms in _strategy.GetTestCases(sourceData))
                {
                    mi = method.MakeGenericMethodEx(parms.Arguments);
                    if (mi == null)
                    {
                        var tm = new TestMethod(method, suite);
                        tm.RunState = RunState.NotRunnable;
                        tm.Properties.Set(PropertyNames.SkipReason, "Incompatible arguments");
                        tests.Add(tm);
                    }
                    else
                    {
                        tests.Add(_builder.BuildTestMethod(mi, suite, (ParameterSet)parms));
                    }
                }

                return(tests);
            }
#endif
            ParameterInfo[] parameters = method.GetParameters();

            if (parameters.Length > 0)
            {
                IEnumerable[] sources = new IEnumerable[parameters.Length];
                for (int i = 0; i < parameters.Length; i++)
                {
                    sources[i] = _dataProvider.GetDataFor(parameters[i]);
                }

                foreach (var parms in _strategy.GetTestCases(sources))
                {
                    tests.Add(_builder.BuildTestMethod(method, suite, (ParameterSet)parms));
                }
            }

            return(tests);
        }
Ejemplo n.º 7
0
            public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite)
            {
                var explic = method.GetCustomAttributes <ExplicitAttribute>(true)
                             .Cast <IApplyToTest>()
                             .Union(method.GetCustomAttributes <IgnoreAttribute>(true))
                             .ToList();

                var builder = new NUnitTestCaseBuilder();

                TestMethod test    = null;
                var        hasTest = false;

                foreach (var provider in _providerNames)
                {
                    var isIgnore = !UserProviders.ContainsKey(provider);

                    var data = new TestCaseParameters(new object[] { provider });

                    test = builder.BuildTestMethod(method, suite, data);

                    foreach (var attr in explic)
                    {
                        attr.ApplyToTest(test);
                    }

                    test.Properties.Set(PropertyNames.Category, provider);
                    SetName(test, method, provider, false);

                    if (isIgnore)
                    {
                        if (test.RunState != RunState.NotRunnable && test.RunState != RunState.Explicit)
                        {
                            test.RunState = RunState.Ignored;
                        }

                        test.Properties.Set(PropertyNames.SkipReason, "Provider is disabled. See UserDataProviders.txt");
                        continue;
                    }

                    hasTest = true;

                    yield return(test);

                    if (_includeLinqService)
                    {
                        data = new TestCaseParameters(new object[] { provider + ".LinqService" });
                        test = builder.BuildTestMethod(method, suite, data);

                        foreach (var attr in explic)
                        {
                            attr.ApplyToTest(test);
                        }

                        test.Properties.Set(PropertyNames.Category, provider);
                        SetName(test, method, provider, true);

                        yield return(test);
                    }
                }

                if (!hasTest)
                {
                    yield return(test);
                }
            }