2 // Tests for the properties of the builtin types.
5 // David Sheldon <dave-mono@earth.li>
11 using System
.Xml
.Schema
;
13 using NUnit
.Framework
;
15 namespace MonoTests
.System
.Xml
18 public class XmlSchemaBuiltInDatatypeTests
: Assertion
22 public void TestWhiteSpaceCollapse () {
23 WhiteSpaceTest("date", "2003-10-10");
24 WhiteSpaceTest("decimal", "2003.10");
25 WhiteSpaceTest("integer", "0004");
26 WhiteSpaceTest("float", "1.3");
27 WhiteSpaceTest("boolean", "true");
28 WhiteSpaceTest("double", "2.3");
29 WhiteSpaceTest("time", "12:34:56");
30 WhiteSpaceTest("duration", "P1347Y");
31 WhiteSpaceTest("dateTime", "2003-10-10T12:34:56.78");
32 WhiteSpaceTest("gYearMonth", "2003-10");
33 WhiteSpaceTest("gYear", "2003");
34 WhiteSpaceTest("gMonthDay", "--12-12"); //
35 WhiteSpaceTest("gMonth", "--12--"); // These three will fail, due to
36 WhiteSpaceTest("gDay", "---12"); // bug 52274
37 WhiteSpaceTest("hexBinary", "0fB7");
41 /* Takes a type name, and a valid example of that type,
42 Creates a schema consisting of a single element of that
43 type, and validates a bit of xml containing the valid
44 value, with whitespace against that schema.
46 FIXME: Really we want to test the value of whitespace more
47 directly that by creating a schema then parsing a string.
51 public void WhiteSpaceTest(string type
, string valid
) {
53 XmlSchema schema
= new XmlSchema();
55 schema
.TargetNamespace
= "http://example.com/testCase";
56 XmlSchemaElement element
= new XmlSchemaElement();
58 element
.SchemaTypeName
= new XmlQualifiedName(type
, "http://www.w3.org/2001/XMLSchema");
59 schema
.Items
.Add(element
);
60 schema
.Compile(new ValidationEventHandler(ValidationCallbackOne
));
62 XmlValidatingReader vr
= new XmlValidatingReader(new XmlTextReader(new StringReader("<a xmlns='http://example.com/testCase'>\n\n"+valid
+"\n\n</a>" )));
63 vr
.Schemas
.Add(schema
);
64 vr
.ValidationType
= ValidationType
.Schema
;
65 // vr.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
69 Assert(type
+ " doesn't collapse whitespace: " + (errorInfo
!= null ? errorInfo
.Message
: null), passed
);
73 ValidationEventArgs errorInfo
;
75 public void ValidationCallbackOne(object sender
, ValidationEventArgs args
) {