~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.XmlEditor/Tests/FindSchemaObject/ElementReferenceSelectedTestFixture.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using MonoDevelop.Ide.CodeCompletion;
 
3
using MonoDevelop.XmlEditor;
 
4
using NUnit.Framework;
 
5
using System;
 
6
using System.IO;
 
7
using System.Xml.Schema;
 
8
using MonoDevelop.XmlEditor.Tests.Schema;
 
9
using MonoDevelop.XmlEditor.Tests.Utils;
 
10
 
 
11
namespace MonoDevelop.XmlEditor.Tests.FindSchemaObject
 
12
{
 
13
        /// <summary>
 
14
        /// Tests that an xs:element/@ref is located in the schema.
 
15
        /// </summary>
 
16
        [TestFixture]
 
17
        public class ElementReferenceSelectedTestFixture : SchemaTestFixtureBase
 
18
        {
 
19
                XmlSchemaAttribute schemaAttribute;
 
20
                XmlSchemaElement referencedSchemaElement;
 
21
                
 
22
                public override void FixtureInit()
 
23
                {
 
24
                        XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
 
25
                        schemas.Add(SchemaCompletionData);
 
26
                        XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema());
 
27
                        schemas.Add(xsdSchemaCompletionData);
 
28
                        XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty, null);
 
29
                        
 
30
                        string xml = GetSchema();
 
31
                        schemaAttribute = (XmlSchemaAttribute)XmlEditorView.GetSchemaObjectSelected(xml, xml.IndexOf("ref=\"name"), provider, SchemaCompletionData);
 
32
                        
 
33
                        int index = xml.IndexOf("ref=\"name");
 
34
                        index = xml.IndexOf('n', index);
 
35
                        referencedSchemaElement = (XmlSchemaElement)XmlEditorView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData);
 
36
                }
 
37
                
 
38
                [Test]
 
39
                public void AttributeName()
 
40
                {
 
41
                        Assert.AreEqual("ref", schemaAttribute.QualifiedName.Name);
 
42
                }               
 
43
                
 
44
                [Test]
 
45
                public void ReferencedElementName()
 
46
                {
 
47
                        Assert.AreEqual("name", referencedSchemaElement.QualifiedName.Name);
 
48
                }
 
49
                
 
50
                protected override string GetSchema()
 
51
                {
 
52
                        return "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"http://www.w3schools.com\"  xmlns=\"http://www.w3schools.com\">\r\n" +
 
53
                                "\r\n" +
 
54
                                "<!-- definition of simple elements -->\r\n" +
 
55
                                "<xs:element name=\"name\" type=\"xs:string\"/>\r\n" +
 
56
                                "<xs:element name=\"address\" type=\"xs:string\"/>\r\n" +
 
57
                                "\r\n" +
 
58
                                "<!-- definition of complex elements -->\r\n" +
 
59
                                "<xs:element name=\"shipto\">\r\n" +
 
60
                                " <xs:complexType>\r\n" +
 
61
                                "  <xs:sequence>\r\n" +
 
62
                                "   <xs:element ref=\"name\"/>\r\n" +
 
63
                                "   <xs:element ref=\"address\"/>\r\n" +
 
64
                                "  </xs:sequence>\r\n" +
 
65
                                "  <xs:attribute name=\"address\"/>\r\n" +
 
66
                                " </xs:complexType>\r\n" +
 
67
                                "</xs:element>\r\n" +
 
68
                                "\r\n" +
 
69
                                "<xs:element name=\"shiporder\">\r\n" +
 
70
                                " <xs:complexType>\r\n" +
 
71
                                "  <xs:sequence>\r\n" +
 
72
                                "   <xs:element ref=\"shipto\"/>\r\n" +
 
73
                                "  </xs:sequence>\r\n" +
 
74
                                "  <xs:attribute name=\"id\"/>\r\n" +
 
75
                                " </xs:complexType>\r\n" +
 
76
                                "</xs:element>\r\n" +
 
77
                                "\r\n" +
 
78
                                "</xs:schema>";
 
79
                }
 
80
        }
 
81
}