Exemplo n.º 1
0
        public SQLServerWrapper(SqlConnection connectionObject, WrapperAdditionalConfig config) : this()
        {
            Connection = connectionObject;

            if (!string.IsNullOrWhiteSpace(config.ParameterBindingStartValue))
            {
                BindingStartValue = config.ParameterBindingStartValue;
                if (!string.IsNullOrWhiteSpace(config.DatabaseVersion))
                {
                    ParameterProcessor = new SQLServerParameterProcessor(InternalDatabaseBinding, config.DatabaseVersion, config.ParameterBindingStartValue);
                }
                else
                {
                    ParameterProcessor = new SQLServerParameterProcessor(InternalDatabaseBinding, null, config.ParameterBindingStartValue);
                }
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(config.DatabaseVersion))
                {
                    ParameterProcessor = new SQLServerParameterProcessor(InternalDatabaseBinding, config.DatabaseVersion);
                }
            }

            MaxDeadlockRetry   = config?.MaxDeadlockRetry ?? 0;
            MaxDeadlockMSDelay = config?.MaxDeadlockMSDelay ?? 0;
            ConnectionTimeout  = config?.ConnectionTimeout ?? 30;
        }
        public void FailureMissingParameter()
        {
            var pms = new { you = "test123" };

            SQLServerParameterProcessor mProcessor = new SQLServerParameterProcessor("@");

            Assert.Throws(Is.TypeOf <Exception>().And.Message.EqualTo("The number of parameter binding indexs in the SQL does not match the parameters suplied."), delegate { mProcessor.GetParameters(query, pms); });
        }
        public void FailureWrongParameterName()
        {
            var pms = new { you = "test123", AGEE = 11 };

            SQLServerParameterProcessor mProcessor = new SQLServerParameterProcessor("@");

            Assert.Throws(Is.TypeOf <Exception>().And.Message.EqualTo("The number of binding indexs in your SQL matches the supplied parameters but one or more of them does not have the correct matching name."), delegate { mProcessor.GetParameters(query, pms); });
        }
        public void FailureWrongTypeName()
        {
            var pms  = new { you = "test123", AGE = 11 };
            var typs = new { you = SqlDbType.VarChar, AGEE = SqlDbType.Int };

            SQLServerParameterProcessor mProcessor = new SQLServerParameterProcessor("@");

            Assert.Throws(Is.TypeOf <Exception>().And.Message.EqualTo("One or more of the databaseTypes does not have a matching binding name to the other parameters."), delegate { mProcessor.GetParameters(query, pms, typs); });
        }
        public void FailureMissingType()
        {
            var pms  = new { you = "test123", AGE = 11 };
            var typs = new { you = SqlDbType.VarChar };

            SQLServerParameterProcessor mProcessor = new SQLServerParameterProcessor("@");

            Assert.Throws(Is.TypeOf <Exception>().And.Message.EqualTo("The number of parameters does not match the supplied databaseTypes."), delegate { mProcessor.GetParameters(query, pms, typs); });
        }
        public void Success()
        {
            var pms = new { you = "test123", AGE = 11 };

            SQLServerParameterProcessor mProcessor = new SQLServerParameterProcessor("@");
            var parameters = mProcessor.GetParameters(query, pms);

            Assert.IsTrue(parameters != null && parameters.Count == 2);
        }
        public void SuccessWithTypes()
        {
            var pms  = new { you = "test123", AGE = 11 };
            var typs = new { you = SqlDbType.VarChar, AGE = SqlDbType.Int };

            SQLServerParameterProcessor mProcessor = new SQLServerParameterProcessor("@");
            var parameters = mProcessor.GetParameters(query, pms, typs);

            Assert.IsTrue(parameters != null && parameters.Count == 2);
        }
        public void SuccessWithTypesCheck()
        {
            var pms  = new { you = "test123", AGE = 11 };
            var typs = new { you = SqlDbType.VarChar, AGE = SqlDbType.Int };

            SQLServerParameterProcessor mProcessor = new SQLServerParameterProcessor("@");
            var parameters = mProcessor.GetParameters(query, pms, typs);

            Assert.IsTrue(parameters != null && parameters.Count == 2);

            SQLServerDatabaseType youType = parameters.Where(p => p.BindingName == "you").First().DatabaseType as SQLServerDatabaseType;
            SQLServerDatabaseType AGEType = parameters.Where(p => p.BindingName == "AGE").First().DatabaseType as SQLServerDatabaseType;

            Assert.IsTrue(youType.SQLDBType == SqlDbType.VarChar && AGEType.SQLDBType == SqlDbType.Int);
        }
        public void SuccessfulBindingParameterTypes()
        {
            var pms = new { you = "test123", AGE = 11 };

            SQLServerParameterProcessor mProcessor = new SQLServerParameterProcessor("@");
            var results = mProcessor.GetParameters(pms);

            var dbCommand = new SqlCommand();

            mProcessor.BindParameters(dbCommand, results);

            Assert.IsTrue(dbCommand.Parameters != null && dbCommand.Parameters.Count == 2);
            Assert.IsTrue(dbCommand.Parameters["@you"].SqlDbType == SqlDbType.VarChar);
            Assert.IsTrue(dbCommand.Parameters["@AGE"].SqlDbType == SqlDbType.Int);
        }
        public void SuccessfulBindingParameter()
        {
            var pms = new { you = "test123", AGE = 11 };

            SQLServerParameterProcessor mProcessor = new SQLServerParameterProcessor("@");
            var results = mProcessor.GetParameters(pms);

            var dbCommand = new SqlCommand();

            mProcessor.BindParameters(dbCommand, results);

            Assert.IsTrue(dbCommand.Parameters != null && dbCommand.Parameters.Count == 2);
            Assert.IsTrue(dbCommand.Parameters["@you"]?.Value?.ToString() == "test123");
            Assert.IsTrue(Convert.ToInt32(dbCommand.Parameters["@AGE"]?.Value?.ToString()) == 11);
        }
Exemplo n.º 11
0
 protected SQLServerWrapper() : base()
 {
     SQLCommand         = new SqlCommand();
     ParameterProcessor = new SQLServerParameterProcessor(InternalDatabaseBinding);
 }