~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/XmlEditor/Test/FindSchemaObject/AttributeTypeSelectedTestFixture.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 ICSharpCode.XmlEditor;
 
5
using NUnit.Framework;
 
6
using System;
 
7
using System.IO;
 
8
using System.Xml.Schema;
 
9
using XmlEditor.Tests.Schema;
 
10
using XmlEditor.Tests.Utils;
 
11
 
 
12
namespace XmlEditor.Tests.FindSchemaObject
 
13
{
 
14
        /// <summary>
 
15
        /// Tests that a xs:attribute/@type can be located in the schema.
 
16
        /// </summary>
 
17
        [TestFixture]
 
18
        public class AttributeTypeSelectedTestFixture : SchemaTestFixtureBase
 
19
        {
 
20
                XmlSchemaSimpleType schemaSimpleType;
 
21
                
 
22
                public override void FixtureInit()
 
23
                {
 
24
                        XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
 
25
                        schemas.Add(SchemaCompletion);
 
26
                        XmlSchemaCompletion xsdSchemaCompletionData = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
 
27
                        schemas.Add(xsdSchemaCompletionData);
 
28
 
 
29
                        string xml = GetSchema();
 
30
                        int index = xml.IndexOf("type=\"dir\"/>");
 
31
                        index = xml.IndexOf("dir", index);
 
32
                        XmlSchemaDefinition schemaDefinition = new XmlSchemaDefinition(schemas, SchemaCompletion);
 
33
                        schemaSimpleType = (XmlSchemaSimpleType)schemaDefinition.GetSelectedSchemaObject(xml, index);
 
34
                }
 
35
                
 
36
                [Test]
 
37
                public void SimpleTypeName()
 
38
                {
 
39
                        Assert.AreEqual("dir", schemaSimpleType.QualifiedName.Name);
 
40
                }               
 
41
                
 
42
                protected override string GetSchema()
 
43
                {
 
44
                        return "<xs:schema version=\"1.0\" xml:lang=\"en\"\r\n" +
 
45
                                        "    xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" +
 
46
                                        "    targetNamespace=\"http://foo/xhtml\"\r\n" +
 
47
                                        "    xmlns=\"http://foo/xhtml\"\r\n" +
 
48
                                        "    elementFormDefault=\"qualified\">\r\n" +
 
49
                                        "  <xs:element name=\"html\">\r\n" +
 
50
                                        "    <xs:complexType>\r\n" +
 
51
                                        "      <xs:sequence>\r\n" +
 
52
                                        "        <xs:element ref=\"head\"/>\r\n" +
 
53
                                        "        <xs:element ref=\"body\"/>\r\n" +
 
54
                                        "      </xs:sequence>\r\n" +
 
55
                                        "      <xs:attributeGroup ref=\"i18n\"/>\r\n" +
 
56
                                        "      <xs:attribute name=\"id\" type=\"dir\"/>\r\n" +
 
57
                                        "    </xs:complexType>\r\n" +
 
58
                                        "  </xs:element>\r\n" +
 
59
                                        "\r\n" +
 
60
                                        "  <xs:element name=\"head\" type=\"xs:string\"/>\r\n" +
 
61
                                        "  <xs:element name=\"body\" type=\"xs:string\"/>\r\n" +
 
62
                                        "\r\n" +
 
63
                                        "      <xs:simpleType name=\"dir\">\r\n" +
 
64
                                        "        <xs:restriction base=\"xs:token\">\r\n" +
 
65
                                        "          <xs:enumeration value=\"ltr\"/>\r\n" +
 
66
                                        "          <xs:enumeration value=\"rtl\"/>\r\n" +
 
67
                                        "        </xs:restriction>\r\n" +
 
68
                                        "      </xs:simpleType>\r\n" +
 
69
                                        "</xs:schema>";
 
70
                }
 
71
        }
 
72
}