Ejemplo n.º 1
0
        public void Constructor_NameIsProvided_NamePropertyIsSet()
        {
            var name = "TestParameter";

            var sqlParameterAttribute = new SqlParameterAttribute(name);

            Assert.AreEqual(name, sqlParameterAttribute.Name);
            Assert.IsNull(sqlParameterAttribute.SqlDbType);
            Assert.IsNull(sqlParameterAttribute.Precision);
            Assert.IsNull(sqlParameterAttribute.Scale);
            Assert.IsNull(sqlParameterAttribute.Size);
        }
Ejemplo n.º 2
0
        public void Constructor_NameAndSqlDbTypeAndSizeAreProvided_NameAndSqlDbTypeAndSizePropertiesAreSet()
        {
            var name      = "TestParameter";
            var sqlDbType = SqlDbType.VarChar;
            var size      = 50;

            var sqlParameterAttribute = new SqlParameterAttribute(name, sqlDbType, size);

            Assert.AreEqual(name, sqlParameterAttribute.Name);
            Assert.AreEqual(sqlDbType, sqlParameterAttribute.SqlDbType);
            Assert.AreEqual(size, sqlParameterAttribute.Size);
            Assert.IsNull(sqlParameterAttribute.Precision);
            Assert.IsNull(sqlParameterAttribute.Scale);
        }
Ejemplo n.º 3
0
        public void Constructor_NameAndSqlDbTypeAndPrecisionAndScaleAreProvided_NameAndSqlDbTypeAndPrecisionAndScalePropertiesAreSet()
        {
            var name      = "TestParameter";
            var sqlDbType = SqlDbType.Decimal;
            var precision = (byte)8;
            var scale     = (byte)2;

            var sqlParameterAttribute = new SqlParameterAttribute(name, sqlDbType, precision, scale);

            Assert.AreEqual(name, sqlParameterAttribute.Name);
            Assert.AreEqual(sqlDbType, sqlParameterAttribute.SqlDbType);
            Assert.AreEqual(precision, sqlParameterAttribute.Precision);
            Assert.AreEqual(scale, sqlParameterAttribute.Scale);
            Assert.IsNull(sqlParameterAttribute.Size);
        }
Ejemplo n.º 4
0
        private EntityParameterSchema CreateSchema(object parametersObject)
        {
            List <ParameterSchema> parameters = new List <ParameterSchema>();

            Type entityType = parametersObject.GetType();

            foreach (PropertyInfo property in entityType.GetProperties())
            {
                if (property.GetCustomAttribute <NotSqlParameterAttribute>() is null)
                {
                    SqlParameterAttribute parameterAttribute =
                        property.GetCustomAttribute <SqlParameterAttribute>();

                    string name = parameterAttribute is null ? property.Name : parameterAttribute.Name;
                    DbType type = SqlTypeMap.Types[property.PropertyType];

                    parameters.Add(new ParameterSchema(name, type, property));
                }
            }

            return(new EntityParameterSchema(entityType, parameters));
        }