Exemple #1
0
 public Manager()
 {
     _errorData = new StringBuilder();
     _managers  = new ConcurrentDictionary <DbAccessType, Func <IManagerImplementation> >();
     _managers.Add(DbAccessType.MsSql, () => new MsSqlManager());
     _managers.Add(DbAccessType.SqLite, () => new SqLiteManager());
     _managers.Add(DbAccessType.MySql, () => new MySqlManager());
     AllTestContextHelper.TestSetup(null);
 }
Exemple #2
0
        public DbAccessLayer GetWrapper(DbAccessType type, params object[] additionalArguments)
        {
            DbAccessLayer expectWrapper = null;

            _errorData.AppendLine("---------------------------------------------");
            _errorData.AppendLine("Found " + type);

            Assert.That(new DbConfig().SClassInfoCaches, Is.Empty, () => "The Global Class cache is not empty");
            var testClassName = TestContext.CurrentContext.Test.ClassName.Replace(typeof(Manager).Namespace, "")
                                .Where(e => char.IsUpper(e)).Select(e => e.ToString())
                                .Aggregate((e, f) => e + f) + "." +
                                TestContext.CurrentContext.Test.MethodName;

            testClassName = testClassName + "_" + Guid.NewGuid().ToString("N");
            testClassName = new Regex("[^a-zA-Z0-9]").Replace(testClassName, "_");
            _errorData.AppendLine($"Attach to Database: {testClassName}");

            expectWrapper = (_selectedMgr = _managers[type]()).GetWrapper(type, testClassName);
            expectWrapper.Config.EnableInstanceThreadSafety = true;


            expectWrapper.RaiseEvents      = true;
            expectWrapper.RaiseEventsAsync = false;
            expectWrapper.OnSelect        += (sender, eventArg) =>
            {
                _querys.Add(new KeyValuePair <string, string>("SELECT", eventArg.QueryDebugger.ToString()));
            };

            expectWrapper.OnDelete += (sender, eventArg) =>
            {
                _querys.Add(new KeyValuePair <string, string>("DELETE", eventArg.QueryDebugger.ToString()));
            };

            expectWrapper.OnInsert += (sender, eventArg) =>
            {
                _querys.Add(new KeyValuePair <string, string>("INSERT", eventArg.QueryDebugger.ToString()));
            };

            expectWrapper.OnUpdate += (sender, eventArg) =>
            {
                _querys.Add(new KeyValuePair <string, string>("UPDATE", eventArg.QueryDebugger.ToString()));
            };

            expectWrapper.OnNonResultQuery += (sender, eventArg) =>
            {
                _querys.Add(new KeyValuePair <string, string>("Query", eventArg.QueryDebugger.ToString()));
            };

            expectWrapper.OnFailedQuery += (sender, eventArg, exception) =>
            {
                _querys.Add(new KeyValuePair <string, string>("Query Failed", eventArg.QueryDebugger.ToString()));
            };

            Assert.NotNull(expectWrapper, "This test cannot run as no Database Variable is defined");
            var checkDatabase = expectWrapper.CheckDatabase();

            Assert.IsTrue(checkDatabase);
            AllTestContextHelper.TestSetup(expectWrapper.Config.ConstructorSettings);
            expectWrapper.Multipath = true;
            return(expectWrapper);
        }
Exemple #3
0
        public DbAccessLayer GetWrapper(DbAccessType type, params object[] additionalArguments)
        {
            DbAccessLayer expectWrapper = null;

            _errorData.AppendLine("---------------------------------------------");
            _errorData.AppendLine("Found " + type);

            Assert.That(new DbConfig().SClassInfoCaches, Is.Empty, () => "The Global Class cache is not empty");
            var testClassName = TestContext.CurrentContext.Test.ClassName.Replace(typeof(Manager).Namespace, "").Where(e => char.IsUpper(e)).Select(e => e.ToString())
                                .Aggregate((e, f) => e + f) + "." +
                                TestContext.CurrentContext.Test.MethodName;


            //var arguments =
            //		additionalArguments.Select(
            //		                           f =>
            //		                           {
            //			                           if (f == null)
            //			                           {
            //				                           return TestContext.CurrentContext.Random.NextShort().ToString();
            //			                           }

            //			                           if (typeof(string).Assembly.GetTypes().Contains(f.GetType()))
            //			                           {
            //				                           return f.ToString();
            //			                           }

            //			                           return f.GetHashCode().ToString();
            //		                           })
            //		                   .ToArray();

            //if (arguments.Any())
            //{
            //	testClassName =
            //}
            testClassName = testClassName + "_" + Guid.NewGuid().ToString("N");
            testClassName = new Regex("[^a-zA-Z0-9]").Replace(testClassName, "_");
            _errorData.AppendLine($"Attach to Database: {testClassName}");

            expectWrapper = (_selectedMgr = _managers[type]()).GetWrapper(type, testClassName);
            expectWrapper.Config.EnableInstanceThreadSafety = true;


            expectWrapper.RaiseEvents = true;
            expectWrapper.OnSelect   += (sender, eventArg) =>
            {
                _errorData.AppendFormat(@"SELECT: \r\n{0}", eventArg.QueryDebugger);
                _errorData.AppendLine();
            };

            expectWrapper.OnDelete += (sender, eventArg) =>
            {
                _errorData.AppendFormat(@"DELETE: \r\n{0}", eventArg.QueryDebugger);
                _errorData.AppendLine();
            };

            expectWrapper.OnInsert += (sender, eventArg) =>
            {
                _errorData.AppendFormat(@"INSERT: \r\n{0}", eventArg.QueryDebugger);
                _errorData.AppendLine();
            };

            expectWrapper.OnUpdate += (sender, eventArg) =>
            {
                _errorData.AppendFormat(@"UPDATE: \r\n{0}", eventArg.QueryDebugger);
                _errorData.AppendLine();
            };

            expectWrapper.OnFailedQuery += (sender, eventArg, exception) =>
            {
                _errorData.AppendFormat(@"Query Failed: \r\n{0}\r\n{1}", eventArg.QueryDebugger, exception);
                _errorData.AppendLine();
            };

            Assert.NotNull(expectWrapper, "This test cannot run as no Database Variable is defined");
            var checkDatabase = expectWrapper.CheckDatabase();

            Assert.IsTrue(checkDatabase);
            AllTestContextHelper.TestSetup(expectWrapper.Config.ConstructorSettings);
            expectWrapper.Multipath = true;
            return(expectWrapper);
        }