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 (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.");
        }
Example #2
0
        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 (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.");
                    }
                }
            }
            Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown.");
        }
Example #3
0
        public void NotNullConstraintExceptionListsOffendingColumnsOnInsert()
        {
            using (TestDb db = new TestDb())
            {
                db.CreateTable <NotNullNoPK>();

                try
                {
                    NotNullNoPK obj = new NotNullNoPK()
                    {
                        RequiredStringProp = "Some value"
                    };
                    db.Insert(obj);
                }
                catch (NotNullConstraintViolationException ex)
                {
                    string expected = "AnotherRequiredStringProp, RequiredIntProp";
                    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 (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.");
                    }
                }
                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 PCLTESTS
                    if (ex.Result == SQLite3.Result.Constraint)
                    {
                        Inconclusive();
                        return;
                    }
#else
                    if (SQLite3.LibVersionNumber() < 3007017 && ex.Result == SQLite3.Result.Constraint)
                    {
                        Inconclusive();
                        return;
                    }
#endif
                }
            }
            Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown.");
        }
Example #5
0
        public void NotNullConstraintExceptionListsOffendingColumnsOnInsert()
        {
            using (SQLiteConnection db = TestDb.GetMemoryDb()) {
                db.CreateTable <NotNullNoPK> ();

                try {
                    NotNullNoPK obj = new NotNullNoPK()
                    {
                        RequiredStringProp = "Some value"
                    };
                    db.Insert(obj);
                }
                catch (NotNullConstraintViolationException ex) {
                    string expected = "RequiredIntProp";
                    string actual   = ex.Column?.PropertyName;

                    Assert.AreEqual(expected, actual, "NotNullConstraintViolationException did not correctly list the columns that violated the constraint");
                    return;
                }
                catch (SQLiteException ex) {
                    if (SQLite3.LibraryVersionInt32 < 3007017 && ex.Result == Result.Constraint)
                    {
                        Inconclusive();
                        return;
                    }
                }
                Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown.");
            }
        }
        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.");
        }
Example #7
0
        public void NotNullConstraintExceptionListsOffendingColumnsOnUpdate()
        {
            using (TestDb db = new TestDb())
            {
                // Skip this test if the Dll doesn't support the extended SQLITE_CONSTRAINT codes
                if (db.Platform.SQLiteApi.LibVersionNumber() >= 3007017)
                {
                    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 (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.");
                }
            }
        }
Example #8
0
        public void InsertWithNullsThrowsException()
        {
            using (SQLiteConnection db = TestDb.GetMemoryDb()) {
                db.CreateTable <NotNullNoPK> ();

                try {
                    NotNullNoPK obj = new NotNullNoPK();
                    db.Insert(obj);
                }
                catch (NotNullConstraintViolationException) {
                    return;
                }
                catch (SQLiteException ex) {
                    if (SQLite3.LibraryVersionInt32 < 3007017 && ex.Result == Result.Constraint)
                    {
                        Inconclusive();
                        return;
                    }
                }
            }
            Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown.");
        }
Example #9
0
        public void NotNullConstraintExceptionListsOffendingColumnsOnUpdate()
        {
            // Skip this test if the Dll doesn't support the extended SQLITE_CONSTRAINT codes

            using (SQLiteConnection db = TestDb.GetMemoryDb()) {
                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   = ex.Column?.PropertyName;

                    Assert.AreEqual(expected, actual, "NotNullConstraintViolationException did not correctly list the columns that violated the constraint");

                    return;
                }
                catch (SQLiteException ex) {
                    if (SQLite3.LibraryVersionInt32 < 3007017 && ex.Result == 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.");
            }
        }
Example #10
0
        public void ExecuteNonQueryWithNullThrowsException()
        {
            using (SQLiteConnection db = TestDb.GetMemoryDb()) {
                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.LibraryVersionInt32 < 3007017 && ex.Result == 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 NotNullConstraintExceptionListsOffendingColumnsOnUpdate()
        {
            using (TestDb db = new TestDb())
            {
                // Skip this test if the Dll doesn't support the extended SQLITE_CONSTRAINT codes
                if (db.Platform.SQLiteApi.LibVersionNumber() >= 3007017)
                {
                    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 (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 NotNullConstraintExceptionListsOffendingColumnsOnInsert()
        {
            using (TestDb db = new TestDb())
            {

                db.CreateTable<NotNullNoPK>();

                try
                {
                    NotNullNoPK obj = new NotNullNoPK() { RequiredStringProp = "Some value" };
                    db.Insert(obj);
                }
                catch (NotNullConstraintViolationException ex)
                {
                    string expected = "AnotherRequiredStringProp, RequiredIntProp";
                    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 (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.");
                    }
                }
                Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown.");
            }
        }
        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 (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.");
                    }
                }
            }
            Assert.Fail("Expected an exception of type NotNullConstraintViolationException to be thrown. No exception was thrown.");
        }
		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 (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.");
		}