~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/XmlEditor/Test/Tree/ExplicitNamespaceTestFixture.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;
 
9
using XmlEditor.Tests.Utils;
 
10
 
 
11
namespace XmlEditor.Tests.Tree
 
12
{
 
13
        /// <summary>
 
14
        /// Tests that a child element is added to the XML document by the
 
15
        /// XmlTreeEditor with the correct namespace.
 
16
        /// </summary>
 
17
        [TestFixture]
 
18
        public class ExplicitNamespaceTestFixture : XmlTreeViewTestFixtureBase
 
19
        {
 
20
                XmlElement bodyElement;
 
21
                        
 
22
                [SetUp]
 
23
                public void Init()
 
24
                {
 
25
                        base.InitFixture();
 
26
                        XmlNamespaceManager nsManager = new XmlNamespaceManager(editor.Document.NameTable);
 
27
                        nsManager.AddNamespace("h", "http://www.w3.org/1999/xhtml");
 
28
                        bodyElement = (XmlElement)editor.Document.SelectSingleNode("/h:html/h:body", nsManager);
 
29
                        mockXmlTreeView.SelectedElement = bodyElement;
 
30
                        mockXmlTreeView.SelectedNewElementsToReturn.Add("h1");
 
31
 
 
32
                        editor.AppendChildElement();
 
33
                }
 
34
                
 
35
                [Test]
 
36
                public void HeadlineElementNamespace()
 
37
                {
 
38
                        XmlElement element = (XmlElement)bodyElement.FirstChild;
 
39
                        Assert.AreEqual("http://www.w3.org/1999/xhtml", element.NamespaceURI);
 
40
                }
 
41
                
 
42
                [Test]
 
43
                public void InsertBeforeDifferentNamespaceElementSelected()
 
44
                {
 
45
                        XmlNamespaceManager nsManager = new XmlNamespaceManager(editor.Document.NameTable);
 
46
                        nsManager.AddNamespace("a", "http://asp.net");
 
47
                        XmlElement buttonElement = (XmlElement)editor.Document.SelectSingleNode("//a:button", nsManager);
 
48
                        XmlElement headElement = (XmlElement)buttonElement.ParentNode;
 
49
                        mockXmlTreeView.SelectedElement = buttonElement;
 
50
                        mockXmlTreeView.SelectedNewElementsToReturn.Clear();
 
51
                        mockXmlTreeView.SelectedNewElementsToReturn.Add("title");
 
52
                        
 
53
                        editor.InsertElementBefore();
 
54
                        
 
55
                        XmlElement titleElement = (XmlElement)headElement.FirstChild;
 
56
                        Assert.AreEqual(2, headElement.ChildNodes.Count);
 
57
                        Assert.AreEqual("title", titleElement.LocalName);
 
58
                        Assert.AreEqual("http://www.w3.org/1999/xhtml", titleElement.NamespaceURI);
 
59
                }
 
60
                
 
61
                [Test]
 
62
                public void InsertAfterDifferentNamespaceElementSelected()
 
63
                {
 
64
                        XmlNamespaceManager nsManager = new XmlNamespaceManager(editor.Document.NameTable);
 
65
                        nsManager.AddNamespace("a", "http://asp.net");
 
66
                        XmlElement buttonElement = (XmlElement)editor.Document.SelectSingleNode("//a:button", nsManager);
 
67
                        XmlElement headElement = (XmlElement)buttonElement.ParentNode;
 
68
                        mockXmlTreeView.SelectedElement = buttonElement;
 
69
                        mockXmlTreeView.SelectedNewElementsToReturn.Clear();
 
70
                        mockXmlTreeView.SelectedNewElementsToReturn.Add("title");
 
71
                        
 
72
                        editor.InsertElementAfter();
 
73
                        
 
74
                        XmlElement titleElement = (XmlElement)headElement.LastChild;
 
75
                        Assert.AreEqual(2, headElement.ChildNodes.Count);
 
76
                        Assert.AreEqual("title", titleElement.LocalName);
 
77
                        Assert.AreEqual("http://www.w3.org/1999/xhtml", titleElement.NamespaceURI);
 
78
                }
 
79
 
 
80
                /// <summary>
 
81
                /// Returns the xhtml strict schema as the default schema.
 
82
                /// </summary>
 
83
                protected override XmlSchemaCompletion DefaultSchemaCompletion {
 
84
                        get { return new XmlSchemaCompletion(ResourceManager.ReadXhtmlStrictSchema()); }
 
85
                }
 
86
                
 
87
                protected override string GetXml()
 
88
                {
 
89
                        return "<html xmlns='http://www.w3.org/1999/xhtml'>\r\n" +
 
90
                                "\t<head>\r\n" +
 
91
                                "\t\t<asp:button xmlns:asp='http://asp.net'/>\r\n" +
 
92
                                "\t</head>\r\n" +
 
93
                                "\t<body>\r\n" +
 
94
                                "\t</body>\r\n" +
 
95
                                "</html>";
 
96
                }
 
97
        }
 
98
}