public void OnlyKey() { var db = new TestDb(); db.CreateTable <OnlyKeyModel> (); db.InsertOrReplace(new OnlyKeyModel { MyModelId = "Foo" }); var foo = db.Get <OnlyKeyModel> ("Foo"); Assert.AreEqual(foo.MyModelId, "Foo"); db.Insert(new OnlyKeyModel { MyModelId = "Bar" }); var bar = db.Get <OnlyKeyModel> ("Bar"); Assert.AreEqual(bar.MyModelId, "Bar"); db.Update(new OnlyKeyModel { MyModelId = "Foo" }); var foo2 = db.Get <OnlyKeyModel> ("Foo"); Assert.AreEqual(foo2.MyModelId, "Foo"); }
public void InsertOrReplace() { _db.Trace = true; _db.InsertAll(from i in Enumerable.Range(1, 20) select new TestObj { Text = "#" + i }); Assert.AreEqual(20, _db.Table <TestObj> ().Count()); var t = new TestObj { Id = 5, Text = "Foo", }; _db.InsertOrReplace(t); var r = (from x in _db.Table <TestObj> () orderby x.Id select x).ToList(); Assert.AreEqual(20, r.Count); Assert.AreEqual("Foo", r[4].Text); }
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."); }