summaryrefslogtreecommitdiff
path: root/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaAssertion.cs
blob: d614b39bf8e814a85594fb0950519d3f3117efaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// System.Xml.XmlSchemaAssertion.cs
//
// Author:
//   Atsushi Enomoto <atsushi@ximian.com>
//
// (C) 2004 Atsushi Enomoto
//

using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using NUnit.Framework;

namespace MonoTests.System.Xml
{
	public class XmlSchemaAssertion
	{
		public static XmlSchema GetSchema (string path)
		{
			XmlTextReader reader = new XmlTextReader (path);
			XmlSchema schema = XmlSchema.Read (reader, null);
			reader.Close ();
			return schema;
		}

		public static XmlQualifiedName QName (string name, string ns)
		{
			return new XmlQualifiedName (name, ns);
		}

		public static void AssertElement (XmlSchemaElement element,
			string name, XmlQualifiedName refName, string id,
			XmlQualifiedName schemaTypeName, XmlSchemaType schemaType)
		{
			Assert.IsNotNull (element);
			Assert.AreEqual (name, element.Name);
			Assert.AreEqual (refName, element.RefName);
			Assert.AreEqual (id, element.Id);
			Assert.AreEqual (schemaTypeName, element.SchemaTypeName);
			Assert.AreEqual (schemaType, element.SchemaType);
		}

		public static void AssertElementEx (XmlSchemaElement element,
			XmlSchemaDerivationMethod block, XmlSchemaDerivationMethod final,
			string defaultValue, string fixedValue,
			XmlSchemaForm form, bool isAbstract, bool isNillable,
			XmlQualifiedName substGroup)
		{
			Assert.IsNotNull (element);
			Assert.AreEqual (block, element.Block);
			Assert.AreEqual (final, element.Final);
			Assert.AreEqual (defaultValue, element.DefaultValue);
			Assert.AreEqual (fixedValue, element.FixedValue);
			Assert.AreEqual (form, element.Form);
			Assert.AreEqual (isAbstract, element.IsAbstract);
			Assert.AreEqual (isNillable, element.IsNillable);
			Assert.AreEqual (substGroup, element.SubstitutionGroup);
		}

		public static void AssertCompiledComplexType (XmlSchemaComplexType cType,
			XmlQualifiedName name,
			int attributesCount, int attributeUsesCount,
			bool existsAny, Type contentModelType,
			bool hasContentTypeParticle,
			XmlSchemaContentType contentType)
		{
			Assert.IsNotNull (cType);
			Assert.AreEqual (name.Name, cType.Name);
			Assert.AreEqual (name, cType.QualifiedName);
			Assert.AreEqual (attributesCount, cType.Attributes.Count);
			Assert.AreEqual (attributeUsesCount, cType.AttributeUses.Count);
			Assert.IsTrue (existsAny == (cType.AttributeWildcard != null));
			if (contentModelType == null)
				Assert.IsNull (cType.ContentModel);
			else
				Assert.AreEqual (contentModelType, cType.ContentModel.GetType ());
			Assert.AreEqual (hasContentTypeParticle, cType.ContentTypeParticle != null);
			Assert.AreEqual (contentType, cType.ContentType);
		}

		public static void AssertCompiledComplexContentExtension (XmlSchemaComplexContentExtension xccx,
			int attributeCount, bool hasAnyAttribute, XmlQualifiedName baseTypeName)
		{
			Assert.IsNotNull (xccx);
			Assert.AreEqual (attributeCount, xccx.Attributes.Count);
			Assert.AreEqual (hasAnyAttribute, xccx.AnyAttribute != null);
			Assert.AreEqual (baseTypeName, xccx.BaseTypeName);
			Assert.IsNotNull (xccx.Particle);
		}

		public static void AssertCompiledElement (XmlSchemaElement element,
			XmlQualifiedName name, object elementType)
		{
			Assert.IsNotNull (element);
			Assert.AreEqual (name, element.QualifiedName);
			Assert.AreEqual (elementType, element.ElementType);
		}

	}
}