2 // Tests for the length facets.
\r
5 // David Sheldon <dave-mono@earth.li>
\r
11 using System.Xml.Schema;
\r
12 using NUnit.Framework;
\r
14 namespace MonoTests.System.Xml
\r
17 public class XmlSchemaLengthFacetTests : Assertion
\r
21 public void TestValidCombinations () {
\r
22 CreateSimpletypeLength("5","-","-", true);
\r
23 CreateSimpletypeLength("5","1","-", false);
\r
24 CreateSimpletypeLength("5","-","1", false);
\r
26 CreateSimpletypeLength("-","1","10", true);
\r
27 CreateSimpletypeLength("-","10","1", false);
\r
28 CreateSimpletypeLength("-","1","-", true);
\r
29 CreateSimpletypeLength("-","-","1", true);
\r
31 CreateSimpletypeLength("-5","-","-", false);
\r
32 CreateSimpletypeLength("-","-1","-", false);
\r
33 CreateSimpletypeLength("-","-","-1", false);
\r
35 CreateSimpletypeLength("5.4","-","-", false);
\r
36 CreateSimpletypeLength("-","1.0","-", false);
\r
37 CreateSimpletypeLength("-","-","1.3", false);
\r
39 CreateSimpletypeLength("+5","-","-", true);
\r
40 CreateSimpletypeLength("-","+1","-", true);
\r
41 CreateSimpletypeLength("-","-","+1", true);
\r
44 private void CreateSimpletypeLength(string length, string minLength, string maxLength, bool expected) {
\r
47 XmlSchema schema = new XmlSchema();
\r
49 XmlSchemaSimpleType testType = new XmlSchemaSimpleType();
\r
50 testType.Name = "TestType";
\r
52 XmlSchemaSimpleTypeRestriction testTypeRestriction = new XmlSchemaSimpleTypeRestriction();
\r
53 testTypeRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
\r
55 if (length != "-") {
\r
56 XmlSchemaLengthFacet _length = new XmlSchemaLengthFacet();
\r
57 _length.Value = length;
\r
58 testTypeRestriction.Facets.Add(_length);
\r
60 if (minLength != "-") {
\r
61 XmlSchemaMinLengthFacet _minLength = new XmlSchemaMinLengthFacet();
\r
62 _minLength.Value = minLength;
\r
63 testTypeRestriction.Facets.Add(_minLength);
\r
65 if (maxLength != "-") {
\r
66 XmlSchemaMaxLengthFacet _maxLength = new XmlSchemaMaxLengthFacet();
\r
67 _maxLength.Value = maxLength;
\r
68 testTypeRestriction.Facets.Add(_maxLength);
\r
71 testType.Content = testTypeRestriction;
\r
72 schema.Items.Add(testType);
\r
73 schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
\r
76 (passed ? "Test passed, should have failed" : "Test failed, should have passed") +
\r
77 ": " + length + " " + minLength + " " + maxLength,
\r
78 expected == passed);
\r
84 private void ValidationCallbackOne(object sender, ValidationEventArgs args) {
\r