public UserModel(int id) { DataTable DataTable = SQLiteDBStateless.ExecDataTable($"SELECT * FROM {this.TableName()} WHERE usrID = {id}"); if (DataTable.Rows.Count == 1) { LoadByUserModelDataRow(DataTable.Rows[0]); } }
public void ReturnTrueIfModelTableFieldsAreCorrect() { List <string> UserModelFields = SQLiteDBStateless.ModelFieldNames(typeof(UserModel)); StringBuilder StringBuilder = new StringBuilder(); foreach (string userModelField in UserModelFields) { StringBuilder.Append(StringBuilder.Length == 0 ? $"{userModelField}" : $", {userModelField}"); } Assert.AreEqual("usrID, usrUID, usrFirstName, usrLastName, usrEmailAddress", StringBuilder.ToString()); }
public void ReturnTrueIfStandardInsertStatementisCorrect() { UserModel UserModel = new UserModel() { ID = 1, UID = "Testert1", FirstName = "Test", LastName = "Tester", EmailAddress = "*****@*****.**" }; string UserInsertStatement = SQLiteDBStateless.GenerateStandardInsertStatement(UserModel); Assert.AreEqual($"INSERT INTO {UserModel.TableName()} (usrUID, usrFirstName, usrLastName, usrEmailAddress) VALUES ('Testert1', 'Test', 'Tester', '*****@*****.**')", UserInsertStatement); }
public void ReturnTrueIfDeleteStatementIsCorrect() { UserModel UserModel = new UserModel() { ID = 1, UID = "Testert1", FirstName = "Test", LastName = "Tester", EmailAddress = "*****@*****.**" }; string UserDeleteStatement = SQLiteDBStateless.GenerateStandardDeleteStatement(UserModel, nameof(UserModel.ID), UserModel.ID); Assert.AreEqual($"DELETE FROM {UserModel.TableName()} WHERE usrID = 1", UserDeleteStatement); }
public void ReturnTrueIfUpdateStatementIsCorrect() { UserModel UserModel = new UserModel() { ID = 1, UID = "Testert1", FirstName = "Test", LastName = "Tester", EmailAddress = "*****@*****.**" }; string UserUpdateStatement = SQLiteDBStateless.GenerateStandardUpdateStatement(UserModel, nameof(UserModel.ID), UserModel.ID); Assert.AreEqual($"UPDATE {UserModel.TableName()} SET usrUID = 'Testert1', usrFirstName = 'Test', usrLastName = 'Tester', usrEmailAddress = '*****@*****.**' WHERE usrID = 1", UserUpdateStatement); }
public void ReturnTrueIfUpdateFieldsAreCorrect() { UserModel UserModel = new UserModel() { ID = 1, UID = "Testert1", FirstName = "Test", LastName = "Tester", EmailAddress = "*****@*****.**" }; string UserUpdateFields = SQLiteDBStateless.GenerateUpdateFields(UserModel); Assert.AreEqual("usrUID = 'Testert1', usrFirstName = 'Test', usrLastName = 'Tester', usrEmailAddress = '*****@*****.**'", UserUpdateFields); Assert.AreEqual($"UPDATE {UserModel.TableName()} SET usrUID = 'Testert1', usrFirstName = 'Test', usrLastName = 'Tester', usrEmailAddress = '*****@*****.**' WHERE usrID = 1", $"UPDATE {UserModel.TableName()} SET {UserUpdateFields} WHERE usrID = 1"); }
public void ReturnTrueIfModelValuesAreCorrect() { UserModel UserModel = new UserModel() { ID = 1, UID = "Testert1", FirstName = "Test", LastName = "Tester", EmailAddress = "*****@*****.**" }; List <object> UserModelFields = SQLiteDBStateless.ModelFieldValues(UserModel); StringBuilder StringBuilder = new StringBuilder(); foreach (object userModelField in UserModelFields) { StringBuilder.Append(StringBuilder.Length == 0 ? $"{userModelField}" : $", {userModelField}"); } Assert.AreEqual("1, 'Testert1', 'Test', 'Tester', '*****@*****.**'", StringBuilder.ToString()); }
private void Update() { SQLiteDBStateless.ExecNonQuery(SQLiteDBStateless.GenerateStandardUpdateStatement(this, nameof(this.ID), this.ID)); }
private void Insert() { this.ID = (int)SQLiteDBStateless.ExecInsertNonQueryReturnID(SQLiteDBStateless.GenerateStandardInsertStatement(this)); }
private object GetDatabaseTableFieldName(DataRow dataRow, string fieldName) => dataRow[SQLiteDBStateless.GetDatabaseTableFieldName(this, fieldName)];
public void Delete() { SQLiteDBStateless.ExecNonQuery(SQLiteDBStateless.GenerateStandardDeleteStatement(this, nameof(this.ID), this.ID)); }