XmlSchemaLengthFacetTests.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Tests for the length facets.
  3. //
  4. // Author:
  5. // David Sheldon <[email protected]>
  6. //
  7. //
  8. using System;
  9. using System.Xml;
  10. using System.Xml.Schema;
  11. using NUnit.Framework;
  12. namespace MonoTests.System.Xml
  13. {
  14. [TestFixture]
  15. public class XmlSchemaLengthFacetTests : Assertion
  16. {
  17. [Test]
  18. public void TestValidCombinations () {
  19. CreateSimpletypeLength("5","-","-", true);
  20. CreateSimpletypeLength("5","1","-", false);
  21. CreateSimpletypeLength("5","-","1", false);
  22. CreateSimpletypeLength("-","1","10", true);
  23. CreateSimpletypeLength("-","10","1", false);
  24. CreateSimpletypeLength("-","1","-", true);
  25. CreateSimpletypeLength("-","-","1", true);
  26. CreateSimpletypeLength("-5","-","-", false);
  27. CreateSimpletypeLength("-","-1","-", false);
  28. CreateSimpletypeLength("-","-","-1", false);
  29. CreateSimpletypeLength("5.4","-","-", false);
  30. CreateSimpletypeLength("-","1.0","-", false);
  31. CreateSimpletypeLength("-","-","1.3", false);
  32. CreateSimpletypeLength("+5","-","-", true);
  33. CreateSimpletypeLength("-","+1","-", true);
  34. CreateSimpletypeLength("-","-","+1", true);
  35. }
  36. private void CreateSimpletypeLength(string length, string minLength, string maxLength, bool expected) {
  37. passed = true;
  38. XmlSchema schema = new XmlSchema();
  39. XmlSchemaSimpleType testType = new XmlSchemaSimpleType();
  40. testType.Name = "TestType";
  41. XmlSchemaSimpleTypeRestriction testTypeRestriction = new XmlSchemaSimpleTypeRestriction();
  42. testTypeRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
  43. if (length != "-") {
  44. XmlSchemaLengthFacet _length = new XmlSchemaLengthFacet();
  45. _length.Value = length;
  46. testTypeRestriction.Facets.Add(_length);
  47. }
  48. if (minLength != "-") {
  49. XmlSchemaMinLengthFacet _minLength = new XmlSchemaMinLengthFacet();
  50. _minLength.Value = minLength;
  51. testTypeRestriction.Facets.Add(_minLength);
  52. }
  53. if (maxLength != "-") {
  54. XmlSchemaMaxLengthFacet _maxLength = new XmlSchemaMaxLengthFacet();
  55. _maxLength.Value = maxLength;
  56. testTypeRestriction.Facets.Add(_maxLength);
  57. }
  58. testType.Content = testTypeRestriction;
  59. schema.Items.Add(testType);
  60. schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
  61. Assert(
  62. (passed ? "Test passed, should have failed" : "Test failed, should have passed") +
  63. ": " + length + " " + minLength + " " + maxLength,
  64. expected == passed);
  65. }
  66. bool passed = true;
  67. private void ValidationCallbackOne(object sender, ValidationEventArgs args) {
  68. passed = false;
  69. }
  70. }
  71. }