예제 #1
0
        public UserModel(int id)
        {
            DataTable DataTable = SQLiteDBStateless.ExecDataTable($"SELECT * FROM {this.TableName()} WHERE usrID = {id}");

            if (DataTable.Rows.Count == 1)
            {
                LoadByUserModelDataRow(DataTable.Rows[0]);
            }
        }
예제 #2
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());
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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");
        }
예제 #7
0
        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());
        }
예제 #8
0
 private void Update()
 {
     SQLiteDBStateless.ExecNonQuery(SQLiteDBStateless.GenerateStandardUpdateStatement(this, nameof(this.ID), this.ID));
 }
예제 #9
0
 private void Insert()
 {
     this.ID = (int)SQLiteDBStateless.ExecInsertNonQueryReturnID(SQLiteDBStateless.GenerateStandardInsertStatement(this));
 }
예제 #10
0
 private object GetDatabaseTableFieldName(DataRow dataRow, string fieldName) => dataRow[SQLiteDBStateless.GetDatabaseTableFieldName(this, fieldName)];
예제 #11
0
 public void Delete()
 {
     SQLiteDBStateless.ExecNonQuery(SQLiteDBStateless.GenerateStandardDeleteStatement(this, nameof(this.ID), this.ID));
 }