public void Issue115_MissingPrimaryKey() { using (var conn = new TestDb()) { conn.CreateTable <Issue115_MyObject> (); conn.InsertAll(from i in Enumerable.Range(0, 10) select new Issue115_MyObject { UniqueId = i.ToString(), OtherValue = (byte)(i * 10), }); var query = conn.Table <Issue115_MyObject> (); foreach (var itm in query) { itm.OtherValue++; Assert.AreEqual(1, conn.Update(itm, typeof(Issue115_MyObject))); } } }
public void DerivedIgnore() { var db = new TestDb(); db.CreateTable <DerivedIgnoreClass> (); var o = new DerivedIgnoreClass { Ignored = "Hello", NotIgnored = "World", }; db.Insert(o); var oo = db.Table <DerivedIgnoreClass> ().First(); Assert.AreEqual(null, oo.Ignored); Assert.AreEqual("World", oo.NotIgnored); }
public void GetDoesntHaveIgnores() { var db = new TestDb(); db.CreateTable <TestObj> (); var o = new TestObj { Text = "Hello", IgnoredText = "World", }; db.Insert(o); var oo = db.Get <TestObj> (o.Id); Assert.AreEqual("Hello", oo.Text); Assert.AreEqual(null, oo.IgnoredText); }
public void BaseIgnores() { var db = new TestDb(); db.CreateTable <TableClass> (); var o = new TableClass { ToIgnore = "Hello", Name = "World", }; db.Insert(o); var oo = db.Table <TableClass> ().First(); Assert.AreEqual(null, oo.ToIgnore); Assert.AreEqual("World", oo.Name); }
public void SetUp() { db = new TestDb(); db.CreateTable <Product> (); var prods = new[] { new Product { Name = "Foo" }, new Product { Name = "Bar" }, new Product { Name = "Foobar" }, }; db.InsertAll(prods); }
public void CreateInsertDrop() { var db = new TestDb(); db.CreateTable <Product> (); db.Insert(new Product { Name = "Hello", Price = 16, }); var n = db.Table <Product> ().Count(); Assert.AreEqual(1, n); db.DropTable <Product> (); ExceptionAssert.Throws <SQLiteException>(() => db.Table <Product> ().Count()); }
public void RedefinedIgnores() { var db = new TestDb(); db.CreateTable <RedefinedClass> (); var o = new RedefinedClass { Name = "Foo", Value = "Bar", Values = new List <string> { "hello", "world" }, }; db.Insert(o); var oo = db.Table <RedefinedClass> ().First(); Assert.AreEqual("Foo", oo.Name); Assert.AreEqual("Bar", oo.Value); Assert.AreEqual(null, oo.Values); }
public void NotNullConstraintExceptionListsOffendingColumnsOnUpdate() { // Skip this test if the Dll doesn't support the extended SQLITE_CONSTRAINT codes using (TestDb db = new TestDb()) { db.CreateTable <NotNullNoPK> (); try { NotNullNoPK obj = new NotNullNoPK() { AnotherRequiredStringProp = "Another required string", RequiredIntProp = 123, RequiredStringProp = "Required string" }; db.Insert(obj); obj.RequiredStringProp = null; db.Update(obj); } catch (NotNullConstraintViolationException ex) { string expected = "RequiredStringProp"; string actual = string.Join(", ", ex.Columns.Where(c => !c.IsPK).OrderBy(p => p.PropertyName).Select(c => c.PropertyName)); Assert.AreEqual(expected, actual, "NotNullConstraintViolationException did not correctly list the columns that violated the constraint"); return; } catch (SQLiteException ex) { if (SQLite3.LibVersionNumber() < 3007017 && ex.Result == SQLite3.Result.Constraint) { Inconclusive(); return; } } catch (Exception ex) { Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. An exception of type {0} was thrown instead.", ex.GetType().Name); } Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown."); } }
public void InsertWithNullsThrowsException() { using (TestDb db = new TestDb()) { db.CreateTable <NotNullNoPK> (); try { NotNullNoPK obj = new NotNullNoPK(); db.Insert(obj); } catch (NotNullConstraintViolationException) { return; } catch (SQLiteException ex) { if (SQLite3.LibVersionNumber() < 3007017 && ex.Result == SQLite3.Result.Constraint) { Inconclusive(); return; } } } Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown."); }
public void SetStringKey() { string path; var key = "SecretPassword"; using (var db = new TestDb(key: key)) { path = db.DatabasePath; db.CreateTable <TestTable> (); db.Insert(new TestTable { Value = "Hello" }); } using (var db = new TestDb(path, key: key)) { path = db.DatabasePath; var r = db.Table <TestTable> ().First(); Assert.AreEqual("Hello", r.Value); } }
public void Issue86() { var db = new TestDb(); db.CreateTable <Foo> (); db.Insert(new Foo { Bar = 42 }); db.Insert(new Foo { Bar = 69 }); var found42 = db.Table <Foo> ().Where(f => f.Bar == 42).FirstOrDefault(); Assert.IsNotNull(found42); var ordered = new List <Foo> (db.Table <Foo> ().OrderByDescending(f => f.Bar)); Assert.AreEqual(2, ordered.Count); Assert.AreEqual(69, ordered[0].Bar); Assert.AreEqual(42, ordered[1].Bar); }
public void ExecuteNonQueryWithNullThrowsException() { using (TestDb db = new TestDb()) { db.CreateTable <NotNullNoPK> (); try { NotNullNoPK obj = new NotNullNoPK() { AnotherRequiredStringProp = "Another required prop", RequiredIntProp = 123, RequiredStringProp = "Required string prop" }; db.Insert(obj); NotNullNoPK obj2 = new NotNullNoPK() { objectId = 1, OptionalIntProp = 123, }; db.InsertOrReplace(obj2); } catch (NotNullConstraintViolationException) { return; } catch (SQLiteException ex) { if (SQLite3.LibVersionNumber() < 3007017 && ex.Result == SQLite3.Result.Constraint) { Inconclusive(); return; } } catch (Exception ex) { Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. An exception of type {0} was thrown instead.", ex.GetType().Name); } } Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown."); }
public void Issue303_WhereNot_B() { using (var db = new TestDb()) { db.CreateTable <Issue303_B>(); db.Insert(new Issue303_B { Id = 1, Flag = true }); db.Insert(new Issue303_B { Id = 2, Flag = false }); db.Insert(new Issue303_B { Id = 3, Flag = true }); db.Insert(new Issue303_B { Id = 4, Flag = false }); var r = (from p in db.Table <Issue303_B>() where !p.Flag select p).ToList(); Assert.AreEqual(2, r.Count); Assert.AreEqual(2, r[0].Id); Assert.AreEqual(4, r[1].Id); } }
public void Issue303_WhereNot_A() { using (var db = new TestDb()) { db.CreateTable <Issue303_A>(); db.Insert(new Issue303_A { Id = 1, Name = "aa" }); db.Insert(new Issue303_A { Id = 2, Name = null }); db.Insert(new Issue303_A { Id = 3, Name = "test" }); db.Insert(new Issue303_A { Id = 4, Name = null }); var r = (from p in db.Table <Issue303_A>() where !(p.Name == null) select p).ToList(); Assert.AreEqual(2, r.Count); Assert.AreEqual(1, r[0].Id); Assert.AreEqual(3, r[1].Id); } }
public void OverrideNames() { var db = new TestDb(); db.CreateTable <OverrideNamesClass> (); var cols = db.GetTableInfo("OverrideNamesClass"); Assert.AreEqual(3, cols.Count); Assert.IsTrue(cols.Exists(x => x.Name == "n")); Assert.IsTrue(cols.Exists(x => x.Name == "v")); var o = new OverrideNamesClass { Name = "Foo", Value = "Bar", }; db.Insert(o); var oo = db.Table <OverrideNamesClass> ().First(); Assert.AreEqual("Foo", oo.Name); Assert.AreEqual("Bar", oo.Value); }
public void CreateTypeWithNoProps() { var db = new TestDb(); db.CreateTable <NoPropObject> (); }
public void CreateTableSucceeds() { var db = new TestDb(); db.CreateTable <TestObj> (); }