Example #1
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
                            });
                        }
                    }
                }
            }
Example #2
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
        }