Example #1
0
        protected ITestDataContext GetDataContext(string configuration, MappingSchema ms = null)
        {
            if (configuration.EndsWith(".LinqService"))
            {
#if !NETSTANDARD1_6 && !NETSTANDARD2_0 && !MONO
                OpenHost();

                var str = configuration.Substring(0, configuration.Length - ".LinqService".Length);
                var dx  = new TestServiceModelDataContext(IP)
                {
                    Configuration = str
                };

                Debug.WriteLine(((IDataContext)dx).ContextID, "Provider ");

                if (ms != null)
                {
                    dx.MappingSchema = new MappingSchema(dx.MappingSchema, ms);
                }

                return(dx);
#else
                configuration = configuration.Substring(0, configuration.Length - ".LinqService".Length);
#endif
            }

            Debug.WriteLine(configuration, "Provider ");

            var res = new TestDataConnection(configuration);
            if (ms != null)
            {
                res.AddMappingSchema(ms);
            }
            return(res);
        }
Example #2
0
        public void Fts5CommandDelete([IncludeDataSources(TestProvName.AllSQLite)] string context)
        {
            using (var db = new TestDataConnection(context))
            {
                db.AddMappingSchema(SetupFtsMapping(SQLiteFTS.FTS5));

                try
                {
                    var record = new FtsTable()
                    {
                        text1 = "one",
                        text2 = "two"
                    };

                    db.FTS5Delete(db.GetTable <FtsTable>(), 2, record);
                }
                catch
                {
                    // we don't have FTS5 table, but we need to get sql for validation
                }
                finally
                {
                    Assert.AreEqual("INSERT INTO [FTS5_TABLE]([FTS5_TABLE], rowid, [text1], [text2]) VALUES('delete', 2, @p0, @p1)", db.LastQuery);
                    Assert.AreEqual(2, db.Command.Parameters.Count);
                    Assert.AreEqual("one", ((DbParameter)db.Command.Parameters[0]).Value);
                    Assert.AreEqual("two", ((DbParameter)db.Command.Parameters[1]).Value);
                }
            }
        }
Example #3
0
        public void Fts3CommandAutoMerge([IncludeDataSources(TestProvName.AllSQLite)] string context, [Values(SQLiteFTS.FTS3, SQLiteFTS.FTS4)] SQLiteFTS type)
        {
            using (var db = new TestDataConnection(context))
            {
                db.AddMappingSchema(SetupFtsMapping(type));

                db.FTS3AutoMerge(db.GetTable <FtsTable>(), 5);

                var tableName = type.ToString() + "_TABLE";

                Assert.AreEqual($"INSERT INTO [{tableName}]([{tableName}]) VALUES('automerge=5')", db.LastQuery);
            }
        }
Example #4
0
        public void BulkCopy2(string context)
        {
            foreach (var bulkCopyType in new[] { BulkCopyType.MultipleRows, BulkCopyType.ProviderSpecific })
            {
                using (var db = new TestDataConnection(context))
                {
                    db.Types2.Delete(_ => _.ID > 1000);

                    if (bulkCopyType == BulkCopyType.ProviderSpecific)
                    {
                        var ms = new MappingSchema();

                        db.AddMappingSchema(ms);

                        ms.GetFluentMappingBuilder()
                        .Entity <LinqDataTypes2>()
                        .Property(e => e.GuidValue)
                        .IsNotColumn()
                        ;
                    }

                    db.BulkCopy(
                        new BulkCopyOptions {
                        MaxBatchSize = 2, BulkCopyType = bulkCopyType
                    },
                        new[]
                    {
                        new LinqDataTypes2 {
                            ID = 1003, MoneyValue = 0m, DateTimeValue = null, BoolValue = true, GuidValue = new Guid("ef129165-6ffe-4df9-bb6b-bb16e413c883"), SmallIntValue = null, IntValue = null
                        },
                        new LinqDataTypes2 {
                            ID = 1004, MoneyValue = 0m, DateTimeValue = DateTime.Now, BoolValue = false, GuidValue = null, SmallIntValue = 2, IntValue = 1532334
                        },
                        new LinqDataTypes2 {
                            ID = 1005, MoneyValue = 1m, DateTimeValue = DateTime.Now, BoolValue = false, GuidValue = null, SmallIntValue = 5, IntValue = null
                        },
                        new LinqDataTypes2 {
                            ID = 1006, MoneyValue = 2m, DateTimeValue = DateTime.Now, BoolValue = false, GuidValue = null, SmallIntValue = 6, IntValue = 153
                        }
                    });

                    db.Types2.Delete(_ => _.ID > 1000);
                }
            }
        }
Example #5
0
        public void Fts5CommandUserMerge([IncludeDataSources(TestProvName.AllSQLite)] string context)
        {
            using (var db = new TestDataConnection(context))
            {
                db.AddMappingSchema(SetupFtsMapping(SQLiteFTS.FTS5));

                try
                {
                    db.FTS5UserMerge(db.GetTable <FtsTable>(), 7);
                }
                catch
                {
                    // we don't have FTS5 table, but we need to get sql for validation
                }
                finally
                {
                    Assert.AreEqual("INSERT INTO [FTS5_TABLE]([FTS5_TABLE], rank) VALUES('usermerge', 7)", db.LastQuery);
                }
            }
        }
Example #6
0
        public void Fts5CommandRank([IncludeDataSources(TestProvName.AllSQLite)] string context)
        {
            using (var db = new TestDataConnection(context))
            {
                db.AddMappingSchema(SetupFtsMapping(SQLiteFTS.FTS5));

                try
                {
                    db.FTS5Rank(db.GetTable <FtsTable>(), "strange('function\")");
                }
                catch
                {
                    // we don't have FTS5 table, but we need to get sql for validation
                }
                finally
                {
                    Assert.AreEqual("INSERT INTO [FTS5_TABLE]([FTS5_TABLE], rank) VALUES('rank', @rank)", db.LastQuery);
                    Assert.AreEqual(1, db.Command.Parameters.Count);
                    Assert.AreEqual("strange('function\")", ((DbParameter)db.Command.Parameters[0]).Value);
                }
            }
        }