1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
6
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
7
using ICSharpCode.XmlEditor;
9
using XmlEditor.Tests.Utils;
11
namespace XmlEditor.Tests.Schema
14
/// Tests the xsd schema.
17
public class XsdSchemaTestFixture
19
XmlSchemaCompletion schemaCompletion;
20
XmlElementPath choicePath;
21
XmlElementPath elementPath;
22
XmlElementPath simpleEnumPath;
23
XmlElementPath enumPath;
24
XmlElementPath allElementPath;
25
XmlElementPath allElementAnnotationPath;
26
XmlCompletionItemCollection choiceAttributes;
27
XmlCompletionItemCollection elementAttributes;
28
XmlCompletionItemCollection simpleEnumElements;
29
XmlCompletionItemCollection enumAttributes;
30
XmlCompletionItemCollection elementFormDefaultAttributeValues;
31
XmlCompletionItemCollection blockDefaultAttributeValues;
32
XmlCompletionItemCollection finalDefaultAttributeValues;
33
XmlCompletionItemCollection mixedAttributeValues;
34
XmlCompletionItemCollection maxOccursAttributeValues;
35
XmlCompletionItemCollection allElementChildElements;
36
XmlCompletionItemCollection allElementAnnotationChildElements;
38
string namespaceURI = "http://www.w3.org/2001/XMLSchema";
42
public void FixtureInit()
44
schemaCompletion = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
46
// Set up choice element's path.
47
choicePath = new XmlElementPath();
48
choicePath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
49
choicePath.AddElement(new QualifiedName("element", namespaceURI, prefix));
50
choicePath.AddElement(new QualifiedName("complexType", namespaceURI, prefix));
52
mixedAttributeValues = schemaCompletion.GetAttributeValueCompletion(choicePath, "mixed");
54
choicePath.AddElement(new QualifiedName("choice", namespaceURI, prefix));
56
// Get choice element info.
57
choiceAttributes = schemaCompletion.GetAttributeCompletion(choicePath);
58
maxOccursAttributeValues = schemaCompletion.GetAttributeValueCompletion(choicePath, "maxOccurs");
60
// Set up element path.
61
elementPath = new XmlElementPath();
62
elementPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
64
elementFormDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "elementFormDefault");
65
blockDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "blockDefault");
66
finalDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "finalDefault");
68
elementPath.AddElement(new QualifiedName("element", namespaceURI, prefix));
70
// Get element attribute info.
71
elementAttributes = schemaCompletion.GetAttributeCompletion(elementPath);
73
// Set up simple enum type path.
74
simpleEnumPath = new XmlElementPath();
75
simpleEnumPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
76
simpleEnumPath.AddElement(new QualifiedName("simpleType", namespaceURI, prefix));
77
simpleEnumPath.AddElement(new QualifiedName("restriction", namespaceURI, prefix));
79
// Get child elements.
80
simpleEnumElements = schemaCompletion.GetChildElementCompletion(simpleEnumPath);
83
enumPath = new XmlElementPath();
84
enumPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
85
enumPath.AddElement(new QualifiedName("simpleType", namespaceURI, prefix));
86
enumPath.AddElement(new QualifiedName("restriction", namespaceURI, prefix));
87
enumPath.AddElement(new QualifiedName("enumeration", namespaceURI, prefix));
90
enumAttributes = schemaCompletion.GetAttributeCompletion(enumPath);
92
// Set up xs:all path.
93
allElementPath = new XmlElementPath();
94
allElementPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
95
allElementPath.AddElement(new QualifiedName("element", namespaceURI, prefix));
96
allElementPath.AddElement(new QualifiedName("complexType", namespaceURI, prefix));
97
allElementPath.AddElement(new QualifiedName("all", namespaceURI, prefix));
99
// Get child elements of the xs:all element.
100
allElementChildElements = schemaCompletion.GetChildElementCompletion(allElementPath);
102
// Set up the path to the annotation element that is a child of xs:all.
103
allElementAnnotationPath = new XmlElementPath();
104
allElementAnnotationPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
105
allElementAnnotationPath.AddElement(new QualifiedName("element", namespaceURI, prefix));
106
allElementAnnotationPath.AddElement(new QualifiedName("complexType", namespaceURI, prefix));
107
allElementAnnotationPath.AddElement(new QualifiedName("all", namespaceURI, prefix));
108
allElementAnnotationPath.AddElement(new QualifiedName("annotation", namespaceURI, prefix));
110
// Get the xs:all annotation child element.
111
allElementAnnotationChildElements = schemaCompletion.GetChildElementCompletion(allElementAnnotationPath);
115
public void ChoiceHasAttributes()
117
Assert.IsTrue(choiceAttributes.Count > 0, "Should have at least one attribute.");
121
public void ChoiceHasMinOccursAttribute()
123
Assert.IsTrue(choiceAttributes.Contains("minOccurs"),
124
"Attribute minOccurs missing.");
128
public void ChoiceHasMaxOccursAttribute()
130
Assert.IsTrue(choiceAttributes.Contains("maxOccurs"),
131
"Attribute maxOccurs missing.");
135
/// Tests that prohibited attributes are not added to the completion data.
138
public void ChoiceDoesNotHaveNameAttribute()
140
Assert.IsFalse(choiceAttributes.Contains("name"),
141
"Attribute name should not exist.");
145
/// Tests that prohibited attributes are not added to the completion data.
148
public void ChoiceDoesNotHaveRefAttribute()
150
Assert.IsFalse(choiceAttributes.Contains("ref"),
151
"Attribute ref should not exist.");
155
/// Duplicate attribute test.
158
public void ElementNameAttributeAppearsOnce()
160
int nameAttributeCount = elementAttributes.GetOccurrences("name");
161
Assert.AreEqual(1, nameAttributeCount, "Should be only one name attribute.");
165
public void ElementHasIdAttribute()
167
Assert.IsTrue(elementAttributes.Contains("id"),
168
"id attribute missing.");
172
public void SimpleRestrictionTypeHasEnumChildElement()
174
Assert.IsTrue(simpleEnumElements.Contains("xs:enumeration"),
175
"enumeration element missing.");
179
public void EnumHasValueAttribute()
181
Assert.IsTrue(enumAttributes.Contains("value"),
182
"Attribute value missing.");
186
public void ElementFormDefaultAttributeHasValueQualified()
188
Assert.IsTrue(elementFormDefaultAttributeValues.Contains("qualified"),
189
"Attribute value 'qualified' missing.");
193
public void BlockDefaultAttributeHasValueAll()
195
Assert.IsTrue(blockDefaultAttributeValues.Contains("#all"),
196
"Attribute value '#all' missing.");
200
public void BlockDefaultAttributeHasValueExtension()
202
Assert.IsTrue(blockDefaultAttributeValues.Contains("extension"),
203
"Attribute value 'extension' missing.");
207
public void FinalDefaultAttributeHasValueList()
209
Assert.IsTrue(finalDefaultAttributeValues.Contains("list"),
210
"Attribute value 'list' missing.");
214
/// xs:boolean tests.
217
public void MixedAttributeHasValueTrue()
219
Assert.IsTrue(mixedAttributeValues.Contains("true"),
220
"Attribute value 'true' missing.");
224
public void MaxOccursAttributeHasValueUnbounded()
226
Assert.IsTrue(maxOccursAttributeValues.Contains("unbounded"),
227
"Attribute value 'unbounded' missing.");
231
public void AllElementHasAnnotationChildElement()
233
Assert.IsTrue(allElementChildElements.Contains("xs:annotation"),
234
"Should have an annotation child element.");
238
public void AllElementHasElementChildElement()
240
Assert.IsTrue(allElementChildElements.Contains("xs:element"),
241
"Should have an child element called 'element'.");
245
public void AllElementAnnotationHasDocumentationChildElement()
247
Assert.IsTrue(allElementAnnotationChildElements.Contains("xs:documentation"),
248
"Should have documentation child element.");