public void UpdateWithNullThrowsException() { 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) { 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 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 Update() { var query = from p in db.Table <Product>() select p; Assert.AreEqual(0, changeCount); Assert.AreEqual(22, query.Count()); var pr = query.First(); pr.Price = 10000000; db.Update(pr); Assert.AreEqual(1, changeCount); Assert.AreEqual(22, query.Count()); }
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 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."); } }