public void TestRules() { { AttributeType test = new AttributeType("test", typeof(SByte)); CollectionAssert.IsEmpty(test.Rules); SimpleAttributeRule rule = new SimpleAttributeRule(); test.AddRule(rule); CollectionAssert.Contains(test.Rules, rule); Assert.False(rule.Validated); test.Validate(null, null); Assert.True(rule.Validated); } }
public void TestScalarConstructor() { // fully test one type { AttributeType test = new AttributeType("test", typeof(SByte)); Assert.AreEqual(test.Name, "test"); Assert.AreEqual(test.ClrType, typeof(SByte)); Assert.AreEqual(test.Type, AttributeTypes.Int8); Assert.AreEqual(test.Length, 1); Assert.False(test.IsArray); Assert.AreEqual((SByte)test.GetDefault(), (SByte)0); // test validation of type, without any custom rules Assert.True(test.Validate((SByte)1, null)); Assert.False(test.Validate((Int32)1, null)); Assert.AreEqual(test.GetDefault(), (SByte)0); } // test an unrecognized type { AttributeType test = new AttributeType("test", typeof(AttributeType[])); // unrecognized type is treated as string Assert.AreEqual(test.ClrType, typeof(String)); Assert.AreEqual(test.Type, AttributeTypes.String); Assert.AreEqual(test.Length, 1); Assert.False(test.IsArray); } // test all other types TestScalar <Byte>(AttributeTypes.UInt8); TestScalar <Int16>(AttributeTypes.Int16); TestScalar <UInt16>(AttributeTypes.UInt16); TestScalar <Int32>(AttributeTypes.Int32); TestScalar <UInt32>(AttributeTypes.UInt32); TestScalar <Int64>(AttributeTypes.Int64); TestScalar <UInt64>(AttributeTypes.UInt64); TestScalar <Single>(AttributeTypes.Single); TestScalar <Double>(AttributeTypes.Double); TestScalar <Decimal>(AttributeTypes.Decimal); TestScalar <Boolean>(AttributeTypes.Boolean); TestScalar <DateTime>(AttributeTypes.DateTime); TestScalar <String>(AttributeTypes.String); Assert.AreEqual(new AttributeType("test", typeof(string)).GetDefault(), string.Empty); TestScalar <Uri>(AttributeTypes.Uri); Assert.Null(new AttributeType("test", typeof(Uri)).GetDefault()); TestScalar <DomNode>(AttributeTypes.Reference); Assert.Null(new AttributeType("test", typeof(DomNode)).GetDefault()); TestArray <SByte>(AttributeTypes.Int8Array); TestArray <Byte>(AttributeTypes.UInt8Array); TestArray <Int16>(AttributeTypes.Int16Array); TestArray <UInt16>(AttributeTypes.UInt16Array); TestArray <Int32>(AttributeTypes.Int32Array); TestArray <UInt32>(AttributeTypes.UInt32Array); TestArray <Int64>(AttributeTypes.Int64Array); TestArray <UInt64>(AttributeTypes.UInt64Array); TestArray <Single>(AttributeTypes.SingleArray); TestArray <Double>(AttributeTypes.DoubleArray); TestArray <Decimal>(AttributeTypes.DecimalArray); TestArray <Boolean>(AttributeTypes.BooleanArray); TestArray <String>(AttributeTypes.StringArray); }