public TestDb(bool storeDateTimeAsTicks = true, IContractResolver resolver = null) : base( TestPath.CreateTemporaryDatabase(), storeDateTimeAsTicks, null, extraTypeMappings: null, resolver: resolver) { TraceListener = DebugTraceListener.Instance; }
public void CustomIgnoreAttributeTest() { var db = new SQLiteConnection(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 void ByteArrayWhereNull() { //Byte Arrays for comparison 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[]{ } }, //Empty byte array should stay empty (and not become null) 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 = null } //Null should be supported }; var database = new SQLiteConnection(TestPath.CreateTemporaryDatabase()); database.CreateTable <ByteArrayClass>(); //Insert all of the ByteArrayClass int id = 0; foreach (var b in byteArrays) { database.Insert(b); if (b.bytes == null) { id = b.ID; } } Assert.AreNotEqual(0, id, "An ID wasn't set"); //Get it back out var fetchedByteArray = database.Table <ByteArrayClass>().FirstOrDefault(x => x.bytes == null); Assert.IsNotNull(fetchedByteArray); //Check they are the same Assert.AreEqual(id, fetchedByteArray.ID); }
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.CreateTemporaryDatabase()); int numIn = db.InsertAll(objs); Assert.AreEqual(numIn, n, "Num inserted must = num objects"); return(db); }
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); }
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.CreateTemporaryDatabase())) { 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 NullableScalarInt() { var db = new SQLiteConnection(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); 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 WhereNotNull() { var db = new SQLiteConnection(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>().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(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(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 BlobDatabase(IBlobSerializer serializer) : base(TestPath.CreateTemporaryDatabase(), false, serializer) { DropTable <ComplexOrder>(); }
public void Setup() { _db = new TestDb(TestPath.CreateTemporaryDatabase()); }
public void AsyncAsTicks() { var db = new SQLiteConnection(TestPath.CreateTemporaryDatabase()); TestAsyncDateTime(db, true); }
public TestDb() : base(TestPath.CreateTemporaryDatabase()) { TraceListener = DebugTraceListener.Instance; }
public void TestTimeSpan() { var db = new SQLiteConnection(TestPath.CreateTemporaryDatabase()); TestAsyncDateTime(db); }