Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
 public TestDb(bool storeDateTimeAsTicks = true, IContractResolver resolver = null)
     : base(
         new SQLitePlatformTest(), TestPath.GetTempFileName(), storeDateTimeAsTicks, null,
         extraTypeMappings: null,
         resolver: resolver)
 {
     TraceListener = DebugTraceListener.Instance;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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]);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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.
         }
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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]);
        }
Ejemplo n.º 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]);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 20
0
 public TestDb(bool storeDateTimeAsTicks = false)
     : base(new SQLitePlatformTest(), TestPath.GetTempFileName(), storeDateTimeAsTicks)
 {
     TraceListener = DebugTraceListener.Instance;
 }
Ejemplo n.º 21
0
 public void Setup()
 {
     _db = new TestDb(TestPath.GetTempFileName());
 }
Ejemplo n.º 22
0
 public TestDb(bool storeDateTimeAsTicks = false)
     : base(new SQLitePlatformWin32(), TestPath.GetTempFileName(), storeDateTimeAsTicks)
 {
     Trace = true;
 }
Ejemplo n.º 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>();
 }
Ejemplo n.º 26
0
        public void SetUp()
        {
            var databaseFile = TestPath.CreateTemporaryDatabase();

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