예제 #1
0
        public void TestByCall(
            [Values("tableName1", "tableName2")] string tableName,
            [Values("database1", "database2")]  string databaseName,
            [Values("schema1", "schema2")]    string schemaName
            )
        {
            if (!UserProviders.Contains(ProviderName.SqlServer))
            {
                return;
            }

            using (var db = GetDataContext(ProviderName.SqlServer))
            {
                var query =
                    from c in db.Child
                    from cc in (
                        from c1 in GetTestTable <Child>(db, tableName, databaseName, schemaName)
                        from c2 in GetTestTable <Child>(db, tableName, databaseName, schemaName)
                        select new { c1, c2 }
                        )
                    select cc;

                var sql = query.ToString() !;
                Console.WriteLine(sql);

                Assert.That(CountOccurrences(sql, tableName), Is.EqualTo(2));
                Assert.That(CountOccurrences(sql, databaseName), Is.EqualTo(2));
                Assert.That(CountOccurrences(sql, schemaName), Is.EqualTo(2));
            }
        }
예제 #2
0
        public void TakeHint(
            [Values(TakeHints.Percent, TakeHints.WithTies, TakeHints.Percent | TakeHints.WithTies)] TakeHints takeHint
            )
        {
            if (!UserProviders.Contains(ProviderName.SqlServer))
            {
                return;
            }

            using (var db = GetDataContext(ProviderName.SqlServer))
            {
                var query =
                    from c1 in db.Child
                    from c2 in db.Child.Take(10, takeHint)
                    select new { c1, c2 };

                var sql = query.ToString();
                Console.WriteLine(sql);

                if (takeHint.HasFlag(TakeHints.Percent))
                {
                    Assert.That(sql, Contains.Substring("PERCENT"));
                }

                if (takeHint.HasFlag(TakeHints.WithTies))
                {
                    Assert.That(sql, Contains.Substring("WITH TIES"));
                }
            }
        }
예제 #3
0
        public void TestInlined(
            [Values("tableName1", "tableName2")] string tableName,
            [Values("database1", "database2")]  string databaseName,
            [Values("owner1", "owner2")]     string ownerName,
            [Values("schema1", "schema2")]    string schemaName
            )
        {
            if (!UserProviders.ContainsKey(ProviderName.SqlServer))
            {
                return;
            }

            using (var db = GetDataContext(ProviderName.SqlServer))
            {
                var query =
                    from c in db.Child
                    from cc in
                    (
                        from c1 in db.Child.DatabaseName(databaseName).OwnerName(ownerName).SchemaName(schemaName)
                        .TableName(tableName)
                        from c2 in db.Child.DatabaseName(databaseName).OwnerName(ownerName).SchemaName(schemaName)
                        .TableName(tableName)
                        select new { c1, c2 }
                    )
                    select cc;

                var sql = query.ToString();
                Console.WriteLine(sql);

                Assert.That(CountOccurences(sql, tableName), Is.EqualTo(2));
                Assert.That(CountOccurences(sql, databaseName), Is.EqualTo(2));
                // Assert.That(CountOccurences(sql, ownerName),    Is.EqualTo(2));
                Assert.That(CountOccurences(sql, schemaName), Is.EqualTo(2));
            }
        }
예제 #4
0
파일: TestBase.cs 프로젝트: tcomlab/linq2db
        static TestBase()
        {
            //Configuration.AvoidSpecificDataProviderAPI = true;
            //Configuration.Linq.GenerateExpressionTest = true;

            var providerListFile =
                File.Exists(@"..\..\UserDataProviders.txt") ?
                @"..\..\UserDataProviders.txt" :
                @"..\..\DefaultDataProviders.txt";

            UserProviders.AddRange(
                File.ReadAllLines(providerListFile)
                .Select(s => s.Trim())
                .Where(s => s.Length > 0 && !s.StartsWith("--")));

            DataConnection.TurnTraceSwitchOn();

            LinqService.TypeResolver = str =>
            {
                switch (str)
                {
                case "Tests.Model.Gender": return(typeof(Gender));

                case "Tests.Model.Person": return(typeof(Person));

                default: return(null);
                }
            };

            OpenHost();
        }
예제 #5
0
파일: TestBase.cs 프로젝트: hugoaa/linq2db
        static TestBase()
        {
            //Configuration.AvoidSpecificDataProviderAPI = true;
            //Configuration.Linq.GenerateExpressionTest = true;

            var providerListFile =
                File.Exists(@"..\..\UserDataProviders.txt") ?
                @"..\..\UserDataProviders.txt" :
                @"..\..\DefaultDataProviders.txt";

            UserProviders.AddRange(
                File.ReadAllLines(providerListFile)
                .Select(s => s.Trim())
                .Where(s => s.Length > 0 && !s.StartsWith("--"))
                .Select(s =>
            {
                var ss = s.Split('*');
                switch (ss.Length)
                {
                case 0: return(null);

                case 1: return(new UserProviderInfo {
                        Name = ss[0].Trim()
                    });

                default: return(new UserProviderInfo {
                        Name = ss[0].Trim(), ConnectionString = ss[1].Trim()
                    });
                }
            }));

            foreach (var provider in UserProviders)
            {
                if (provider.ConnectionString != null)
                {
                    DataConnection.SetConnectionString(provider.Name, provider.ConnectionString);
                }
            }

            DataConnection.TurnTraceSwitchOn();

            LinqService.TypeResolver = str =>
            {
                switch (str)
                {
                case "Tests.Model.Gender": return(typeof(Gender));

                case "Tests.Model.Person": return(typeof(Person));

                default: return(null);
                }
            };

            OpenHost();
        }
예제 #6
0
        /// <summary>
        /// Performs tasks associated with listening ETW events on Windows.
        /// </summary>
        /// <param name="runner">Operation to be profiled/traced.</param>
        /// <returns>The return value of the method that the runner delegate encapsulates.</returns>
        public TResult Record(Func <TResult> runner)
        {
            if (runner == null)
            {
                throw new ArgumentNullException(nameof(runner));
            }

            var fi             = new FileInfo(UserSessionData.FileName);
            var kernelFileName = Path.Combine($"{fi.DirectoryName}", $"{Path.GetFileNameWithoutExtension(fi.Name)}.kernel.etl");
            var kernelProvider = KernelProviders.Aggregate(KernelProvider.Default,
                                                           (current, item) => new KernelProvider
            {
                Flags        = current.Flags | item.Flags,
                StackCapture = current.StackCapture | item.StackCapture,
            });
            var needKernelSession = Helper.NeedSeparateKernelSession(kernelProvider);

            if (needKernelSession && !Helper.CanEnableKernelProvider)
            {
                const string message = "The application is required to run as Administrator in order to capture kernel data.";
                WriteErrorLine(message);
                throw new UnauthorizedAccessException(message);
            }

            TResult result;

            WriteDebugLine("ETW capture start.");
            using (var kernelSession = needKernelSession ? Helper.MakeKernelSession(kernelFileName, UserSessionData.BufferSizeMB) : null)
            {
                kernelSession?.EnableKernelProvider(kernelProvider.Flags, kernelProvider.StackCapture);

                using (var userSession = new Session(UserSessionData))
                {
                    UserProviders.ForEach(provider =>
                    {
                        userSession.EnableProvider(provider.Guid, provider.Level, provider.Keywords, provider.Options);
                    });

                    result = runner();
                }
            }
            WriteDebugLine("ETW capture stop.");

            WriteDebugLine("ETW merge start.");
            TraceEventSession.MergeInPlace(UserSessionData.FileName, Console.Out);
            WriteDebugLine("ETW merge stop.");

            return(result);
        }
예제 #7
0
            public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite)
            {
                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);

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

                    if (isIgnore)
                    {
                        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);

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

                        yield return(test);
                    }
                }

                if (!hasTest)
                {
                    yield return(test);
                }
            }
예제 #8
0
            public override IEnumerable GetData(ParameterInfo parameter)
            {
                if (Include != null)
                {
                    var list = Include.Intersect(
                        ExcludeLinqService == false ?
                        UserProviders.Select(_ => _.Name).Concat(UserProviders.Select(p => p + ".LinqService")) :
                        UserProviders.Select(_ => _.Name)).
                               ToArray();

                    return(list);
                }

                var providers = new List <string>();

                foreach (var info in Providers)
                {
                    if (info.Skip && Include == null)
                    {
                        continue;
                    }

                    if (Except != null && Except.Contains(info.Name))
                    {
                        continue;
                    }

                    if (!UserProviders.Select(_ => _.Name).Contains(info.Name))
                    {
                        continue;
                    }

                    providers.Add(info.Name);

                    if (!ExcludeLinqService)
                    {
                        providers.Add(info.Name + ".LinqService");
                    }
                }

                return(providers.ToArray());
            }
예제 #9
0
        public void TestSqlQueryDependent(
            [Values(
                 "MIN",
                 "MAX",
                 "AVG",
                 "COUNT"
                 )] string funcName,
            [Values(
                 nameof(ALLTYPE.ID),
                 nameof(ALLTYPE.BIGINTDATATYPE),
                 nameof(ALLTYPE.SMALLINTDATATYPE),
                 nameof(ALLTYPE.DECIMALDATATYPE),
                 nameof(ALLTYPE.DECFLOATDATATYPE),
                 nameof(ALLTYPE.INTDATATYPE),
                 nameof(ALLTYPE.REALDATATYPE),
                 nameof(ALLTYPE.TIMEDATATYPE)
                 )] string fieldName)
        {
            if (!UserProviders.Contains(ProviderName.SQLiteClassic))
            {
                return;
            }

            using (var db = GetDataContext(ProviderName.SQLiteClassic))
            {
                var query =
                    from t in db.GetTable <ALLTYPE>()
                    from c in db.GetTable <Child>()
                    select new
                {
                    Aggregate = AggregateFunc(funcName, fieldName)
                };

                var sql = query.ToString();
                Console.WriteLine(sql);

                Assert.That(sql, Contains.Substring(funcName).And.Contains(fieldName));
            }
        }
예제 #10
0
            static IEnumerable TestData(CacheMode mode)
            {
                foreach (var provider in UserProviders.Where(p => p == TestProvName.NoopProvider))
                {
                    foreach (var cnt in new[] { 1, 2, 5, 10, 20 })
                    {
                        foreach (var set in new[]
                        {
                            // linq queries
                            new { Name = "Select", Action = new Action <ITestDataContext>[] { Select } },
                            new { Name = "Insert", Action = new Action <ITestDataContext>[] { Insert } },
                            new { Name = "InsertWithIdentity", Action = new Action <ITestDataContext>[] { InsertWithIdentity } },
                            new { Name = "InsertOrUpdate", Action = new Action <ITestDataContext>[] { InsertOrUpdate } },
                            new { Name = "Update", Action = new Action <ITestDataContext>[] { Update } },
                            new { Name = "Delete", Action = new Action <ITestDataContext>[] { Delete } },
                            new { Name = "MixedLinq", Action = new Action <ITestDataContext>[] { Select, Insert, InsertWithIdentity, InsertOrUpdate, Update, Delete } },

                            // object queries
                            new { Name = "InsertObject", Action = new Action <ITestDataContext>[] { InsertObject } },
                            new { Name = "InsertWithIdentityObject", Action = new Action <ITestDataContext>[] { InsertWithIdentityObject } },
                            new { Name = "InsertOrUpdateObject", Action = new Action <ITestDataContext>[] { InsertOrUpdateObject } },
                            new { Name = "UpdateObject", Action = new Action <ITestDataContext>[] { UpdateObject } },
                            new { Name = "DeleteObject", Action = new Action <ITestDataContext>[] { DeleteObject } },
                            new { Name = "MixedObject", Action = new Action <ITestDataContext>[] { InsertObject, InsertWithIdentityObject, InsertOrUpdateObject, UpdateObject, DeleteObject } },

                            // linq and object queries mixed
                            new { Name = "MixedAll", Action = new Action <ITestDataContext>[] { Select, Insert, InsertWithIdentity, InsertOrUpdate, Update, Delete, InsertObject, InsertWithIdentityObject, InsertOrUpdateObject, UpdateObject, DeleteObject } },
                        })
                        {
                            var baseName = $"TestPerformance_set-{set.Name}_threads-{cnt:00}_cache-{mode}";
                            yield return(new TestCaseData(provider, cnt, set.Action, baseName)
                            {
                                TestName = baseName
                            });
                        }
                    }
                }
            }
예제 #11
0
        static TestBase()
        {
            var providerListFile =
                File.Exists(@"..\..\UserDataProviders.txt") ?
                @"..\..\UserDataProviders.txt" :
                @"..\..\DefaultDataProviders.txt";

            UserProviders.AddRange(
                File.ReadAllLines(providerListFile)
                .Select(s => s.Trim())
                .Where(s => s.Length > 0 && !s.StartsWith("--"))
                .Select(s =>
            {
                var ss = s.Split('*');
                switch (ss.Length)
                {
                case 0:  return(null);

                case 1:  return(new UserProviderInfo {
                        Name = ss[0].Trim()
                    });

                default: return(new UserProviderInfo {
                        Name = ss[0].Trim(), ConnectionString = ss[1].Trim()
                    });
                }
            })
                .Where(_ => _ != null));

            foreach (var provider in UserProviders)
            {
                if (provider.ConnectionString != null)
                {
                    DbManager.AddConnectionString(provider.Name, provider.ConnectionString);
                }
            }


            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
            {
                string assembly;

                if (args.Name.IndexOf("Sybase.AdoNet2.AseClient") >= 0)
                {
                    assembly = @"Sybase\Sybase.AdoNet2.AseClient.dll";
                }
                else if (args.Name.IndexOf("Oracle.DataAccess") >= 0)
                {
                    assembly = @"Oracle\Oracle.DataAccess.dll";
                }
                else if (args.Name.IndexOf("IBM.Data.DB2") >= 0)
                {
                    assembly = @"IBM\IBM.Data.DB2.dll";
                }
                else if (args.Name.IndexOf("Npgsql.resources") >= 0)
                {
                    return(null);
                }
                else if (args.Name.IndexOf("Npgsql") >= 0)
                {
                    assembly = @"PostgreSql\Npgsql.dll";
                }
                else if (args.Name.IndexOf("Mono.Security") >= 0)
                {
                    assembly = @"PostgreSql\Mono.Security.dll";
                }
                else if (args.Name.IndexOf("System.Data.SqlServerCe,") >= 0)
                {
                    assembly = @"SqlCe\System.Data.SqlServerCe.dll";
                }
                else
                {
                    return(null);
                }

                assembly = @"..\..\..\..\Redist\" + assembly;

                if (!File.Exists(assembly))
                {
                    assembly = @"..\..\" + assembly;
                }

                return(Assembly.LoadFrom(assembly));
            };

            DbManager.TurnTraceSwitchOn();

            PostgreSQLSqlProvider.QuoteIdentifiers = true;

            var path = Path.GetDirectoryName(typeof(DbManager).Assembly.CodeBase.Replace("file:///", ""));

            foreach (var info in Providers)
            {
                try
                {
                    Type type;

                    if (info.Assembly == null)
                    {
                        type = typeof(DbManager).Assembly.GetType(info.Type, true);
                    }
                    else
                    {
#if FW4
                        var fileName = info.Assembly + ".4.dll";
#else
                        var fileName = info.Assembly + ".3.dll";
#endif

                        var assembly = Assembly.LoadFile(Path.Combine(path, fileName));

                        type = assembly.GetType(info.Type, true);
                    }

                    DbManager.AddDataProvider(type);

                    info.Loaded = true;
                }
                catch (Exception)
                {
                    info.Loaded = false;
                }
            }

            LinqService.TypeResolver = str =>
            {
                switch (str)
                {
                //case "Data.Linq.Model.Gender" : return typeof(Gender);
                case "Data.Linq.Model.Person": return(typeof(Person));

                case "Data.Linq.WhereTest+TestEnum": return(typeof(WhereTest.TestEnum));

                default: return(null);
                }
            };
        }
예제 #12
0
        static TestBase()
        {
            Console.WriteLine("Tests started in {0}...",
#if NETSTANDARD
                              System.IO.Directory.GetCurrentDirectory()
#else
                              Environment.CurrentDirectory
#endif
                              );

            var traceCount = 0;

            DataConnection.TurnTraceSwitchOn();
            DataConnection.WriteTraceLine = (s1, s2) =>
            {
                if (traceCount < 10000)
                {
                    Console.WriteLine("{0}: {1}", s2, s1);
                    Debug.WriteLine(s1, s2);
                }
#if MONO
                else
                {
                    Console.Write("z");
                }
#else
                if (traceCount++ > 10000)
                {
                    DataConnection.TurnTraceSwitchOn(TraceLevel.Off);
                }
#endif
            };

            //Configuration.RetryPolicy.Factory = db => new Retry();

            //Configuration.AvoidSpecificDataProviderAPI = true;
            //Configuration.Linq.GenerateExpressionTest = true;
            var assemblyPath = typeof(TestBase).AssemblyEx().GetPath();

            ProjectPath = FindProjectPath(assemblyPath);

#if !NETSTANDARD && !MONO
            SqlServerTypes.Utilities.LoadNativeAssemblies(assemblyPath);
#endif

#if NETSTANDARD
            System.IO.Directory.SetCurrentDirectory(assemblyPath);
#else
            Environment.CurrentDirectory = assemblyPath;
#endif
#if NETSTANDARD
            var userDataProviders    = Path.Combine(ProjectPath, @"UserDataProviders.Core.txt");
            var defaultDataProviders = Path.Combine(ProjectPath, @"DefaultDataProviders.Core.txt");
#else
            var userDataProviders    = Path.Combine(ProjectPath, @"UserDataProviders.txt");
            var defaultDataProviders = Path.Combine(ProjectPath, @"DefaultDataProviders.txt");
#endif

            var providerListFile =
                File.Exists(userDataProviders) ? userDataProviders : defaultDataProviders;

            var dataPath = Path.GetFullPath(@"Database\Data");

            if (Directory.Exists(dataPath))
            {
                Directory.Delete(dataPath, true);
            }

            Directory.CreateDirectory(dataPath);

            var databasePath = Path.GetFullPath(Path.Combine(@"Database"));

            foreach (var file in Directory.GetFiles(databasePath, "*.*"))
            {
                File.Copy(file, Path.Combine(dataPath, Path.GetFileName(file)), true);
            }

            UserProviders =
                File.ReadAllLines(providerListFile)
                .Select(s => s.Trim())
                .Where(s => s.Length > 0 && !s.StartsWith("--"))
                .Select(s =>
            {
                var isDefault = s.StartsWith("!");
                if (isDefault)
                {
                    s = s.Substring(1);
                }

                var ss = s.Split('*');
                switch (ss.Length)
                {
                case 0: return(null);

                case 1: return(new UserProviderInfo {
                        Name = ss[0].Trim(), ProviderName = ss[0], IsDefault = isDefault
                    });

                case 2: return(new UserProviderInfo {
                        Name = ss[0].Trim(), ConnectionString = ss[1].Trim(), ProviderName = ss[0], IsDefault = isDefault
                    });

                default: return(new UserProviderInfo {
                        Name = ss[0].Trim(), ConnectionString = ss[1].Trim(), ProviderName = ss[2].Trim(), IsDefault = isDefault
                    });
                }
            })
                .ToDictionary(i => i.Name);

            //var map = new ExeConfigurationFileMap();
            //map.ExeConfigFilename = Path.Combine(
            //	Path.GetDirectoryName(typeof(TestBase).Assembly.CodeBase.Substring("file:///".Length)),
            //	@"..\..\App.config");

            //var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

            //DataConnection.SetConnectionStrings(config);

#if NETSTANDARD
            DataConnection.DefaultSettings            = TxtSettings.Instance;
            TxtSettings.Instance.DefaultConfiguration = "SQLiteMs";

            foreach (var provider in UserProviders.Values)
            {
                if (string.IsNullOrWhiteSpace(provider.ConnectionString))
                {
                    throw new InvalidOperationException("ConnectionString should be provided");
                }

                if (string.IsNullOrWhiteSpace(provider.ProviderName))
                {
                    throw new InvalidOperationException("provider.ProviderName should be provided");
                }

                TxtSettings.Instance.AddConnectionString(provider.Name, provider.ProviderName, provider.ConnectionString);
            }
#else
            foreach (var provider in UserProviders.Values)
            {
                if (provider.ConnectionString != null)
                {
                    DataConnection.SetConnectionString(provider.Name, provider.ConnectionString);
                }
            }
#endif

            var defaultConfiguration = UserProviders.Where(_ => _.Value.IsDefault).Select(_ => _.Key).FirstOrDefault();
            if (!string.IsNullOrEmpty(defaultConfiguration))
            {
                DataConnection.DefaultConfiguration = defaultConfiguration;
#if NETSTANDARD
                TxtSettings.Instance.DefaultConfiguration = defaultConfiguration;
#endif
            }

            DataConnection.TurnTraceSwitchOn();

#if !NETSTANDARD
            LinqService.TypeResolver = str =>
            {
                switch (str)
                {
                case "Tests.Model.Gender": return(typeof(Gender));

                case "Tests.Model.Person": return(typeof(Person));

                default: return(null);
                }
            };
#endif
        }
예제 #13
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);

                    foreach (var parameters in GetParameters(provider))
                    {
                        var data = new TestCaseParameters(parameters);

                        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);

                        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)
                    {
                        foreach (var paremeters in GetParameters(provider + ".LinqService"))
                        {
                            var data = new TestCaseParameters(paremeters);
                            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);

                            yield return(test);
                        }
                    }
#endif
                }

                if (!hasTest)
                {
                    yield return(test);
                }
            }
예제 #14
0
            public IEnumerable <TestMethod> BuildFrom(IMethodInfo method, Test suite)
            {
                var tests = UserProviders.Contains(_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()),
#if !NPGSQL226
                    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))),
#endif
                    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.Contains(_providerName))
                    {
                        test.RunState = RunState.Ignored;
                        test.Properties.Set(PropertyNames.SkipReason, "Provider is disabled. See DataProviders.json");
                    }

                    yield return(test);
                }
            }
예제 #15
0
 public UserService()
 {
     objUserProviders = new UserProviders();
 }