예제 #1
0
        public void CreateBackup()
        {
            var obj1 = new BackupTestObj
            {
                Text = "GLaDOS loves testing!"
            };
            var obj2 = new BackupTestObj2
            {
                Text = "Keep testing, just keep testing"
            };

            SQLiteConnection srcDb = new BackupTestDb(TestPath.CreateTemporaryDatabase());

            int numIn1 = srcDb.Insert(obj1);

            Assert.AreEqual(1, numIn1);
            int numIn2 = srcDb.Insert(obj2);

            Assert.AreEqual(1, numIn2);

            const int numInserts = 1000;
            int       inserts    = 0;

            for (int i = 0; i < numInserts; i++)
            {
                inserts += srcDb.Insert(new BackupTestObj3());
            }
            Assert.AreEqual(numInserts, inserts);

            List <BackupTestObj> result1 = srcDb.Query <BackupTestObj>("select * from BackupTestObj").ToList();

            Assert.AreEqual(numIn1, result1.Count);
            Assert.AreEqual(obj1.Text, result1.First().Text);

            List <BackupTestObj> result2 = srcDb.Query <BackupTestObj>("select * from BackupTestObj2").ToList();

            Assert.AreEqual(numIn2, result2.Count);
            Assert.AreEqual(obj2.Text, result2.First().Text);

            string destDbPath = srcDb.CreateDatabaseBackup(new SQLitePlatformTest());
//            Assert.IsTrue(File.Exists(destDbPath));

            SQLiteConnection destDb = new BackupTestDb(destDbPath);

            result1 = destDb.Query <BackupTestObj>("select * from BackupTestObj").ToList();
            Assert.AreEqual(numIn1, result1.Count);
            Assert.AreEqual(obj1.Text, result1.First().Text);

            result2 = destDb.Query <BackupTestObj>("select * from BackupTestObj2").ToList();
            Assert.AreEqual(numIn2, result2.Count);
            Assert.AreEqual(obj2.Text, result2.First().Text);

            int count = destDb.ExecuteScalar <int>("select count(*) from BackupTestObj3");

            Assert.AreEqual(numInserts, count);

            srcDb.Close();
            destDb.Close();
        }
예제 #2
0
        public void AsyncAsTicks()
        {
            var sqLiteConnectionPool   = new SQLiteConnectionPool(new SQLitePlatformWin32());
            var sqLiteConnectionString = new SQLiteConnectionString(TestPath.GetTempFileName(), true);
            var db = new SQLiteAsyncConnection(() => sqLiteConnectionPool.GetConnection(sqLiteConnectionString));

            TestAsyncDateTime(db);
        }
예제 #3
0
        public async Task AsyncAsString()
        {
            var sqLiteConnectionPool   = new SQLiteConnectionPool(new SQLitePlatformTest());
            var sqLiteConnectionString = new SQLiteConnectionString(TestPath.GetTempFileName(), false);
            var db = new SQLiteAsyncConnection(() => sqLiteConnectionPool.GetConnection(sqLiteConnectionString));

            await TestAsyncDateTime(db, sqLiteConnectionString.StoreDateTimeAsTicks);
        }
예제 #4
0
        public async Task TestTimeSpan()
        {
            var sqLiteConnectionPool   = new SQLiteConnectionPool(new SQLitePlatformTest());
            var sqLiteConnectionString = new SQLiteConnectionString(TestPath.GetTempFileName(), true);
            var db = new SQLiteAsyncConnection(() => sqLiteConnectionPool.GetConnection(sqLiteConnectionString));

            await TestAsyncDateTime(db);
        }
예제 #5
0
 public TestDb(bool storeDateTimeAsTicks = true, IContractResolver resolver = null)
     : base(
         new SQLitePlatformTest(), TestPath.GetTempFileName(), storeDateTimeAsTicks, null,
         extraTypeMappings: null,
         resolver: resolver)
 {
     TraceListener = DebugTraceListener.Instance;
 }
예제 #6
0
        public void CustomIgnoreAttributeTest()
        {
            var db = new SQLiteConnection(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase());

            db.ColumnInformationProvider = new TestColumnInformationProvider();
            // if the Ignored property is not ignore this will cause an exception
            db.CreateTable <TestObjIntWithIgnore>();
            db.ColumnInformationProvider = null;
        }
예제 #7
0
        public async Task UnicodePathsAsync()
        {
            var fileName = TestPath.CreateDefaultTempFilename() + UnicodeText + ".db";
            var filePath = TestPath.CreateTemporaryDatabase(fileName);

            var db = new SQLiteAsyncConnection(() => new SQLiteConnectionWithLock(new SQLitePlatformTest(), new SQLiteConnectionString(filePath, true)));
            await db.CreateTableAsync <OrderLine>();

            Assert.That(filePath.Length, Is.GreaterThan(0), fileName);
        }
예제 #8
0
        public void ByteArrays()
        {
            //Byte Arrays for comparisson
            ByteArrayClass[] byteArrays =
            {
                new ByteArrayClass
                {
                    bytes = new byte[]{                        1, 2, 3, 4, 250, 252, 253, 254, 255 }
                }, //Range check
                new ByteArrayClass
                {
                    bytes = new byte[]{ 0 }
                }, //null bytes need to be handled correctly
                new ByteArrayClass
                {
                    bytes = new byte[]{                        0, 0 }
                },
                new ByteArrayClass
                {
                    bytes = new byte[]{                        0, 1, 0 }
                },
                new ByteArrayClass
                {
                    bytes = new byte[]{                        1, 0, 1 }
                },
                new ByteArrayClass
                {
                    bytes = new byte[]{}
                }, //Empty byte array should stay empty (and not become null)
                new ByteArrayClass
                {
                    bytes = null
                } //Null should be supported
            };

            var database = new SQLiteConnection(_sqlite3Platform, TestPath.GetTempFileName());

            database.CreateTable <ByteArrayClass>();

            //Insert all of the ByteArrayClass
            foreach (ByteArrayClass b in byteArrays)
            {
                database.Insert(b);
            }

            //Get them back out
            ByteArrayClass[] fetchedByteArrays = database.Table <ByteArrayClass>().OrderBy(x => x.ID).ToArray();

            Assert.AreEqual(fetchedByteArrays.Length, byteArrays.Length);
            //Check they are the same
            for (int i = 0; i < byteArrays.Length; i++)
            {
                byteArrays[i].AssertEquals(fetchedByteArrays[i]);
            }
        }
예제 #9
0
        public void UnicodePaths()
        {
            var fileName = TestPath.CreateDefaultTempFilename() + UnicodeText + ".db";
            var filePath = TestPath.CreateTemporaryDatabase(fileName);

            using (var db = new SQLiteConnection(new SQLitePlatformTest(), filePath, true))
            {
                db.CreateTable <OrderLine>();
            }

            Assert.That(filePath.Length, Is.GreaterThan(0), fileName);
        }
예제 #10
0
        public void TestCustomDefaultColumnValues()
        {
            using (var db = new TestDbWithCustomAttributes(TestPath.CreateTemporaryDatabase()))
            {
                string failed = string.Empty;
                foreach (var col in db.GetMapping <TestObjIntWithDefaultValue>().Columns)
                {
                    if (col.PropertyName == "SomeValue" && !col.DefaultValue.Equals(WithDefaultValue.CustomAttributeDefaultValue))
                    {
                        failed += " , SomeValue does not equal " + WithDefaultValue.CustomAttributeDefaultValue;
                    }
                }

                Assert.True(string.IsNullOrWhiteSpace(failed), failed);
                db.ColumnInformationProvider = null;
            }
        }
예제 #11
0
        public void CanHaveSubtractInWhereClause()
        {
            int n = 20;
            IEnumerable <TestObjInt> cq = from i in Enumerable.Range(1, n)
                                          select new TestObjInt()
            {
                Data = i,
            };

            var db = new TestDb(TestPath.CreateTemporaryDatabase());

            db.InsertAll(cq);

            TableQuery <TestObjInt> results = db.Table <TestObjInt>().Where(o => o.Data - 10 >= 0);

            Assert.AreEqual(results.Count(), 11);
            Assert.AreEqual(results.OrderBy(o => o.Data).FirstOrDefault().Data, 10);
        }
예제 #12
0
 public void SelectWorks()
 {
     using (var db = new TestDb(TestPath.GetTempFileName()))
     {
         db.Insert(new TestObj()
         {
             Order = 5
         });
         try
         {
             Assert.That(db.Table <TestObj>().Select(obj => obj.Order * 2).First(), Is.EqualTo(10));
         }
         catch (NotImplementedException)
         {
             //Allow Not implemented exceptions as the selection may be too complex.
         }
     }
 }
예제 #13
0
        public void AddForStringsMeansConcatenate()
        {
            int n = 20;
            IEnumerable <TestObjString> cq = from i in Enumerable.Range(1, n)
                                             select new TestObjString()
            {
                Data = i.ToString(),
            };

            var db = new TestDb(TestPath.CreateTemporaryDatabase());

            db.InsertAll(cq);

            TableQuery <TestObjString> results = db.Table <TestObjString>().Where(o => o.Data + "1" == "11");

            Assert.AreEqual(1, results.Count());
            Assert.AreEqual("1", results.OrderBy(o => o.Data).FirstOrDefault().Data);
        }
예제 #14
0
        private static TestDb GetTestDBWith100Elements()
        {
            int n = 100;

            IEnumerable <TestObj> cq = from i in Enumerable.Range(1, n)
                                       select new TestObj
            {
                Order = i
            };

            TestObj[] objs = cq.ToArray();
            var       db   = new TestDb(TestPath.GetTempFileName());

            int numIn = db.InsertAll(objs);

            Assert.AreEqual(numIn, n, "Num inserted must = num objects");
            return(db);
        }
예제 #15
0
        public void NullableScalarInt()
        {
            var db = new SQLiteConnection(new SQLitePlatformTest(), TestPath.GetTempFileName());

            db.CreateTable <NullableIntClass>();

            var withNull = new NullableIntClass
            {
                NullableInt = null
            };
            var with0 = new NullableIntClass
            {
                NullableInt = 0
            };
            var with1 = new NullableIntClass
            {
                NullableInt = 1
            };
            var withMinus1 = new NullableIntClass
            {
                NullableInt = -1
            };

            db.Insert(withNull);
            db.Insert(with0);
            db.Insert(with1);
            db.Insert(withMinus1);

            var actualShouldBeNull   = db.ExecuteScalar <int?>("select NullableInt from NullableIntClass order by ID limit 1");
            var actualShouldBe0      = db.ExecuteScalar <int?>("select NullableInt from NullableIntClass order by ID limit 1 offset 1");
            var actualShouldBe1      = db.ExecuteScalar <int?>("select NullableInt from NullableIntClass order by ID limit 1 offset 2");
            var actualShouldBeMinus1 = db.ExecuteScalar <int?>("select NullableInt from NullableIntClass order by ID limit 1 offset 3");

            Assert.AreEqual(null, actualShouldBeNull);
            Assert.AreEqual(0, actualShouldBe0);
            Assert.AreEqual(1, actualShouldBe1);
            Assert.AreEqual(-1, actualShouldBeMinus1);
        }
예제 #16
0
        public void NullableInt()
        {
            var db = new SQLiteConnection(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase());

            db.CreateTable <NullableIntClass>();

            var withNull = new NullableIntClass
            {
                NullableInt = null
            };
            var with0 = new NullableIntClass
            {
                NullableInt = 0
            };
            var with1 = new NullableIntClass
            {
                NullableInt = 1
            };
            var withMinus1 = new NullableIntClass
            {
                NullableInt = -1
            };

            db.Insert(withNull);
            db.Insert(with0);
            db.Insert(with1);
            db.Insert(withMinus1);

            NullableIntClass[] results = db.Table <NullableIntClass>().OrderBy(x => x.ID).ToArray();

            Assert.AreEqual(4, results.Length);

            Assert.AreEqual(withNull, results[0]);
            Assert.AreEqual(with0, results[1]);
            Assert.AreEqual(with1, results[2]);
            Assert.AreEqual(withMinus1, results[3]);
        }
예제 #17
0
        public void WhereNotNull()
        {
            var db = new SQLiteConnection(new SQLitePlatformTest(), TestPath.GetTempFileName());

            db.CreateTable <NullableIntClass>();

            var withNull = new NullableIntClass
            {
                NullableInt = null
            };
            var with0 = new NullableIntClass
            {
                NullableInt = 0
            };
            var with1 = new NullableIntClass
            {
                NullableInt = 1
            };
            var withMinus1 = new NullableIntClass
            {
                NullableInt = -1
            };

            db.Insert(withNull);
            db.Insert(with0);
            db.Insert(with1);
            db.Insert(withMinus1);

            NullableIntClass[] results =
                db.Table <NullableIntClass>().Where(x => x.NullableInt != null).OrderBy(x => x.ID).ToArray();

            Assert.AreEqual(3, results.Length);

            Assert.AreEqual(with0, results[0]);
            Assert.AreEqual(with1, results[1]);
            Assert.AreEqual(withMinus1, results[2]);
        }
예제 #18
0
        public void ReplaceInWhere()
        {
            string testElement      = "Element";
            string alternateElement = "Alternate";
            string replacedElement  = "ReplacedElement";

            int n = 20;
            IEnumerable <TestObj> cq = from i in Enumerable.Range(1, n)
                                       select new TestObj
            {
                Name = (i % 2 == 0) ? testElement : alternateElement
            };

            var db = new TestDb(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase());

            db.InsertAll(cq);

            db.TraceListener = DebugTraceListener.Instance;


            List <TestObj> result = (from o in db.Table <TestObj>() where o.Name.Replace(testElement, replacedElement) == replacedElement select o).ToList();

            Assert.AreEqual(10, result.Count);
        }
예제 #19
0
        public void CollateAttributeSubtype()
        {
            var obj = new TestObjWithSubtypedAttributes
            {
                CollateDefault = "Alpha ",
                CollateBinary  = "Alpha ",
                CollateRTrim   = "Alpha ",
                CollateNoCase  = "Alpha ",
            };

            var db = new TestDbSubtype(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase());

            db.Insert(obj);

            var testTable = db.Table <TestObjWithSubtypedAttributes>();

            Assert.AreEqual(1, (from o in testTable where o.CollateDefault == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateDefault == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateDefault == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateDefault == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in testTable where o.CollateBinary == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateBinary == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateBinary == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateBinary == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in testTable where o.CollateRTrim == "Alpha " select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateRTrim == "ALPHA " select o).Count());
            Assert.AreEqual(1, (from o in testTable where o.CollateRTrim == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateRTrim == "ALPHA" select o).Count());

            Assert.AreEqual(1, (from o in testTable where o.CollateNoCase == "Alpha " select o).Count());
            Assert.AreEqual(1, (from o in testTable where o.CollateNoCase == "ALPHA " select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateNoCase == "Alpha" select o).Count());
            Assert.AreEqual(0, (from o in testTable where o.CollateNoCase == "ALPHA" select o).Count());
        }
예제 #20
0
 public TestDb(bool storeDateTimeAsTicks = false)
     : base(new SQLitePlatformTest(), TestPath.GetTempFileName(), storeDateTimeAsTicks)
 {
     TraceListener = DebugTraceListener.Instance;
 }
예제 #21
0
 public void Setup()
 {
     _db = new TestDb(TestPath.GetTempFileName());
 }
예제 #22
0
 public TestDb(bool storeDateTimeAsTicks = false)
     : base(new SQLitePlatformWin32(), TestPath.GetTempFileName(), storeDateTimeAsTicks)
 {
     Trace = true;
 }
예제 #23
0
 public void Setup()
 {
     _db = new TestDb(TestPath.CreateTemporaryDatabase());
 }
 public BlobDatabase(IBlobSerializer serializer) :
     base(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase(), false, serializer)
 {
     DropTable <ComplexOrder>();
 }
 public BlobDatabase(IBlobSerializer serializer) :
     base(new SQLitePlatformTest(), TestPath.GetTempFileName(), false, serializer)
 {
     DropTable <ComplexOrder>();
 }
예제 #26
0
        public void SetUp()
        {
            var databaseFile = TestPath.CreateTemporaryDatabase();

            _connectionParameters = new SQLiteConnectionString(databaseFile, false);
        }
예제 #27
0
 public TestDb() : base(new SQLitePlatformWin32(), TestPath.GetTempFileName())
 {
     Trace = true;
 }
예제 #28
0
 public TestDb() : base(new SQLitePlatformTest(), TestPath.GetTempFileName())
 {
     TraceListener = DebugTraceListener.Instance;
 }
예제 #29
0
 public TestDb() : base(new SQLitePlatformTest(), TestPath.CreateTemporaryDatabase())
 {
     TraceListener = DebugTraceListener.Instance;
 }