public void TestCreateEntity(DatabaseProviderTestCase tc)
        {
            var databaseServices = tc.Services;
            IDMLEntityActions dmlEntityActions = GetDMLEntityActions(databaseServices);
            IDictionary <InsertPlaceholder, string> insertPlaceholders = dmlEntityActions.SQLPlaceholderValuesForCreate();
            string beforeStatement     = insertPlaceholders.GetPlaceholderValueTrimStart(InsertPlaceholder.BeforeStatement);
            string beforeValuesKeyword = insertPlaceholders.GetPlaceholderValueTrimStart(InsertPlaceholder.BeforeValuesKeyword);
            string afterStatement      = insertPlaceholders.GetPlaceholderValueTrimEnd(InsertPlaceholder.AfterStatement);

            int    value     = 2;
            string insertSql = beforeStatement + "INSERT INTO DUMMY" + MachineName + " (VAL) " + beforeValuesKeyword + "VALUES (" + value + ")" + afterStatement;
            string selectSql = "SELECT VAL FROM DUMMY" + MachineName + " WHERE VAL = " + value;

            ExecuteSQL(databaseServices, (service, tran) => {
                using (IDbCommand cmd = service.CreateCommand(tran, insertSql)) {
                    service.ExecuteNonQuery(cmd);
                }
                int insertedValue;
                using (IDbCommand cmd = service.CreateCommand(tran, selectSql)) {
                    insertedValue = (int)Convert.ChangeType(service.ExecuteScalar(cmd), typeof(int));
                }
                AssertEqual(value, insertedValue, string.Format(errorMessageFormat, "CreateEntity", insertSql));
                return(true);
            });
        }
        public void TestGetEntityForUpdate(DatabaseProviderTestCase tc)
        {
            var databaseServices = tc.Services;
            IDMLEntityActions dmlEntityActions = GetDMLEntityActions(databaseServices);

            InnerGetEntity(databaseServices, dmlEntityActions.SQLPlaceholderValuesForGetForUpdate(), /*forUpdate*/ true);
        }
        public void TestUpdateEntity(DatabaseProviderTestCase tc)
        {
            var databaseServices = tc.Services;
            IDMLEntityActions dmlEntityActions = GetDMLEntityActions(databaseServices);
            IDictionary <UpdatePlaceholder, string> updatePlaceholders = dmlEntityActions.SQLPlaceholderValuesForUpdate();
            string beforeStatement    = updatePlaceholders.GetPlaceholderValueTrimStart(UpdatePlaceholder.BeforeStatement);
            string beforeWhereKeyword = updatePlaceholders.GetPlaceholderValueTrimStart(UpdatePlaceholder.BeforeWhereKeyword);
            string afterStatement     = updatePlaceholders.GetPlaceholderValueTrimEnd(UpdatePlaceholder.AfterStatement);

            int    value     = 2;
            string updateSql = beforeStatement + "UPDATE DUMMY" + MachineName + " SET VAL = " + value + " " + beforeWhereKeyword + "WHERE ID = 1" + afterStatement;
            string selectSql = "SELECT VAL FROM DUMMY" + MachineName + " WHERE ID = 1";

            ExecuteSQL(databaseServices, (service, tran) => {
                using (IDbCommand cmd = service.CreateCommand(tran, updateSql)) {
                    service.ExecuteNonQuery(cmd);
                }
                int updatedValue;
                using (IDbCommand cmd = service.CreateCommand(tran, selectSql)) {
                    updatedValue = (int)Convert.ChangeType(service.ExecuteScalar(cmd), typeof(int));
                }
                AssertEqual(value, updatedValue, string.Format(errorMessageFormat, "UpdateEntity", updateSql));
                return(true);
            });
        }
        public void TestCreateEntityRetrievingId(DatabaseProviderTestCase tc)
        {
            var databaseServices = tc.Services;
            IDMLEntityActions dmlEntityActions = GetDMLEntityActions(databaseServices);

            string           cleanParamName = "id";
            string           paramName      = databaseServices.ExecutionService.ParameterPrefix + cleanParamName;
            int              value          = 2;
            RetrieveIdMethod retrieveIdMethod;
            IDictionary <InsertPlaceholder, string> insertPlaceholders = dmlEntityActions.SQLPlaceholderValuesForCreateAndRetrieveId("ID", cleanParamName, out retrieveIdMethod);

            string beforeStatement     = insertPlaceholders.GetPlaceholderValueTrimStart(InsertPlaceholder.BeforeStatement);
            string beforeValuesKeyword = insertPlaceholders.GetPlaceholderValueTrimStart(InsertPlaceholder.BeforeValuesKeyword);
            string afterStatement      = insertPlaceholders.GetPlaceholderValueTrimEnd(InsertPlaceholder.AfterStatement);

            string sql = beforeStatement + "INSERT INTO DUMMY" + MachineName + " (VAL) " + beforeValuesKeyword + "VALUES (" + value + ")" + afterStatement;

            //Console.WriteLine("TestCreateEntityRetrievingId SQL: " + sql);
            if (retrieveIdMethod == RetrieveIdMethod.ReturnValue)
            {
                ExecuteSQL(databaseServices, (service, tran) => {
                    int returnedId;
                    using (IDbCommand cmd = service.CreateCommand(tran, sql)) {
                        returnedId = (int)Convert.ChangeType(service.ExecuteScalar(cmd), typeof(int));
                    }
                    ValidateInsertedValue(service, tran, value, returnedId, sql);
                    return(true);
                });
            }
            else
            {
                ExecuteSQL(databaseServices, (service, tran) => {
                    int returnedId;
                    using (IDbCommand cmd = service.CreateCommand(tran, sql)) {
                        IDbDataParameter parameter = service.CreateParameter(cmd, paramName, DbType.Int32, null);
                        service.SetParameterDirection(parameter, ParameterDirection.Output);
                        service.ExecuteNonQuery(cmd);
                        returnedId = (int)Convert.ChangeType(parameter.Value, typeof(int));
                    }
                    ValidateInsertedValue(service, tran, value, returnedId, sql);
                    return(true);
                });
            }
        }
        public void TestDeleteEntity(DatabaseProviderTestCase tc)
        {
            var databaseServices = tc.Services;
            IDMLEntityActions dmlEntityActions = GetDMLEntityActions(databaseServices);
            IDictionary <DeletePlaceholder, string> deletePlaceholders = dmlEntityActions.SQLPlaceholderValuesForDelete();
            string beforeStatement    = deletePlaceholders.GetPlaceholderValueTrimStart(DeletePlaceholder.BeforeStatement);
            string beforeWhereKeyword = deletePlaceholders.GetPlaceholderValueTrimStart(DeletePlaceholder.BeforeWhereKeyword);
            string afterStatement     = deletePlaceholders.GetPlaceholderValueTrimEnd(DeletePlaceholder.AfterStatement);

            string deleteSql = beforeStatement + "DELETE FROM DUMMY" + MachineName + " " + beforeWhereKeyword + "WHERE ID = 1" + afterStatement;
            string selectSql = "SELECT VAL FROM DUMMY" + MachineName + " WHERE ID = 1";

            ExecuteSQL(databaseServices, (service, tran) => {
                using (IDbCommand cmd = service.CreateCommand(tran, deleteSql)) {
                    service.ExecuteNonQuery(cmd);
                }
                object deletedValue;
                using (IDbCommand cmd = service.CreateCommand(tran, selectSql)) {
                    deletedValue = service.ExecuteScalar(cmd);
                }
                AssertEqual(null, deletedValue, string.Format(errorMessageFormat, "DeleteEntity", deleteSql));
                return(true);
            });
        }