Exemplo n.º 1
0
        public virtual void Setup(string[] args)
        {
            this.provider = this.CreateProvider();
            this.provider.Connection.Open();

            if (args.Any(a => a == "-log"))
            {
                this.provider.Log = Console.Out;
            }

            this.executeQueries = this.ExecuteQueries();

            var    baseLineFilePath    = this.GetBaseLineFilePath();
            string newBaseLineFilePath = baseLineFilePath != null ? baseLineFilePath + ".new" : null;

            if (!string.IsNullOrEmpty(baseLineFilePath))
            {
                this.ReadBaselines(baseLineFilePath);
            }

            if (!string.IsNullOrEmpty(newBaseLineFilePath))
            {
                baselineWriter             = new XmlTextWriter(newBaseLineFilePath, Encoding.UTF8);
                baselineWriter.Formatting  = Formatting.Indented;
                baselineWriter.Indentation = 2;
                baselineWriter.WriteStartDocument();
                baselineWriter.WriteStartElement("baselines");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var provider = DbEntityProvider.From(@"c:\data\Northwind.mdf", "Test.NorthwindWithAttributes");

            //var provider = DbEntityProvider.From(@"c:\data\Northwind.accdb", "Test.NorthwindWithAttributes");
            //var provider = DbEntityProvider.From(@"c:\data\Northwind.mdb", "Test.NorthwindWithAttributes");
            //var provider = DbEntityProvider.From(@"c:\data\Northwind.sdf", "Test.NorthwindWithAttributes");
            //var provider = DbEntityProvider.From("IQToolkit.Data.MySqlClient", "Northwind", "Test.MySqlNorthwind");
            //var provider = DbEntityProvider.From("IQToolkit.Data.SQLite", @"c:\data\Northwind.db3", "Test.NorthwindWithAttributes");

            //provider.Log = Console.Out;
            provider.Connection.Open();
            //provider.Cache = new QueryCache(5);

            try
            {
                var db = new Northwind(provider);

                //NorthwindTranslationTests.Run(db, true);
                NorthwindExecutionTests.Run(db);
                //NorthwindCUDTests.Run(db);
                //MultiTableTests.Run(new MultiTableContext(provider.New(new AttributeMapping(typeof(MultiTableContext)))));
                //NorthwindPerfTests.Run(db, "TestStandardQuery");
            }
            finally
            {
                provider.Connection.Close();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the primary key if the Entity has only one column for the primary key.  The assumption is that composite
        /// primary keys don't need to be retrieved after executing the Insert statement.
        /// </summary>
        /// <param name="provider">DbEntityProvider instance.</param>
        /// <returns>Returns the PrimaryKey PropertyInfo.</returns>
        private PropertyInfo GetPrimaryKey(DbEntityProvider provider)
        {
            MemberInfo primaryKeyMemberInfo = provider.Mapping
                                              .GetPrimaryKeyMembers(this.mappingEntity)
                                              .SingleOrDefault();

            return(primaryKeyMemberInfo as PropertyInfo);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Db connection init.
 /// </summary>
 /// <param name="provider">The provider.</param>
 private static void DbInit(DbEntityProvider provider)
 {
     if (dbInit == false)
     {
         dbInit = true;
         provider.Connection.Open();
     }
 }
        /// <summary>
        /// Insert Data Object
        /// </summary>
        /// <param name="dataContext">Data Context</param>
        /// <param name="table">Data Table</param>
        /// <param name="newDataObject">New Data Object</param>
        protected override void InsertDataObject(object dataContext, object table, object newDataObject)
        {
            if (newDataObject is IValidate)
            {
                ((IValidate)newDataObject).Validate();
            }

            if (this.owner.RetrieveGeneratedId)
            {
                // look for the Provider property
                PropertyInfo pi = dataContext.GetType().GetProperties().Where(p => p.PropertyType.IsSubclassOf(typeof(DbEntityProvider))).FirstOrDefault();

                if (pi != null)
                {
                    // cast the Provider
                    DbEntityProvider provider = (DbEntityProvider)pi.GetValue(dataContext);

                    // get the Mapping for the Provider
                    BasicMapping mapping = (BasicMapping)provider.Mapping;

                    // get the Mapping Entity for the data object
                    MappingEntity mappingEntity = mapping.GetEntity(newDataObject.GetType());

                    // get the primary key MemberInfo
                    MemberInfo primaryKeyMemberInfo = mapping.GetMappedMembers(mappingEntity).Where(m => mapping.IsPrimaryKey(mappingEntity, m)).Single();

                    // verify that the primary key is generated by calling the protected method IsGenerated
                    MethodBase isGeneratedMethod = mapping.GetType().GetMethod("IsGenerated", BindingFlags.NonPublic | BindingFlags.Instance);
                    bool       isGeneratedId     = (bool)isGeneratedMethod.Invoke(mapping, new object[] { mappingEntity, primaryKeyMemberInfo });

                    if (isGeneratedId)
                    {
                        // create a type array for the generic types for the Insert<T, S> method
                        Type[] genericTypes = new Type[] { newDataObject.GetType(), typeof(int) };

                        // create type for Expression<Func<T, S>>
                        Type functionExpressionType = Expression.GetFuncType(genericTypes);

                        // create a Expression Parameter for the data object type
                        var p1 = Expression.Parameter(newDataObject.GetType(), "instance");

                        // create a Lambda Expression for the Func<T, S> call ... expression example:  d => d.ID
                        LambdaExpression expression = Expression.Lambda(functionExpressionType, Expression.Property(p1, primaryKeyMemberInfo.Name), p1);

                        // MethodInfo for: public static S Insert<T, S>(this IUpdatable<T> collection, T instance, Expression<Func<T, S>> resultSelector)
                        MethodInfo mi = typeof(IQToolkit.Updatable).GetMethods().Where(d => d.Name == "Insert" && d.IsGenericMethod && d.ReturnType.FullName == null).First();
                        mi = mi.MakeGenericMethod(genericTypes);
                        object id = mi.Invoke(null, new object[] { table, newDataObject, expression });

                        // set the newDataObject's primary key property
                        newDataObject.GetType().GetProperty(primaryKeyMemberInfo.Name).SetValue(newDataObject, (int)id);
                        return;
                    }
                }
            }

            ((IEntityTable)table).Insert(newDataObject);
        }
        public DbEntityContextBase(DbEntityProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            this.provider = provider;
        }
        public DbEntitySessionBase(DbEntityProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            this.provider = provider;
            this.session  = new EntitySession(provider);
        }
Exemplo n.º 8
0
        protected DbEntityInserterBase(IEntityTable <T> entityTable, DbEntityProvider provider)
        {
            if (entityTable == null)
            {
                throw new ArgumentNullException("entityTable");
            }

            this.entityTable = entityTable;

            if (provider != null)
            {
                this.mappingEntity = provider.Mapping.GetEntity(this.entityType);
                this.primaryKey    = this.GetPrimaryKey(provider);
            }

            this.func = this.GetFunction();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates the repository. Init the provider and establish
        /// a database connection
        /// </summary>
        /// <returns></returns>
        private static DbEntityRepository CreateRepository()
        {
            DbEntityProvider dbentprovider;

            string connectionString = ConfigurationManager.AppSettings["ConnORA"];
            string MapPath          = Utils.GetMapPath("MapORA");
            string provider         = ConfigurationManager.AppSettings["ProviderORA"];

            var mapping = XmlMapping.FromXml(File.ReadAllText(MapPath));

            dbentprovider = DbEntityProvider.From(provider, connectionString, mapping, QueryPolicy.Default);

            //May not be needed for all databases,
            //some need a little kick start before serving requests
            DbInit(dbentprovider);

            return(new DbEntityRepository(dbentprovider));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DSPIQUpdateProvider"/> class.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="metadata">The metadata.</param>
        /// <param name="session">The session.</param>
        public DSPIQUpdateProvider(DbEntityProvider provider, DSPMetadata metadata, IEntitySession session)
        {
            if (provider == null)
            {
                throw new ArgumentException("The specified provider is null.");
            }
            if (metadata == null)
            {
                throw new ArgumentException("The specified metadata is null.");
            }
            if (session == null)
            {
                throw new ArgumentException("The specified session is null.");
            }


            this.metadata       = metadata;
            this.provider       = provider;
            this.session        = session;
            this.pendingChanges = new List <Action>();
        }
Exemplo n.º 11
0
 public QueryGlobal(string constrName)//, bool isWeb = false
 {
     if (!_dic.ContainsKey(constrName))
     {
         //isWeb ? WebConfigurationManager.ConnectionStrings[constrName].ConnectionString :
         //似乎在web程序中使用ConfigurationManager也能读到连接字符串
         var connectionString = ConfigurationManager.ConnectionStrings[constrName].ConnectionString;
         connectionString = this.DecryptConnectionString(connectionString);//new DESCrypt().DecryptDES(connectionString);
         QueryProvider    = DbEntityProvider.From(QueryProviderStr, connectionString);
         LinqOP           = new LinqOPEncap(QueryProvider);
         DB = new SqlDatabase(connectionString);
         _dic.Add(constrName, this);
     }
     else
     {
         var cache = _dic[constrName];
         QueryProvider = cache.QueryProvider;
         LinqOP        = cache.LinqOP;
         DB            = cache.DB;
     }
 }
Exemplo n.º 12
0
 public DbEntityRepository(DbEntityProvider provider)
 {
     this.Provider = provider;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DSPIQUpdateProvider"/> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="metadata">The metadata.</param>
 public DSPIQUpdateProvider(DbEntityProvider provider, DSPMetadata metadata) :
     this(provider, metadata, new EntitySession(provider))
 {
 }
Exemplo n.º 14
0
        protected void TestQuery(DbEntityProvider pro, Expression query, bool expectedToFail)
        {
            if (this.baselines == null) {
                XDocument doc = XDocument.Parse(Properties.Resources.NorthwindTranslationXml);
                this.baselines = doc.Root.Elements("baseline").ToDictionary(e => (string)e.Attribute("key"), e => e.Value);
            }

            if (query.NodeType == ExpressionType.Convert && query.Type == typeof(object)) {
                query = ((UnaryExpression)query).Operand; // remove box
            }

            string queryText = null;

            queryText = pro.GetQueryText(query);

            Exception caught = null;
            try {
                object result = pro.Execute(query);
                IEnumerable seq = result as IEnumerable;
                if (seq != null) {
                    // iterate results
                    foreach (var item in seq) {
                    }
                }
                else {
                    IDisposable disposable = result as IDisposable;
                    if (disposable != null)
                        disposable.Dispose();
                }
            }
            catch (Exception e) {
                caught = e;
                if (!expectedToFail) {
                    throw;
                }
            }

            if (caught == null && expectedToFail) {
                throw new Exception("Table succeeded when expected to fail");
            }

            string baseline = null;
            if (this.baselines != null && this.baselines.TryGetValue(this.TestContext.TestName, out baseline)) {
                string trimAct = TrimExtraWhiteSpace(queryText).Trim();
                string trimBase = TrimExtraWhiteSpace(baseline).Trim();

                if (trimAct != trimBase) {
                    this.TestContext.WriteLine("Table translation does not match baseline:");
                    this.TestContext.WriteLine(queryText);
                    this.TestContext.WriteLine("---- current ----");
                    this.TestContext.WriteLine(trimAct);
                    this.TestContext.WriteLine("---- baseline ----");
                    this.TestContext.WriteLine(trimBase);
                    throw new Exception("Translation differed from baseline.");
                }
            }

            if (baseline == null && this.baselines != null) {
                throw new Exception("No baseline");
            }
        }
Exemplo n.º 15
0
 public IQToolkitTestModel(DbEntityProvider provider)
 {
     this.provider = provider;
 }
Exemplo n.º 16
0
 protected void RunTests(DbEntityProvider provider, string baselineFile, string newBaselineFile, bool executeQueries)
 {
     this.RunTests(provider, baselineFile, newBaselineFile, executeQueries, this.GetType().GetMethods().Where(m => m.Name.StartsWith("Test")).ToArray());
 }
 public DbEntitySessionRepository(DbEntityProvider provider)
     : base(provider)
 {
     this.Session = new EntitySession(provider);
 }
Exemplo n.º 18
0
 public lineorder_flat_collection(DbEntityProvider provider)
 {
     this.provider = provider;
 }
 public NorthwindSessionFix(DbEntityProvider provider)
     : base(provider)
 {
 }
Exemplo n.º 20
0
 public Executor(DbEntityProvider provider)
 {
     this.provider = provider;
 }
Exemplo n.º 21
0
 private static DbEntityProvider CreateNorthwindProvider()
 {
     return(DbEntityProvider.From(@"Northwind.mdb", "Test.NorthwindWithAttributes"));
 }
 public DbEntityInserter(IEntityTable <T> entityTable, DbEntityProvider provider)
     : base(entityTable, provider)
 {
 }
Exemplo n.º 23
0
 private static DbEntityProvider CreateNorthwindProvider()
 {
     return(DbEntityProvider.From("IQToolkit.Data.MySqlClient", "Server=localhost;user id='root';password='******';Database=Northwind", "Test.NorthwindWithAttributes"));
 }
Exemplo n.º 24
0
 private static DbEntityProvider CreateNorthwindProvider(string mapping = "Test.NorthwindWithAttributes")
 {
     return(DbEntityProvider.From(@"Northwind40.sdf", mapping));
 }
 public ADataServiceContext(DbEntityProvider provider)
 {
     this.provider = provider;
     this.session  = new EntitySession(provider);
 }
Exemplo n.º 26
0
 protected void RunTest(DbEntityProvider provider, string baselineFile, bool executeQueries, string testName)
 {
     this.RunTests(provider, baselineFile, null, executeQueries,
                   new MethodInfo[] { this.GetType().GetMethod(testName) }
                   );
 }
Exemplo n.º 27
0
 public DSPRestrictedUpdateProvider(DbEntityProvider provider, DSPMetadata metadata)
     : base(provider, metadata, new EntitySessionEx(provider))
 {
 }
Exemplo n.º 28
0
 protected void RunTests(DbEntityProvider provider, string baselineFile, string newBaselineFile, bool executeQueries)
 {
     this.RunTests(provider, baselineFile, newBaselineFile, executeQueries, this.GetType().GetMethods().Where(m => m.Name.StartsWith("Test")).ToArray());
 }
Exemplo n.º 29
0
 protected void RunTest(DbEntityProvider provider, string baselineFile, bool executeQueries, string testName)
 {
     this.RunTests(provider, baselineFile, null, executeQueries,
         new MethodInfo[] { this.GetType().GetMethod(testName) }
         );
 }
Exemplo n.º 30
0
        protected void RunTests(DbEntityProvider provider, string baselineFile, string newBaselineFile, bool executeQueries, MethodInfo[] tests)
        {
            this.provider       = provider;
            this.executeQueries = executeQueries;

            ReadBaselines(baselineFile);

            if (!string.IsNullOrEmpty(newBaselineFile))
            {
                baselineWriter             = new XmlTextWriter(newBaselineFile, Encoding.UTF8);
                baselineWriter.Formatting  = Formatting.Indented;
                baselineWriter.Indentation = 2;
                baselineWriter.WriteStartDocument();
                baselineWriter.WriteStartElement("baselines");
            }

            int          iTest         = 0;
            int          iPassed       = 0;
            var          failures      = new List <TestFailure>();
            ConsoleColor originalColor = Console.ForegroundColor;

            if (WriteOutput)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Running tests: {0}", this.GetType().Name);
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            var timer = new System.Diagnostics.Stopwatch();

            timer.Start();

            try
            {
                foreach (MethodInfo method in tests.Where(m => m != null && TestIsEnabled(m)))
                {
                    iTest++;
                    currentMethod = method;
                    string testName = method.Name.Substring(4);
                    bool   passed   = false;
                    if (WriteOutput)
                    {
                        Console.WriteLine();
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    SetupTest();
                    string reason = "";
                    try
                    {
                        Console.ForegroundColor = ConsoleColor.Gray;
                        TestMethod test = (TestMethod)Delegate.CreateDelegate(typeof(TestMethod), this, method);
                        test();
                        if (testName.EndsWith("Fails"))
                        {
                            passed = false;
                            reason = "Expected failure";
                        }
                        else
                        {
                            passed = true;
                            iPassed++;
                        }
                    }
                    catch (Exception tf)//(TestFailureException tf)
                    {
                        if (testName.EndsWith("Fails"))
                        {
                            passed = true;
                            iPassed++;
                        }
                        else if (tf.Message != null)
                        {
                            reason = tf.Message;
                        }
                    }
                    finally
                    {
                        TeardownTest();
                    }

                    if (!passed)
                    {
                        failures.Add(new TestFailure {
                            TestName = method.Name, Reason = reason
                        });
                    }

                    if (WriteOutput)
                    {
                        Console.ForegroundColor = passed ? ConsoleColor.Green : ConsoleColor.Red;
                        Console.WriteLine("Test {0}: {1} - {2}", iTest, method.Name, passed ? "PASSED" : "FAILED");
                        if (!passed && !string.IsNullOrEmpty(reason))
                        {
                            Console.WriteLine("Reason: {0}", reason);
                        }
                    }
                }
            }
            finally
            {
                if (baselineWriter != null)
                {
                    baselineWriter.WriteEndElement();
                    baselineWriter.Close();
                }
            }

            timer.Stop();

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("SUMMARY: {0}", this.GetType().Name);
            Console.WriteLine("Total tests run: {0}", iTest);
            Console.WriteLine("Total elapsed time: {0}", timer.Elapsed);

            Console.ForegroundColor = ConsoleColor.Green;
            if (iPassed == iTest)
            {
                Console.WriteLine("ALL tests passed!");
            }
            else
            {
                Console.WriteLine("Total tests passed: {0}", iPassed);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Total tests failed: {0}", iTest - iPassed);
                foreach (var failure in failures)
                {
                    Console.WriteLine("  {0}: {1}", failure.TestName, failure.Reason != null ? failure.Reason : string.Empty);
                }
            }
            Console.ForegroundColor = originalColor;
            Console.WriteLine();
        }
Exemplo n.º 31
0
        protected void RunTests(DbEntityProvider provider, string baselineFile, string newBaselineFile, bool executeQueries, MethodInfo[] tests)
        {
            this.provider = provider;
            this.executeQueries = executeQueries;

            ReadBaselines(baselineFile);

            if (!string.IsNullOrEmpty(newBaselineFile))
            {
                baselineWriter = new XmlTextWriter(newBaselineFile, Encoding.UTF8);
                baselineWriter.Formatting = Formatting.Indented;
                baselineWriter.Indentation = 2;
                baselineWriter.WriteStartDocument();
                baselineWriter.WriteStartElement("baselines");
            }

            int iTest = 0;
            int iPassed = 0;
            var failures = new List<TestFailure>();
            ConsoleColor originalColor = Console.ForegroundColor;
            if (WriteOutput)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Running tests: {0}", this.GetType().Name);
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            var timer = new System.Diagnostics.Stopwatch();
            timer.Start();

            try
            {
                foreach (MethodInfo method in tests.Where(m => m != null && TestIsEnabled(m)))
                {
                    iTest++;
                    currentMethod = method;
                    string testName = method.Name.Substring(4);
                    bool passed = false;
                    if (WriteOutput)
                    {
                        Console.WriteLine();
                        Console.ForegroundColor = ConsoleColor.Gray;
                    }
                    SetupTest();
                    string reason = "";
                    try
                    {
                        Console.ForegroundColor = ConsoleColor.Gray;
                        TestMethod test = (TestMethod)Delegate.CreateDelegate(typeof(TestMethod), this, method);
                        test();
                        if (testName.EndsWith("Fails"))
                        {
                            passed = false;
                            reason = "Expected failure";
                        }
                        else
                        {
                            passed = true;
                            iPassed++;
                        }
                    }
                    catch (Exception tf)//(TestFailureException tf)
                    {
                        if (testName.EndsWith("Fails"))
                        {
                            passed = true;
                            iPassed++;
                        }
                        else if (tf.Message != null)
                        {
                            reason = tf.Message;
                        }
                    }
                    finally
                    {
                        TeardownTest();
                    }

                    if (!passed)
                    {
                        failures.Add(new TestFailure { TestName = method.Name, Reason = reason });
                    }

                    if (WriteOutput)
                    {
                        Console.ForegroundColor = passed ? ConsoleColor.Green : ConsoleColor.Red;
                        Console.WriteLine("Test {0}: {1} - {2}", iTest, method.Name, passed ? "PASSED" : "FAILED");
                        if (!passed && !string.IsNullOrEmpty(reason))
                            Console.WriteLine("Reason: {0}", reason);
                    }
                }
            }
            finally
            {
                if (baselineWriter != null)
                {
                    baselineWriter.WriteEndElement();
                    baselineWriter.Close();
                }
            }

            timer.Stop();

            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("SUMMARY: {0}", this.GetType().Name);
            Console.WriteLine("Total tests run: {0}", iTest);
            Console.WriteLine("Total elapsed time: {0}", timer.Elapsed);

            Console.ForegroundColor = ConsoleColor.Green;
            if (iPassed == iTest)
            {
                Console.WriteLine("ALL tests passed!");
            }
            else
            {
                Console.WriteLine("Total tests passed: {0}", iPassed);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Total tests failed: {0}", iTest - iPassed);
                foreach (var failure in failures)
                {
                    Console.WriteLine("  {0}: {1}", failure.TestName, failure.Reason != null ? failure.Reason : string.Empty);
                }
            }
            Console.ForegroundColor = originalColor;
            Console.WriteLine();
        }
Exemplo n.º 32
0
        protected void TestQuery(DbEntityProvider pro, Expression query, bool expectedToFail)
        {
            if (this.baselines == null)
            {
                XDocument doc = XDocument.Parse(Properties.Resources.NorthwindTranslationXml);
                this.baselines = doc.Root.Elements("baseline").ToDictionary(e => (string)e.Attribute("key"), e => e.Value);
            }

            if (query.NodeType == ExpressionType.Convert && query.Type == typeof(object))
            {
                query = ((UnaryExpression)query).Operand; // remove box
            }

            string queryText = null;

            queryText = pro.GetQueryText(query);

            Exception caught = null;

            try {
                object      result = pro.Execute(query);
                IEnumerable seq    = result as IEnumerable;
                if (seq != null)
                {
                    // iterate results
                    foreach (var item in seq)
                    {
                    }
                }
                else
                {
                    IDisposable disposable = result as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            catch (Exception e) {
                caught = e;
                if (!expectedToFail)
                {
                    throw;
                }
            }

            if (caught == null && expectedToFail)
            {
                throw new Exception("Table succeeded when expected to fail");
            }


            string baseline = null;

            if (this.baselines != null && this.baselines.TryGetValue(this.TestContext.TestName, out baseline))
            {
                string trimAct  = TrimExtraWhiteSpace(queryText).Trim();
                string trimBase = TrimExtraWhiteSpace(baseline).Trim();

                if (trimAct != trimBase)
                {
                    this.TestContext.WriteLine("Table translation does not match baseline:");
                    this.TestContext.WriteLine(queryText);
                    this.TestContext.WriteLine("---- current ----");
                    this.TestContext.WriteLine(trimAct);
                    this.TestContext.WriteLine("---- baseline ----");
                    this.TestContext.WriteLine(trimBase);
                    throw new Exception("Translation differed from baseline.");
                }
            }

            if (baseline == null && this.baselines != null)
            {
                throw new Exception("No baseline");
            }
        }
Exemplo n.º 33
0
        public virtual void Setup(string[] args)
        {
            this.provider = this.CreateProvider();
            this.provider.Connection.Open();

            if (args.Any(a => a == "-log"))
            {
                this.provider.Log = Console.Out;
            }

            this.executeQueries = this.ExecuteQueries();

            var baseLineFilePath = this.GetBaseLineFilePath();
            string newBaseLineFilePath = baseLineFilePath != null ? baseLineFilePath + ".new" : null;

            if (!string.IsNullOrEmpty(baseLineFilePath))
            {
                this.ReadBaselines(baseLineFilePath);
            }

            if (!string.IsNullOrEmpty(newBaseLineFilePath))
            {
                baselineWriter = new XmlTextWriter(newBaseLineFilePath, Encoding.UTF8);
                baselineWriter.Formatting = Formatting.Indented;
                baselineWriter.Indentation = 2;
                baselineWriter.WriteStartDocument();
                baselineWriter.WriteStartElement("baselines");
            }
        }
Exemplo n.º 34
0
 private static DbEntityProvider CreateNorthwindProvider()
 {
     return(DbEntityProvider.From("IQToolkit.Data.SQLite", @"Northwind.db3", "Test.NorthwindWithAttributes"));
 }
Exemplo n.º 35
0
        private static bool RunTest(DbEntityProvider provider, string selection)
        {
            if (selection.Equals("q", StringComparison.OrdinalIgnoreCase))
                return false;

            if (selection.StartsWith("log", StringComparison.OrdinalIgnoreCase))
            {
                if (selection.Equals("log on", StringComparison.OrdinalIgnoreCase))
                {
                    logEnabled = true;
                }
                else if (selection.Equals("log off", StringComparison.OrdinalIgnoreCase))
                {
                    logEnabled = false;
                }

                Console.WriteLine(String.Format("Log is {0}.", logEnabled ? "On" : "Off"));
                return true;
            }

            if(logEnabled)
                provider.Log = Console.Out;
            else
                provider.Log = null;

            provider.Connection.Open();
            //provider.Cache = new QueryCache(5);
            try
            {
                var db = new Northwind(provider);

                if (selection.Contains("0") || selection.Contains("1"))
                    NorthwindTranslationTests.Run(db, true);
                if (selection.Contains("0") || selection.Contains("2"))
                    NorthwindExecutionTests.Run(db);
                if (selection.Contains("0") || selection.Contains("3"))
                    NorthwindCUDTests.Run(db);
                if (selection.Contains("0") || selection.Contains("4"))
                    MultiTableTests.Run(new MultiTableContext(provider.New(new AttributeMapping(typeof(MultiTableContext)))));
                if (selection.Contains("0") || selection.Contains("5"))
                    NorthwindPerfTests.Run(db, "TestStandardQuery");
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                provider.Connection.Close();
            }

            return true;
        }
Exemplo n.º 36
0
        private static bool RunTest(string selection)
        {
            if (selection.Equals("q", StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (selection.Equals("s", StringComparison.OrdinalIgnoreCase))
            {
                if (adoProviderName == "IQToolkit.Data.OracleClient")
                {
                    adoProviderName = "IQToolkit.Data.ODP";
                }
                else
                {
                    adoProviderName = "IQToolkit.Data.OracleClient";
                }
                return(true);
            }

            string connectionStringName = "Oracle";
            string providerName         = ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName;
            string connectionString     = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;

            var provider = DbEntityProvider.From(adoProviderName, connectionString, "Test.NorthwindWithAttributes");


            if (selection.StartsWith("log", StringComparison.OrdinalIgnoreCase))
            {
                if (selection.Equals("log on", StringComparison.OrdinalIgnoreCase))
                {
                    logEnabled = true;
                }
                else if (selection.Equals("log off", StringComparison.OrdinalIgnoreCase))
                {
                    logEnabled = false;
                }

                Console.WriteLine(String.Format("Log is {0}.", logEnabled ? "On" : "Off"));
                return(true);
            }

            if (logEnabled)
            {
                provider.Log = Console.Out;
            }
            else
            {
                provider.Log = null;
            }

            provider.Connection.Open();
            //provider.Cache = new QueryCache(5);
            try
            {
                var db = new Northwind(provider);

                if (selection.Contains("0") || selection.Contains("1"))
                {
                    NorthwindTranslationTests.Run(db, true);
                }
                if (selection.Contains("0") || selection.Contains("2"))
                {
                    NorthwindExecutionTests.Run(db);
                }
                if (selection.Contains("0") || selection.Contains("3"))
                {
                    NorthwindCUDTests.Run(db);
                }
                if (selection.Contains("0") || selection.Contains("4"))
                {
                    MultiTableTests.Run(new MultiTableContext(provider.New(new AttributeMapping(typeof(MultiTableContext)))));
                }
                if (selection.Contains("0") || selection.Contains("5"))
                {
                    NorthwindPerfTests.Run(db, "TestStandardQuery");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
            }
            finally
            {
                provider.Connection.Close();
            }

            return(true);
        }