Esempio n. 1
0
        public void NewWithNullName()
        {
            var attribute = new CremaAttribute(null);

            Assert.AreEqual(string.Empty, attribute.AttributeName);
            Assert.AreEqual(typeof(string), attribute.DataType);
            Assert.AreEqual(true, attribute.AllowDBNull);
            Assert.AreEqual(false, attribute.AutoIncrement);
            Assert.AreEqual(string.Empty, attribute.Comment);
            Assert.AreEqual(DBNull.Value, attribute.DefaultValue);
        }
Esempio n. 2
0
        public void NewWithName()
        {
            var attributeName = RandomUtility.NextIdentifier();
            var attribute     = new CremaAttribute(attributeName);

            Assert.AreEqual(attributeName, attribute.AttributeName);
            Assert.AreEqual(typeof(string), attribute.DataType);
            Assert.AreEqual(true, attribute.AllowDBNull);
            Assert.AreEqual(false, attribute.AutoIncrement);
            Assert.AreEqual(string.Empty, attribute.Comment);
            Assert.AreEqual(DBNull.Value, attribute.DefaultValue);
        }
Esempio n. 3
0
        public void NewWithNullNameAndType()
        {
            var attributeType = CremaDataTypeUtility.GetBaseTypes().Random();
            var attribute     = new CremaAttribute(null, attributeType);

            Assert.AreEqual(string.Empty, attribute.AttributeName);
            Assert.AreEqual(attributeType, attribute.DataType);
            Assert.AreEqual(true, attribute.AllowDBNull);
            Assert.AreEqual(false, attribute.AutoIncrement);
            Assert.AreEqual(string.Empty, attribute.Comment);
            Assert.AreEqual(DBNull.Value, attribute.DefaultValue);
        }
Esempio n. 4
0
        public static void InitializeRandom(this CremaAttribute attribute)
        {
            attribute.DataType = CremaDataTypeUtility.GetBaseTypes().Random();

            if (RandomUtility.Within(25) == true)
            {
                attribute.Comment = RandomUtility.NextString();
            }

            if (RandomUtility.Within(25) == true)
            {
                attribute.DefaultValue = RandomUtility.Next(attribute.DataType);
            }

            if (RandomUtility.Within(25) == true && CremaDataTypeUtility.CanUseAutoIncrement(attribute.DataType) == true && attribute.DefaultValue == DBNull.Value)
            {
                attribute.AutoIncrement = RandomUtility.NextBoolean();
            }
        }
Esempio n. 5
0
        private void WriteAttribute(XmlSchema schema, XmlSchemaComplexType complexType, CremaAttribute attribute)
        {
            var schemaAttribute = new XmlSchemaAttribute()
            {
                Name           = attribute.AttributeName,
                SchemaTypeName = GetSystemQualifiedName(attribute.DataType, schema.TargetNamespace)
            };

            if (attribute.AllowDBNull == false)
            {
                if (attribute.DefaultValue == DBNull.Value)
                {
                    schemaAttribute.Use = XmlSchemaUse.Required;
                }
                else
                {
                    schemaAttribute.Use = XmlSchemaUse.Optional;
                }
            }

            var defaultValue = attribute.DefaultValue;

            if (defaultValue != DBNull.Value)
            {
                schemaAttribute.DefaultValue = CremaXmlConvert.ToString(defaultValue, attribute.DataType);
            }

            schemaAttribute.WriteAppInfo(CremaSchema.AttributeInfo, CremaSchema.AutoIncrement, attribute.AutoIncrement, schema.TargetNamespace);
            schemaAttribute.WriteAppInfo(CremaSchema.AttributeInfo, CremaSchema.Comment, attribute.Comment, schema.TargetNamespace);

            complexType.Attributes.Add(schemaAttribute);
        }
Esempio n. 6
0
 public static object GetRandomValue(this CremaAttribute attribute)
 {
     return(RandomUtility.Next(attribute.DataType));
 }