~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/XmlEditor/Test/Schema/XsdSchemaTestFixture.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
5
using System.Xml;
 
6
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
 
7
using ICSharpCode.XmlEditor;
 
8
using NUnit.Framework;
 
9
using XmlEditor.Tests.Utils;
 
10
 
 
11
namespace XmlEditor.Tests.Schema
 
12
{
 
13
        /// <summary>
 
14
        /// Tests the xsd schema.
 
15
        /// </summary>
 
16
        [TestFixture]
 
17
        public class XsdSchemaTestFixture
 
18
        {
 
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;
 
37
                
 
38
                string namespaceURI = "http://www.w3.org/2001/XMLSchema";
 
39
                string prefix = "xs";
 
40
                
 
41
                [TestFixtureSetUp]
 
42
                public void FixtureInit()
 
43
                {
 
44
                        schemaCompletion = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
 
45
                        
 
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));
 
51
                        
 
52
                        mixedAttributeValues = schemaCompletion.GetAttributeValueCompletion(choicePath, "mixed");
 
53
 
 
54
                        choicePath.AddElement(new QualifiedName("choice", namespaceURI, prefix));
 
55
                        
 
56
                        // Get choice element info.
 
57
                        choiceAttributes = schemaCompletion.GetAttributeCompletion(choicePath);
 
58
                        maxOccursAttributeValues = schemaCompletion.GetAttributeValueCompletion(choicePath, "maxOccurs");
 
59
                        
 
60
                        // Set up element path.
 
61
                        elementPath = new XmlElementPath();
 
62
                        elementPath.AddElement(new QualifiedName("schema", namespaceURI, prefix));
 
63
                        
 
64
                        elementFormDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "elementFormDefault");
 
65
                        blockDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "blockDefault");
 
66
                        finalDefaultAttributeValues = schemaCompletion.GetAttributeValueCompletion(elementPath, "finalDefault");
 
67
                        
 
68
                        elementPath.AddElement(new QualifiedName("element", namespaceURI, prefix));
 
69
                                
 
70
                        // Get element attribute info.
 
71
                        elementAttributes = schemaCompletion.GetAttributeCompletion(elementPath);
 
72
 
 
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));
 
78
                        
 
79
                        // Get child elements.
 
80
                        simpleEnumElements = schemaCompletion.GetChildElementCompletion(simpleEnumPath);
 
81
 
 
82
                        // Set up enum path.
 
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));
 
88
                        
 
89
                        // Get attributes.
 
90
                        enumAttributes = schemaCompletion.GetAttributeCompletion(enumPath);
 
91
                        
 
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));
 
98
                
 
99
                        // Get child elements of the xs:all element.
 
100
                        allElementChildElements = schemaCompletion.GetChildElementCompletion(allElementPath);
 
101
                        
 
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));
 
109
                        
 
110
                        // Get the xs:all annotation child element.
 
111
                        allElementAnnotationChildElements = schemaCompletion.GetChildElementCompletion(allElementAnnotationPath);
 
112
                }
 
113
                
 
114
                [Test]
 
115
                public void ChoiceHasAttributes()
 
116
                {
 
117
                        Assert.IsTrue(choiceAttributes.Count > 0, "Should have at least one attribute.");
 
118
                }
 
119
                
 
120
                [Test]
 
121
                public void ChoiceHasMinOccursAttribute()
 
122
                {
 
123
                        Assert.IsTrue(choiceAttributes.Contains("minOccurs"),
 
124
                                      "Attribute minOccurs missing.");
 
125
                }
 
126
                
 
127
                [Test]
 
128
                public void ChoiceHasMaxOccursAttribute()
 
129
                {
 
130
                        Assert.IsTrue(choiceAttributes.Contains("maxOccurs"),
 
131
                                      "Attribute maxOccurs missing.");
 
132
                }
 
133
                
 
134
                /// <summary>
 
135
                /// Tests that prohibited attributes are not added to the completion data.
 
136
                /// </summary>
 
137
                [Test]
 
138
                public void ChoiceDoesNotHaveNameAttribute()
 
139
                {
 
140
                        Assert.IsFalse(choiceAttributes.Contains("name"),
 
141
                                       "Attribute name should not exist.");
 
142
                }
 
143
                
 
144
                /// <summary>
 
145
                /// Tests that prohibited attributes are not added to the completion data.
 
146
                /// </summary>
 
147
                [Test]
 
148
                public void ChoiceDoesNotHaveRefAttribute()
 
149
                {
 
150
                        Assert.IsFalse(choiceAttributes.Contains("ref"),
 
151
                                       "Attribute ref should not exist.");
 
152
                }       
 
153
                
 
154
                /// <summary>
 
155
                /// Duplicate attribute test.
 
156
                /// </summary>
 
157
                [Test]
 
158
                public void ElementNameAttributeAppearsOnce()
 
159
                {
 
160
                        int nameAttributeCount = elementAttributes.GetOccurrences("name");
 
161
                        Assert.AreEqual(1, nameAttributeCount, "Should be only one name attribute.");
 
162
                }
 
163
                
 
164
                [Test]
 
165
                public void ElementHasIdAttribute()
 
166
                {
 
167
                        Assert.IsTrue(elementAttributes.Contains("id"), 
 
168
                                      "id attribute missing.");
 
169
                }               
 
170
                
 
171
                [Test]
 
172
                public void SimpleRestrictionTypeHasEnumChildElement()
 
173
                {
 
174
                        Assert.IsTrue(simpleEnumElements.Contains("xs:enumeration"),
 
175
                                      "enumeration element missing.");                  
 
176
                }
 
177
                
 
178
                [Test]
 
179
                public void EnumHasValueAttribute()
 
180
                {
 
181
                        Assert.IsTrue(enumAttributes.Contains("value"),
 
182
                                      "Attribute value missing.");                      
 
183
                }
 
184
                
 
185
                [Test]
 
186
                public void ElementFormDefaultAttributeHasValueQualified()
 
187
                {
 
188
                        Assert.IsTrue(elementFormDefaultAttributeValues.Contains("qualified"),
 
189
                                      "Attribute value 'qualified' missing.");
 
190
                }
 
191
                
 
192
                [Test]
 
193
                public void BlockDefaultAttributeHasValueAll()
 
194
                {
 
195
                        Assert.IsTrue(blockDefaultAttributeValues.Contains("#all"),
 
196
                                      "Attribute value '#all' missing.");
 
197
                }               
 
198
                
 
199
                [Test]
 
200
                public void BlockDefaultAttributeHasValueExtension()
 
201
                {
 
202
                        Assert.IsTrue(blockDefaultAttributeValues.Contains("extension"),
 
203
                                      "Attribute value 'extension' missing.");
 
204
                }               
 
205
                
 
206
                [Test]
 
207
                public void FinalDefaultAttributeHasValueList()
 
208
                {
 
209
                        Assert.IsTrue(finalDefaultAttributeValues.Contains("list"),
 
210
                                      "Attribute value 'list' missing.");
 
211
                }
 
212
                
 
213
                /// <summary>
 
214
                /// xs:boolean tests.
 
215
                /// </summary>
 
216
                [Test]
 
217
                public void MixedAttributeHasValueTrue()
 
218
                {
 
219
                        Assert.IsTrue(mixedAttributeValues.Contains("true"),
 
220
                                      "Attribute value 'true' missing.");
 
221
                }
 
222
                
 
223
                [Test]
 
224
                public void MaxOccursAttributeHasValueUnbounded()
 
225
                {
 
226
                        Assert.IsTrue(maxOccursAttributeValues.Contains("unbounded"),
 
227
                                      "Attribute value 'unbounded' missing.");
 
228
                }       
 
229
                                
 
230
                [Test]
 
231
                public void AllElementHasAnnotationChildElement()
 
232
                {
 
233
                        Assert.IsTrue(allElementChildElements.Contains("xs:annotation"),
 
234
                                      "Should have an annotation child element.");
 
235
                }
 
236
                
 
237
                [Test]
 
238
                public void AllElementHasElementChildElement()
 
239
                {
 
240
                        Assert.IsTrue(allElementChildElements.Contains("xs:element"),
 
241
                                      "Should have an child element called 'element'.");
 
242
                }
 
243
                
 
244
                [Test]
 
245
                public void AllElementAnnotationHasDocumentationChildElement()
 
246
                {
 
247
                        Assert.IsTrue(allElementAnnotationChildElements.Contains("xs:documentation"),
 
248
                                      "Should have documentation child element.");
 
249
                }
 
250
        }
 
251
}