public void TestColumnValues() { using (TestDb db = new TestDb()) { db.CreateTable <WithDefaultValue>(); string failed = string.Empty; foreach (var col in db.GetMapping <WithDefaultValue>().Columns) { if (col.PropertyName == "TestInt" && !col.DefaultValue.Equals(WithDefaultValue.IntVal)) { failed += " , TestInt does not equal " + WithDefaultValue.IntVal; } if (col.PropertyName == "TestDecimal" && !col.DefaultValue.Equals(WithDefaultValue.DecimalVal)) { failed += "TestDecimal does not equal " + WithDefaultValue.DecimalVal; } if (col.PropertyName == "TestDateTime" && !col.DefaultValue.Equals(WithDefaultValue.DateTimegVal)) { failed += "TestDateTime does not equal " + WithDefaultValue.DateTimegVal; } if (col.PropertyName == "TestString" && !col.DefaultValue.Equals(WithDefaultValue.StringVal)) { failed += "TestString does not equal " + WithDefaultValue.StringVal; } } Assert.True(string.IsNullOrWhiteSpace(failed), failed); } }
public void TestColumnValues() { using (TestDb db = new TestDb()) { db.CreateTable<WithDefaultValue>(); string failed = string.Empty; foreach (var col in db.GetMapping<WithDefaultValue>().Columns) { if (col.PropertyName == "TestInt" && !col.DefaultValue.Equals(WithDefaultValue.IntVal)) failed += " , TestInt does not equal " + WithDefaultValue.IntVal; if (col.PropertyName == "TestDecimal" && !col.DefaultValue.Equals(WithDefaultValue.DecimalVal)) failed += "TestDecimal does not equal " + WithDefaultValue.DecimalVal; if (col.PropertyName == "TestDateTime" && !col.DefaultValue.Equals(WithDefaultValue.DateTimegVal)) failed += "TestDateTime does not equal " + WithDefaultValue.DateTimegVal; if (col.PropertyName == "TestString" && !col.DefaultValue.Equals(WithDefaultValue.StringVal)) failed += "TestString does not equal " + WithDefaultValue.StringVal; } Assert.True(string.IsNullOrWhiteSpace(failed), failed); } }
public void InheritanceWorks() { var db = new TestDb(); TableMapping mapping = db.GetMapping<Derived>(); Assert.AreEqual(3, mapping.Columns.Length); Assert.AreEqual("Id", mapping.PK.Name); }
public void InheritanceWorks() { var db = new TestDb(); TableMapping mapping = db.GetMapping <Derived>(); Assert.AreEqual(3, mapping.Columns.Length); Assert.AreEqual("Id", mapping.PK.Name); }
public void ImplicitIndex() { var db = new TestDb(); db.CreateTable<NoAttributes>(CreateFlags.ImplicitIndex); TableMapping mapping = db.GetMapping<NoAttributes>(); TableMapping.Column column = mapping.Columns[2]; Assert.AreEqual("IndexedId", column.Name); Assert.IsTrue(column.Indices.Any()); }
public void ImplicitIndex() { var db = new TestDb(); db.CreateTable <NoAttributes>(CreateFlags.ImplicitIndex); TableMapping mapping = db.GetMapping <NoAttributes>(); TableMapping.Column column = mapping.Columns[2]; Assert.AreEqual("IndexedId", column.Name); Assert.IsTrue(column.Indices.Any()); }
public void HasGoodNames() { var db = new TestDb(); db.CreateTable <AFunnyTableName>(); TableMapping mapping = db.GetMapping <AFunnyTableName>(); Assert.AreEqual("AGoodTableName", mapping.TableName); Assert.AreEqual("Id", mapping.Columns[0].Name); Assert.AreEqual("AGoodColumnName", mapping.Columns[1].Name); }
private static void VerifyCreations(TestDb db) { TableMapping orderLine = db.GetMapping(typeof (OrderLine)); Assert.AreEqual(6, orderLine.Columns.Length); var l = new OrderLine { Status = OrderLineStatus.Shipped }; db.Insert(l); OrderLine lo = db.Table<OrderLine>().First(x => x.Status == OrderLineStatus.Shipped); Assert.AreEqual(lo.Id, l.Id); }
public void ImplicitAutoIncAsPassedInTypes() { var db = new TestDb(); db.CreateTable(typeof (PkAttribute), CreateFlags.AutoIncPK); TableMapping mapping = db.GetMapping<PkAttribute>(); Assert.IsNotNull(mapping.PK); Assert.AreEqual("Id", mapping.PK.Name); Assert.IsTrue(mapping.PK.IsPK); Assert.IsTrue(mapping.PK.IsAutoInc); }
public void HasGoodNames() { var db = new TestDb(); db.CreateTable<AFunnyTableName>(); TableMapping mapping = db.GetMapping<AFunnyTableName>(); Assert.AreEqual("AGoodTableName", mapping.TableName); Assert.AreEqual("Id", mapping.Columns[0].Name); Assert.AreEqual("AGoodColumnName", mapping.Columns[1].Name); }
public void ImplicitPKAutoInc() { var db = new TestDb(); db.CreateTable(typeof(NoAttributes), CreateFlags.ImplicitPK | CreateFlags.AutoIncPK); TableMapping mapping = db.GetMapping <NoAttributes>(); Assert.IsNotNull(mapping.PK); Assert.AreEqual("Id", mapping.PK.Name); Assert.IsTrue(mapping.PK.IsPK); Assert.IsTrue(mapping.PK.IsAutoInc); }
public void ImplicitAutoIncAsPassedInTypes() { var db = new TestDb(); db.CreateTable(typeof(PkAttribute), CreateFlags.AutoIncPK); TableMapping mapping = db.GetMapping <PkAttribute>(); Assert.IsNotNull(mapping.PK); Assert.AreEqual("Id", mapping.PK.Name); Assert.IsTrue(mapping.PK.IsPK); Assert.IsTrue(mapping.PK.IsAutoInc); }
public void ImplicitAutoInc() { var db = new TestDb(); db.CreateTable<PkAttribute>(CreateFlags.AutoIncPK); TableMapping mapping = db.GetMapping<PkAttribute>(); Assert.IsFalse(mapping.HasCompositePK); Assert.IsNotNull(mapping.PK); Assert.AreEqual("Id", mapping.PK.Name); Assert.IsTrue(mapping.PK.IsPK); Assert.IsTrue(mapping.PK.IsAutoInc); }
public void ImplicitPK() { var db = new TestDb(); db.CreateTable <NoAttributes>(CreateFlags.ImplicitPK); TableMapping mapping = db.GetMapping <NoAttributes>(); Assert.IsNotNull(mapping.PK); Assert.AreEqual("Id", mapping.PK.Name); Assert.IsTrue(mapping.PK.IsPK); Assert.IsFalse(mapping.PK.IsAutoInc); CheckPK(db); }
public void WithoutImplicitMapping() { var db = new TestDb(); db.CreateTable <NoAttributes>(); TableMapping mapping = db.GetMapping <NoAttributes>(); Assert.IsNull(mapping.PK); TableMapping.Column column = mapping.Columns[2]; Assert.AreEqual("IndexedId", column.Name); Assert.IsFalse(column.Indices.Any()); Assert.Throws(typeof(AssertionException), () => CheckPK(db)); }
private static void VerifyCreations(TestDb db) { TableMapping orderLine = db.GetMapping(typeof(OrderLine)); Assert.AreEqual(6, orderLine.Columns.Length); var l = new OrderLine { Status = OrderLineStatus.Shipped }; db.Insert(l); OrderLine lo = db.Table <OrderLine>().First(x => x.Status == OrderLineStatus.Shipped); Assert.AreEqual(lo.Id, l.Id); }
public void ExecuteNonQueryWithNullThrowsException() { using (TestDb db = new TestDb()) { TableMapping map; db.CreateTable <NotNullNoPK>(); try { NotNullNoPK obj = new NotNullNoPK() { AnotherRequiredStringProp = "Another required prop", RequiredIntProp = 123, RequiredStringProp = "Required string prop" }; db.Insert(obj); map = db.GetMapping <NotNullNoPK>(); map.GetInsertCommand(db, "OR REPLACE").ExecuteNonQuery(new object[] { 1, null, 123, null, null, null }); } catch (NotNullConstraintViolationException) { return; } catch (SQLiteException ex) { if (db.Platform.SQLiteApi.LibVersionNumber() < 3007017 && ex.Result == Result.Constraint) { Assert.Inconclusive("Detailed constraint information is only available in SQLite3 version 3.7.17 and above."); } } 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 ImplicitPK() { var db = new TestDb(); db.CreateTable<NoAttributes>(CreateFlags.ImplicitPK); TableMapping mapping = db.GetMapping<NoAttributes>(); Assert.IsNotNull(mapping.PK); Assert.AreEqual("Id", mapping.PK.Name); Assert.IsTrue(mapping.PK.IsPK); Assert.IsFalse(mapping.PK.IsAutoInc); CheckPK(db); }
public void ExecuteNonQueryWithNullThrowsException() { using (TestDb db = new TestDb()) { TableMapping map; db.CreateTable<NotNullNoPK>(); try { NotNullNoPK obj = new NotNullNoPK() { AnotherRequiredStringProp = "Another required prop", RequiredIntProp = 123, RequiredStringProp = "Required string prop" }; db.Insert(obj); map = db.GetMapping<NotNullNoPK>(); map.GetInsertCommand(db, "OR REPLACE").ExecuteNonQuery(new object[] { 1, null, 123, null, null, null }); } catch (NotNullConstraintViolationException) { return; } catch (SQLiteException ex) { if (db.Platform.SQLiteApi.LibVersionNumber() < 3007017 && ex.Result == Result.Constraint) { Assert.Inconclusive("Detailed constraint information is only available in SQLite3 version 3.7.17 and above."); } } 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 ImplicitPKAutoInc() { var db = new TestDb(); db.CreateTable(typeof (NoAttributes), CreateFlags.ImplicitPK | CreateFlags.AutoIncPK); TableMapping mapping = db.GetMapping<NoAttributes>(); Assert.IsNotNull(mapping.PK); Assert.AreEqual("Id", mapping.PK.Name); Assert.IsTrue(mapping.PK.IsPK); Assert.IsTrue(mapping.PK.IsAutoInc); }
public void ImplicitPkAsPassedInTypes() { var db = new TestDb(); db.CreateTable(typeof (NoAttributes), CreateFlags.ImplicitPK); TableMapping mapping = db.GetMapping<NoAttributes>(); Assert.IsFalse(mapping.HasCompositePK); Assert.IsNotNull(mapping.PK); Assert.AreEqual("Id", mapping.PK.Name); Assert.IsTrue(mapping.PK.IsPK); Assert.IsFalse(mapping.PK.IsAutoInc); }
public void WithoutImplicitMapping() { var db = new TestDb(); db.CreateTable<NoAttributes>(); TableMapping mapping = db.GetMapping<NoAttributes>(); Assert.IsNull(mapping.PK); TableMapping.Column column = mapping.Columns[2]; Assert.AreEqual("IndexedId", column.Name); Assert.IsFalse(column.Indices.Any()); Assert.Throws(typeof (AssertionException), () => CheckPK(db)); }