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