Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2111 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
43 changed files with 2919 additions and 50 deletions
@ -0,0 +1,26 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Adds a new text node to selected element.
|
||||||
|
/// </summary>
|
||||||
|
public class AddChildTextNodeCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
XmlTreeViewContainerControl view = Owner as XmlTreeViewContainerControl; |
||||||
|
if (view != null) { |
||||||
|
view.AppendChildTextNode(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interface for the AddAttributeDialog.
|
||||||
|
/// </summary>
|
||||||
|
public interface IAddAttributeDialog : IDisposable |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The attribute names that should be added. These are the
|
||||||
|
/// attribute names that the user selected in the dialog when
|
||||||
|
/// it was closed.
|
||||||
|
/// </summary>
|
||||||
|
string[] AttributeNames {get;} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the dialog.
|
||||||
|
/// </summary>
|
||||||
|
DialogResult ShowDialog(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Interface for the AddElementDialog.
|
||||||
|
/// </summary>
|
||||||
|
public interface IAddElementDialog : IDisposable |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// The element names that should be added. These are the
|
||||||
|
/// element names that the user selected in the dialog when
|
||||||
|
/// it was closed.
|
||||||
|
/// </summary>
|
||||||
|
string[] ElementNames {get;} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the dialog.
|
||||||
|
/// </summary>
|
||||||
|
DialogResult ShowDialog(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Inserts a new text node to after the selected node.
|
||||||
|
/// </summary>
|
||||||
|
public class InsertTextNodeAfterCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
XmlTreeViewContainerControl view = Owner as XmlTreeViewContainerControl; |
||||||
|
if (view != null) { |
||||||
|
view.InsertTextNodeAfter(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,27 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Inserts a new text node to before the selected node.
|
||||||
|
/// </summary>
|
||||||
|
public class InsertTextNodeBeforeCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
XmlTreeViewContainerControl view = Owner as XmlTreeViewContainerControl; |
||||||
|
if (view != null) { |
||||||
|
view.InsertTextNodeBefore(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -0,0 +1,26 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Removes the selected element from the XML tree.
|
||||||
|
/// </summary>
|
||||||
|
public class RemoveElementCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
XmlTreeViewContainerControl view = Owner as XmlTreeViewContainerControl; |
||||||
|
if (view != null) { |
||||||
|
view.RemoveElement(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,26 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using ICSharpCode.Core; |
||||||
|
|
||||||
|
namespace ICSharpCode.XmlEditor |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Removes the currently selected text node from the XML tree.
|
||||||
|
/// </summary>
|
||||||
|
public class RemoveTextNodeCommand : AbstractMenuCommand |
||||||
|
{ |
||||||
|
public override void Run() |
||||||
|
{ |
||||||
|
XmlTreeViewContainerControl view = Owner as XmlTreeViewContainerControl; |
||||||
|
if (view != null) { |
||||||
|
view.RemoveTextNode(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,91 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using System.Xml; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Checks that a text node is added by the XmlTreeEditor as
|
||||||
|
/// a child of the selected element.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class AddChildTextNodeTestFixture : XmlTreeViewTestFixtureBase |
||||||
|
{ |
||||||
|
XmlElement paragraphElement; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
base.InitFixture(); |
||||||
|
paragraphElement = (XmlElement)editor.Document.SelectSingleNode("/html/body/p"); |
||||||
|
mockXmlTreeView.SelectedElement = paragraphElement; |
||||||
|
editor.AddChildTextNode(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ParagraphElementHasChildNodes() |
||||||
|
{ |
||||||
|
Assert.AreEqual(1, paragraphElement.ChildNodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NewTextNodeAdded() |
||||||
|
{ |
||||||
|
XmlNode node = paragraphElement.FirstChild; |
||||||
|
Assert.IsInstanceOfType(typeof(XmlText), node); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsDirty() |
||||||
|
{ |
||||||
|
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AddChildTextNodeWhenNoElementSelected() |
||||||
|
{ |
||||||
|
mockXmlTreeView.SelectedElement = null; |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
editor.AddChildTextNode(); |
||||||
|
Assert.IsFalse(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextNodeAddedToView() |
||||||
|
{ |
||||||
|
Assert.AreEqual(1, mockXmlTreeView.ChildTextNodesAdded.Count); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the xhtml strict schema as the default schema.
|
||||||
|
/// </summary>
|
||||||
|
protected override XmlSchemaCompletionData DefaultSchemaCompletionData { |
||||||
|
get { |
||||||
|
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||||
|
return new XmlSchemaCompletionData(reader); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetXml() |
||||||
|
{ |
||||||
|
return "<html>\r\n" + |
||||||
|
"\t<head>\r\n" + |
||||||
|
"\t\t<title></title>\r\n" + |
||||||
|
"\t</head>\r\n" + |
||||||
|
"\t<body>\r\n" + |
||||||
|
"\t\t<p/>\r\n" + |
||||||
|
"\t</body>\r\n" + |
||||||
|
"</html>"; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,133 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using System.Xml; |
||||||
|
|
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that a text node is inserted after the selected node
|
||||||
|
/// by the XmlTreeEditor.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class InsertTextNodeAfterTestFixture : XmlTreeViewTestFixtureBase |
||||||
|
{ |
||||||
|
XmlElement paragraphElement; |
||||||
|
XmlText textNode; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
base.InitFixture(); |
||||||
|
paragraphElement = (XmlElement)editor.Document.SelectSingleNode("/html/body/p"); |
||||||
|
textNode = (XmlText)paragraphElement.SelectSingleNode("text()"); |
||||||
|
mockXmlTreeView.SelectedTextNode = textNode; |
||||||
|
|
||||||
|
editor.InsertTextNodeAfter(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsDirty() |
||||||
|
{ |
||||||
|
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ParagraphNodeHasTwoChildNodes() |
||||||
|
{ |
||||||
|
Assert.AreEqual(2, paragraphElement.ChildNodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextNodeInserted() |
||||||
|
{ |
||||||
|
XmlText lastTextNode = (XmlText)paragraphElement.LastChild; |
||||||
|
Assert.AreEqual(String.Empty, lastTextNode.Value); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes sure that nothing happens if we try to insert a
|
||||||
|
/// text node when a text node is not already selected.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void NoNodeSelected() |
||||||
|
{ |
||||||
|
mockXmlTreeView.SelectedTextNode = null; |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
editor.InsertTextNodeAfter(); |
||||||
|
ParagraphNodeHasTwoChildNodes(); |
||||||
|
Assert.IsFalse(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextNodeAddedToView() |
||||||
|
{ |
||||||
|
Assert.AreEqual(1, mockXmlTreeView.TextNodesInsertedAfter.Count); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests that we can insert a text node after the
|
||||||
|
/// an element if it is not the root element.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void ElementSelected() |
||||||
|
{ |
||||||
|
mockXmlTreeView.SelectedTextNode = null; |
||||||
|
mockXmlTreeView.SelectedElement = paragraphElement; |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
editor.InsertTextNodeAfter(); |
||||||
|
|
||||||
|
XmlElement bodyElement = (XmlElement)paragraphElement.ParentNode; |
||||||
|
Assert.AreEqual(2, bodyElement.ChildNodes.Count); |
||||||
|
Assert.IsInstanceOfType(typeof(XmlText), bodyElement.LastChild); |
||||||
|
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests that we cannot insert a text node after the
|
||||||
|
/// root element.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void RootElementSelected() |
||||||
|
{ |
||||||
|
mockXmlTreeView.SelectedTextNode = null; |
||||||
|
mockXmlTreeView.SelectedElement = editor.Document.DocumentElement; |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
editor.InsertTextNodeAfter(); |
||||||
|
ParagraphNodeHasTwoChildNodes(); |
||||||
|
Assert.IsFalse(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the xhtml strict schema as the default schema.
|
||||||
|
/// </summary>
|
||||||
|
protected override XmlSchemaCompletionData DefaultSchemaCompletionData { |
||||||
|
get { |
||||||
|
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||||
|
return new XmlSchemaCompletionData(reader); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetXml() |
||||||
|
{ |
||||||
|
return "<html>\r\n" + |
||||||
|
"\t<head>\r\n" + |
||||||
|
"\t\t<title></title>\r\n" + |
||||||
|
"\t</head>\r\n" + |
||||||
|
"\t<body>\r\n" + |
||||||
|
"\t\t<p>text</p>\r\n" + |
||||||
|
"\t</body>\r\n" + |
||||||
|
"</html>"; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,133 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using System.Xml; |
||||||
|
|
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that a text node is inserted before the selected node
|
||||||
|
/// by the XmlTreeEditor.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class InsertTextNodeBeforeTestFixture : XmlTreeViewTestFixtureBase |
||||||
|
{ |
||||||
|
XmlElement paragraphElement; |
||||||
|
XmlText textNode; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
base.InitFixture(); |
||||||
|
paragraphElement = (XmlElement)editor.Document.SelectSingleNode("/html/body/p"); |
||||||
|
textNode = (XmlText)paragraphElement.SelectSingleNode("text()"); |
||||||
|
mockXmlTreeView.SelectedTextNode = textNode; |
||||||
|
|
||||||
|
editor.InsertTextNodeBefore(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsDirty() |
||||||
|
{ |
||||||
|
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ParagraphNodeHasTwoChildNodes() |
||||||
|
{ |
||||||
|
Assert.AreEqual(2, paragraphElement.ChildNodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextNodeInserted() |
||||||
|
{ |
||||||
|
XmlText firstTextNode = (XmlText)paragraphElement.ChildNodes[0]; |
||||||
|
Assert.AreEqual(String.Empty, firstTextNode.Value); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes sure that nothing happens if we try to insert a
|
||||||
|
/// text node when a text node is not already selected.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void NoNodeSelected() |
||||||
|
{ |
||||||
|
mockXmlTreeView.SelectedTextNode = null; |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
editor.InsertTextNodeBefore(); |
||||||
|
ParagraphNodeHasTwoChildNodes(); |
||||||
|
Assert.IsFalse(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextNodeAddedToView() |
||||||
|
{ |
||||||
|
Assert.AreEqual(1, mockXmlTreeView.TextNodesInsertedBefore.Count); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests that we can insert a text node before the
|
||||||
|
/// an element if it is not the root element.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void ElementSelected() |
||||||
|
{ |
||||||
|
mockXmlTreeView.SelectedTextNode = null; |
||||||
|
mockXmlTreeView.SelectedElement = paragraphElement; |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
editor.InsertTextNodeBefore(); |
||||||
|
|
||||||
|
XmlElement bodyElement = (XmlElement)paragraphElement.ParentNode; |
||||||
|
Assert.AreEqual(2, bodyElement.ChildNodes.Count); |
||||||
|
Assert.IsInstanceOfType(typeof(XmlText), bodyElement.FirstChild); |
||||||
|
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests that we cannot insert a text node before the
|
||||||
|
/// root element.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void RootElementSelected() |
||||||
|
{ |
||||||
|
mockXmlTreeView.SelectedTextNode = null; |
||||||
|
mockXmlTreeView.SelectedElement = editor.Document.DocumentElement; |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
editor.InsertTextNodeBefore(); |
||||||
|
ParagraphNodeHasTwoChildNodes(); |
||||||
|
Assert.IsFalse(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the xhtml strict schema as the default schema.
|
||||||
|
/// </summary>
|
||||||
|
protected override XmlSchemaCompletionData DefaultSchemaCompletionData { |
||||||
|
get { |
||||||
|
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||||
|
return new XmlSchemaCompletionData(reader); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetXml() |
||||||
|
{ |
||||||
|
return "<html>\r\n" + |
||||||
|
"\t<head>\r\n" + |
||||||
|
"\t\t<title></title>\r\n" + |
||||||
|
"\t</head>\r\n" + |
||||||
|
"\t<body>\r\n" + |
||||||
|
"\t\t<p>text</p>\r\n" + |
||||||
|
"\t</body>\r\n" + |
||||||
|
"</html>"; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,400 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using System.Windows.Forms; |
||||||
|
using System.Xml; |
||||||
|
|
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests the various menu commands that can be used on the
|
||||||
|
/// Xml Tree (e.g. InsertElementBeforeCommand).
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class MenuCommandsTestFixture |
||||||
|
{ |
||||||
|
DerivedXmlTreeViewContainerControl treeViewContainer; |
||||||
|
XmlDocument doc; |
||||||
|
XmlTreeViewControl treeView; |
||||||
|
XmlElement bodyElement; |
||||||
|
XmlElementTreeNode htmlTreeNode; |
||||||
|
XmlElementTreeNode bodyTreeNode; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
treeViewContainer = new DerivedXmlTreeViewContainerControl(); |
||||||
|
|
||||||
|
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||||
|
XmlSchemaCompletionData xhtmlSchema = new XmlSchemaCompletionData(reader); |
||||||
|
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||||
|
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xhtmlSchema, String.Empty); |
||||||
|
|
||||||
|
treeViewContainer.LoadXml("<html><body></body></html>", provider); |
||||||
|
doc = treeViewContainer.Document; |
||||||
|
treeView = treeViewContainer.TreeView; |
||||||
|
|
||||||
|
htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[0]; |
||||||
|
htmlTreeNode.Expanding(); |
||||||
|
bodyTreeNode = (XmlElementTreeNode)htmlTreeNode.Nodes[0]; |
||||||
|
|
||||||
|
bodyElement = (XmlElement)doc.SelectSingleNode("/html/body"); |
||||||
|
} |
||||||
|
|
||||||
|
[TearDown] |
||||||
|
public void TearDown() |
||||||
|
{ |
||||||
|
if (treeViewContainer != null) { |
||||||
|
treeViewContainer.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nothing should happen if the owner is the XmlTreeViewContainerControl.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void InsertElementBeforeWithUnknownOwner() |
||||||
|
{ |
||||||
|
InsertElementBeforeCommand command = new InsertElementBeforeCommand(); |
||||||
|
command.Owner = this; |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nothing should happen if the owner is null.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void InsertElementBeforeWithNullOwner() |
||||||
|
{ |
||||||
|
InsertElementBeforeCommand command = new InsertElementBeforeCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Here we produce dummy data from our mock AddElementDialog
|
||||||
|
/// and check that the InsertElementBeforeCommand inserts
|
||||||
|
/// the correct element
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void InsertElementBefore() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
treeViewContainer.AddElementDialogElementNamesReturned.Add("head"); |
||||||
|
InsertElementBeforeCommand command = new InsertElementBeforeCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
XmlElement headElement = (XmlElement)doc.SelectSingleNode("/html/head"); |
||||||
|
Assert.IsNotNull(headElement, "Expected a new head element to be inserted."); |
||||||
|
Assert.AreSame(headElement, doc.DocumentElement.FirstChild); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nothing should happen if the owner is null.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void InsertElementAfterWithNullOwner() |
||||||
|
{ |
||||||
|
InsertElementAfterCommand command = new InsertElementAfterCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void InsertElementAfter() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
treeViewContainer.AddElementDialogElementNamesReturned.Add("afterBody"); |
||||||
|
InsertElementAfterCommand command = new InsertElementAfterCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
XmlElement newElement = (XmlElement)doc.SelectSingleNode("/html/afterBody"); |
||||||
|
Assert.IsNotNull(newElement, "Expected a new element to be inserted."); |
||||||
|
Assert.AreSame(newElement, doc.DocumentElement.ChildNodes[1]); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nothing should happen if the owner is null.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void AddChildElementWithNullOwner() |
||||||
|
{ |
||||||
|
AddChildElementCommand command = new AddChildElementCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AddChildElement() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
treeViewContainer.AddElementDialogElementNamesReturned.Add("p"); |
||||||
|
AddChildElementCommand command = new AddChildElementCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
XmlElement paragraphElement = (XmlElement)bodyElement.SelectSingleNode("p"); |
||||||
|
Assert.IsNotNull(paragraphElement, "Expected a new <p> element to be appended."); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the XmlTreeViewContainer.SelectNewElements methods
|
||||||
|
/// returns an empty string array when the AddElementDialog
|
||||||
|
/// is cancelled.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void AddElementDialogCancelled() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
treeViewContainer.AddElementDialogElementNamesReturned.Add("p"); |
||||||
|
treeViewContainer.AddElementDialogResult = DialogResult.Cancel; |
||||||
|
|
||||||
|
string[] elements = treeViewContainer.SelectNewElements(new string[] {"a"}); |
||||||
|
Assert.AreEqual(0, elements.Length); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nothing should happen if the owner is null.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void AddAttributeWithNullOwner() |
||||||
|
{ |
||||||
|
AddAttributeCommand command = new AddAttributeCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AddAttribute() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
treeViewContainer.AddAttributeDialogAttributeNamesReturned.Add("class"); |
||||||
|
AddAttributeCommand command = new AddAttributeCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
Assert.IsTrue(bodyElement.HasAttribute("class")); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nothing should happen if the owner is null.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void RemoveAttributeWithNullOwner() |
||||||
|
{ |
||||||
|
RemoveAttributeCommand command = new RemoveAttributeCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveAttribute() |
||||||
|
{ |
||||||
|
AddAttribute(); |
||||||
|
|
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
treeViewContainer.ShowAttributes(treeView.SelectedElement.Attributes); |
||||||
|
|
||||||
|
Assert.IsNotNull(treeViewContainer.AttributesGrid.SelectedGridItem, |
||||||
|
"Sanity check - should have a grid item selected."); |
||||||
|
|
||||||
|
RemoveAttributeCommand command = new RemoveAttributeCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
Assert.IsFalse(bodyElement.HasAttribute("class")); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests the XmlTreeViewContainer.SelectNewAttributes methods
|
||||||
|
/// returns an empty string array when the AddAttributeDialog
|
||||||
|
/// is cancelled.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void AddAttributeDialogCancelled() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
treeViewContainer.AddAttributeDialogAttributeNamesReturned.Add("class"); |
||||||
|
treeViewContainer.AddAttributeDialogResult = DialogResult.Cancel; |
||||||
|
AddAttributeCommand command = new AddAttributeCommand(); |
||||||
|
|
||||||
|
string[] attributes = treeViewContainer.SelectNewAttributes(new string[] {"a"}); |
||||||
|
Assert.AreEqual(0, attributes.Length); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nothing should happen if the owner is null.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void AddChildTextNodeWithNullOwner() |
||||||
|
{ |
||||||
|
AddChildTextNodeCommand command = new AddChildTextNodeCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AddChildTextNode() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
AddChildTextNodeCommand command = new AddChildTextNodeCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
XmlText textNode = bodyElement.SelectSingleNode("text()") as XmlText; |
||||||
|
Assert.IsNotNull(textNode, "Expected a new text node element to be appended."); |
||||||
|
|
||||||
|
XmlTextTreeNode textTreeNode = bodyTreeNode.Nodes[0] as XmlTextTreeNode; |
||||||
|
Assert.IsNotNull(textTreeNode); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes sure that nothing happens if we try to add a text
|
||||||
|
/// node to the currently selected element node when there
|
||||||
|
/// is no selected element node.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void AddChildTextNodeWhenNoElementSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = null; |
||||||
|
XmlText newTextNode = doc.CreateTextNode(String.Empty); |
||||||
|
treeView.AppendChildTextNode(newTextNode); |
||||||
|
|
||||||
|
XmlText textNode = bodyElement.SelectSingleNode("text()") as XmlText; |
||||||
|
Assert.IsNull(textNode); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Nothing should happen if the owner is null.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void InsertTextNodeBeforeWithNullOwner() |
||||||
|
{ |
||||||
|
InsertTextNodeBeforeCommand command = new InsertTextNodeBeforeCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void InsertTextNodeBefore() |
||||||
|
{ |
||||||
|
AddChildTextNode(); |
||||||
|
|
||||||
|
XmlText textNode = bodyElement.SelectSingleNode("text()") as XmlText; |
||||||
|
textNode.Value = "Original"; |
||||||
|
|
||||||
|
XmlTextTreeNode textTreeNode = bodyTreeNode.Nodes[0] as XmlTextTreeNode; |
||||||
|
treeView.SelectedNode = textTreeNode; |
||||||
|
InsertTextNodeBeforeCommand command = new InsertTextNodeBeforeCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
XmlTextTreeNode insertedTextTreeNode = bodyTreeNode.Nodes[0] as XmlTextTreeNode; |
||||||
|
XmlText insertedTextNode = bodyElement.FirstChild as XmlText; |
||||||
|
Assert.IsNotNull(insertedTextTreeNode); |
||||||
|
Assert.AreEqual(2, bodyTreeNode.Nodes.Count); |
||||||
|
Assert.AreEqual(String.Empty, insertedTextTreeNode.XmlText.Value); |
||||||
|
Assert.IsNotNull(insertedTextNode); |
||||||
|
Assert.AreEqual(2, bodyElement.ChildNodes.Count); |
||||||
|
Assert.AreEqual(String.Empty, insertedTextNode.Value); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes sure that nothing happens if we try to add a text
|
||||||
|
/// node when there is no currently selected node.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void InsertTextNodeWhenNoTreeNodeSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = null; |
||||||
|
XmlText newTextNode = doc.CreateTextNode(String.Empty); |
||||||
|
treeView.InsertTextNodeBefore(newTextNode); |
||||||
|
|
||||||
|
XmlText textNode = bodyElement.SelectSingleNode("text()") as XmlText; |
||||||
|
Assert.IsNull(textNode); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void InsertTextNodeAfterWithNullOwner() |
||||||
|
{ |
||||||
|
InsertTextNodeAfterCommand command = new InsertTextNodeAfterCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void InsertTextNodeAfter() |
||||||
|
{ |
||||||
|
AddChildTextNode(); |
||||||
|
|
||||||
|
XmlText textNode = bodyElement.SelectSingleNode("text()") as XmlText; |
||||||
|
textNode.Value = "OriginalTextNode"; |
||||||
|
|
||||||
|
XmlTextTreeNode textTreeNode = bodyTreeNode.Nodes[0] as XmlTextTreeNode; |
||||||
|
treeView.SelectedNode = textTreeNode; |
||||||
|
InsertTextNodeAfterCommand command = new InsertTextNodeAfterCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
XmlTextTreeNode insertedTextTreeNode = bodyTreeNode.LastNode as XmlTextTreeNode; |
||||||
|
XmlText insertedTextNode = bodyElement.LastChild as XmlText; |
||||||
|
Assert.IsNotNull(insertedTextTreeNode); |
||||||
|
Assert.AreEqual(2, bodyTreeNode.Nodes.Count); |
||||||
|
Assert.AreEqual(String.Empty, insertedTextTreeNode.XmlText.Value); |
||||||
|
Assert.IsNotNull(insertedTextNode); |
||||||
|
Assert.AreEqual(2, bodyElement.ChildNodes.Count); |
||||||
|
Assert.AreEqual(String.Empty, insertedTextNode.Value); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Expect nothing to happen since the ICommand.Owner is not
|
||||||
|
/// set.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void RemoveElementCommandWithNullOwner() |
||||||
|
{ |
||||||
|
RemoveElementCommand command = new RemoveElementCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveRootElementUsingCommand() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = treeView.Nodes[0]; |
||||||
|
|
||||||
|
RemoveElementCommand command = new RemoveElementCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
Assert.AreEqual(0, treeView.Nodes.Count); |
||||||
|
Assert.IsTrue(treeViewContainer.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveTextNodeWithNullOwner() |
||||||
|
{ |
||||||
|
RemoveTextNodeCommand command = new RemoveTextNodeCommand(); |
||||||
|
command.Run(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveTextNode() |
||||||
|
{ |
||||||
|
AddChildTextNode(); |
||||||
|
|
||||||
|
treeView.SelectedNode = bodyTreeNode.Nodes[0]; |
||||||
|
|
||||||
|
RemoveTextNodeCommand command = new RemoveTextNodeCommand(); |
||||||
|
command.Owner = treeViewContainer; |
||||||
|
command.Run(); |
||||||
|
|
||||||
|
Assert.IsFalse(bodyElement.HasChildNodes); |
||||||
|
Assert.AreEqual(0, bodyTreeNode.Nodes.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,93 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that the XmlTreeView fires an AfterSelect event
|
||||||
|
/// when the user clicks into the XmlTreeView control but not
|
||||||
|
/// onto a node and deselects all nodes. The standard behaviour
|
||||||
|
/// of a tree control is to not fire an AfterSelect event in
|
||||||
|
/// this case.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class MouseDownTestFixture |
||||||
|
{ |
||||||
|
DerivedXmlTreeViewControl treeView; |
||||||
|
List<TreeViewEventArgs> treeViewEventArgs; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void SetUpFixture() |
||||||
|
{ |
||||||
|
treeViewEventArgs = new List<TreeViewEventArgs>(); |
||||||
|
treeView = new DerivedXmlTreeViewControl(); |
||||||
|
treeView.Height = 100; |
||||||
|
treeView.Nodes.Add(new ExtTreeNode()); |
||||||
|
treeView.AfterSelect += XmlTreeViewAfterSelect; |
||||||
|
} |
||||||
|
|
||||||
|
[TearDown] |
||||||
|
public void TearDownFixture() |
||||||
|
{ |
||||||
|
if (treeView != null) { |
||||||
|
treeView.AfterSelect -= XmlTreeViewAfterSelect; |
||||||
|
treeView.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Make sure the AfterSelect event is not fired twice and the
|
||||||
|
/// standard behaviour of the OnMouseDown method is preserved
|
||||||
|
/// in the normal case.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void MouseDownWithNodeSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = treeView.Nodes[0]; |
||||||
|
|
||||||
|
// Make sure the button click will select the first node
|
||||||
|
// so choose x=0, y=0.
|
||||||
|
MouseEventArgs e = new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0); |
||||||
|
treeView.CallMouseDown(e); |
||||||
|
|
||||||
|
Assert.IsNotNull(treeView.SelectedNode, "Sanity check: The mouse down call should not deselect the tree node."); |
||||||
|
Assert.AreEqual(1, treeViewEventArgs.Count, "AfterSelect event should be fired once."); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void MouseDownWithNoNodeSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = null; |
||||||
|
|
||||||
|
// Make sure the mouse click will not select any
|
||||||
|
// tree node (x=0, y=99 - Height of control=100)
|
||||||
|
treeViewEventArgs.Clear(); |
||||||
|
MouseEventArgs e = new MouseEventArgs(MouseButtons.Left, 1, 0, 99, 0); |
||||||
|
treeView.CallMouseDown(e); |
||||||
|
|
||||||
|
Assert.IsNull(treeView.SelectedNode, "Sanity check: The mouse down call should not select a tree node"); |
||||||
|
Assert.AreEqual(1, treeViewEventArgs.Count, "AfterSelect event should be fired once."); |
||||||
|
TreeViewEventArgs treeViewEventArg = treeViewEventArgs[0]; |
||||||
|
Assert.IsNull(treeViewEventArg.Node); |
||||||
|
Assert.AreEqual(TreeViewAction.ByMouse, treeViewEventArg.Action); |
||||||
|
} |
||||||
|
|
||||||
|
void XmlTreeViewAfterSelect(object sender, TreeViewEventArgs e) |
||||||
|
{ |
||||||
|
treeViewEventArgs.Add(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,119 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Xml; |
||||||
|
|
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests the XmlTreeViewContainerControl.OwnerState property.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class OwnerStatusTestFixture |
||||||
|
{ |
||||||
|
XmlTreeViewContainerControl treeViewContainer; |
||||||
|
XmlTreeViewControl treeView; |
||||||
|
XmlDocument doc; |
||||||
|
XmlElementTreeNode htmlTreeNode; |
||||||
|
XmlElementTreeNode bodyTreeNode; |
||||||
|
XmlElementTreeNode paraTreeNode; |
||||||
|
XmlTextTreeNode textTreeNode; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
treeViewContainer = new XmlTreeViewContainerControl(); |
||||||
|
|
||||||
|
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||||
|
XmlSchemaCompletionData xhtmlSchema = new XmlSchemaCompletionData(reader); |
||||||
|
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||||
|
XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xhtmlSchema, String.Empty); |
||||||
|
|
||||||
|
treeViewContainer.LoadXml("<html><body class='a'><p>Text</p></body></html>", provider); |
||||||
|
doc = treeViewContainer.Document; |
||||||
|
treeView = treeViewContainer.TreeView; |
||||||
|
|
||||||
|
htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[0]; |
||||||
|
htmlTreeNode.Expanding(); |
||||||
|
|
||||||
|
bodyTreeNode = (XmlElementTreeNode)htmlTreeNode.Nodes[0]; |
||||||
|
bodyTreeNode.Expanding(); |
||||||
|
|
||||||
|
paraTreeNode = (XmlElementTreeNode)bodyTreeNode.Nodes[0]; |
||||||
|
paraTreeNode.Expanding(); |
||||||
|
|
||||||
|
textTreeNode = (XmlTextTreeNode)paraTreeNode.Nodes[0]; |
||||||
|
} |
||||||
|
|
||||||
|
[TearDown] |
||||||
|
public void TearDown() |
||||||
|
{ |
||||||
|
if (treeViewContainer != null) { |
||||||
|
treeViewContainer.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NothingSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = null; |
||||||
|
|
||||||
|
Assert.AreEqual(XmlTreeViewContainerControl.XmlTreeViewContainerControlState.Nothing, |
||||||
|
treeViewContainer.InternalState, |
||||||
|
"OwnerState should be Nothing."); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RootElementSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = htmlTreeNode; |
||||||
|
|
||||||
|
Assert.AreEqual(XmlTreeViewContainerControl.XmlTreeViewContainerControlState.RootElementSelected | XmlTreeViewContainerControl.XmlTreeViewContainerControlState.ElementSelected, |
||||||
|
treeViewContainer.InternalState, |
||||||
|
"OwnerState should be RootElementSelected and ElementSelected."); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void BodyElementSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
|
||||||
|
Assert.AreEqual(XmlTreeViewContainerControl.XmlTreeViewContainerControlState.ElementSelected, |
||||||
|
treeViewContainer.InternalState, |
||||||
|
"OwnerState should be ElementSelected."); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ClassAttributeSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = bodyTreeNode; |
||||||
|
treeViewContainer.ShowAttributes(treeView.SelectedElement.Attributes); |
||||||
|
|
||||||
|
Assert.IsNotNull(treeViewContainer.AttributesGrid.SelectedGridItem, |
||||||
|
"Sanity check - should have a grid item selected."); |
||||||
|
|
||||||
|
Assert.AreEqual(XmlTreeViewContainerControl.XmlTreeViewContainerControlState.ElementSelected | XmlTreeViewContainerControl.XmlTreeViewContainerControlState.AttributeSelected, |
||||||
|
treeViewContainer.InternalState, |
||||||
|
"OwnerState should be ElementSelected and AttributeSelected."); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextNodeSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = textTreeNode; |
||||||
|
|
||||||
|
Assert.AreEqual(XmlTreeViewContainerControl.XmlTreeViewContainerControlState.TextNodeSelected, |
||||||
|
treeViewContainer.InternalState, |
||||||
|
"OwnerState should be TextNodeSelected."); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,97 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using System.Xml; |
||||||
|
|
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that an element is removed from the XML document by the
|
||||||
|
/// XmlTreeEditor.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class RemoveElementTestFixture : XmlTreeViewTestFixtureBase |
||||||
|
{ |
||||||
|
XmlElement bodyElement; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
base.InitFixture(); |
||||||
|
bodyElement = (XmlElement)editor.Document.SelectSingleNode("/html/body"); |
||||||
|
mockXmlTreeView.SelectedElement = bodyElement; |
||||||
|
|
||||||
|
editor.RemoveElement(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void BodyElementRemoved() |
||||||
|
{ |
||||||
|
Assert.IsNull(editor.Document.SelectSingleNode("/html/body")); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void BodyElementRemovedFromTree() |
||||||
|
{ |
||||||
|
Assert.AreEqual(1, mockXmlTreeView.ElementsRemoved.Count); |
||||||
|
Assert.AreSame(bodyElement, mockXmlTreeView.ElementsRemoved[0]); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsDirty() |
||||||
|
{ |
||||||
|
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void NoElementSelected() |
||||||
|
{ |
||||||
|
mockXmlTreeView.SelectedElement = null; |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
editor.RemoveElement(); |
||||||
|
Assert.IsFalse(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveRootElement() |
||||||
|
{ |
||||||
|
XmlElement htmlElement = editor.Document.DocumentElement; |
||||||
|
mockXmlTreeView.SelectedElement = htmlElement; |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
editor.RemoveElement(); |
||||||
|
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||||
|
Assert.IsNull(editor.Document.DocumentElement); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the xhtml strict schema as the default schema.
|
||||||
|
/// </summary>
|
||||||
|
protected override XmlSchemaCompletionData DefaultSchemaCompletionData { |
||||||
|
get { |
||||||
|
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||||
|
return new XmlSchemaCompletionData(reader); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetXml() |
||||||
|
{ |
||||||
|
return "<html>\r\n" + |
||||||
|
"\t<head>\r\n" + |
||||||
|
"\t\t<title></title>\r\n" + |
||||||
|
"\t</head>\r\n" + |
||||||
|
"\t<body id='body' title='abc'>\r\n" + |
||||||
|
"\t</body>\r\n" + |
||||||
|
"</html>"; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,90 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Xml; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class RemoveElementsFromTreeControlTestFixture |
||||||
|
{ |
||||||
|
XmlDocument doc; |
||||||
|
XmlTreeViewContainerControl treeViewContainerControl; |
||||||
|
XmlTreeViewControl treeView; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void SetUp() |
||||||
|
{ |
||||||
|
XmlCompletionDataProvider completionDataProvider = new XmlCompletionDataProvider(new XmlSchemaCompletionDataCollection(), null, String.Empty); |
||||||
|
treeViewContainerControl = new XmlTreeViewContainerControl(); |
||||||
|
treeView = treeViewContainerControl.TreeView; |
||||||
|
treeViewContainerControl.LoadXml("<root><child></child></root>", completionDataProvider); |
||||||
|
doc = treeViewContainerControl.Document; |
||||||
|
} |
||||||
|
|
||||||
|
[TearDown] |
||||||
|
public void TearDown() |
||||||
|
{ |
||||||
|
if (treeViewContainerControl != null) { |
||||||
|
treeViewContainerControl.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsDirty() |
||||||
|
{ |
||||||
|
Assert.IsFalse(treeViewContainerControl.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RootTreeNodesBeforeRemove() |
||||||
|
{ |
||||||
|
Assert.AreEqual(1, treeView.Nodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveSelectedRootElement() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = treeView.Nodes[0]; |
||||||
|
treeView.RemoveElement(doc.DocumentElement); |
||||||
|
Assert.AreEqual(0, treeView.Nodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveRootElementWhenNoTreeNodeSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = null; |
||||||
|
treeView.RemoveElement(doc.DocumentElement); |
||||||
|
Assert.AreEqual(0, treeView.Nodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveChildElement() |
||||||
|
{ |
||||||
|
ExtTreeNode rootNode = (ExtTreeNode)treeView.Nodes[0]; |
||||||
|
rootNode.Expanding(); |
||||||
|
treeView.RemoveElement((XmlElement)doc.DocumentElement.FirstChild); |
||||||
|
Assert.AreEqual(0, treeView.Nodes[0].Nodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removing an element that does not exist in the
|
||||||
|
/// tree should not make the view dirty. Nothing should
|
||||||
|
/// happen at all.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void RemoveUnknownElement() |
||||||
|
{ |
||||||
|
XmlElement element = (XmlElement)doc.CreateElement("NewElement"); |
||||||
|
treeView.RemoveElement(element); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,90 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.IO; |
||||||
|
using System.Xml; |
||||||
|
|
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Tests that a text node is removed from the XML document by the
|
||||||
|
/// XmlTreeEditor.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class RemoveTextNodeTestFixture : XmlTreeViewTestFixtureBase |
||||||
|
{ |
||||||
|
XmlElement paragraphElement; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
base.InitFixture(); |
||||||
|
paragraphElement = (XmlElement)editor.Document.SelectSingleNode("/html/body/p"); |
||||||
|
XmlText textNode = (XmlText)paragraphElement.FirstChild; |
||||||
|
mockXmlTreeView.SelectedTextNode = textNode; |
||||||
|
|
||||||
|
editor.RemoveTextNode(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextNodeRemovedFromDocument() |
||||||
|
{ |
||||||
|
Assert.AreEqual(0, paragraphElement.ChildNodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests that the xml tree editor does not throw
|
||||||
|
/// an exception if we try to remove a text node when
|
||||||
|
/// no node is selected.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void NoTextNodeSelected() |
||||||
|
{ |
||||||
|
mockXmlTreeView.IsDirty = false; |
||||||
|
mockXmlTreeView.SelectedTextNode = null; |
||||||
|
editor.RemoveTextNode(); |
||||||
|
|
||||||
|
Assert.IsFalse(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextNodeRemovedFromView() |
||||||
|
{ |
||||||
|
Assert.AreEqual(1, mockXmlTreeView.TextNodesRemoved.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void IsDirty() |
||||||
|
{ |
||||||
|
Assert.IsTrue(mockXmlTreeView.IsDirty); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the xhtml strict schema as the default schema.
|
||||||
|
/// </summary>
|
||||||
|
protected override XmlSchemaCompletionData DefaultSchemaCompletionData { |
||||||
|
get { |
||||||
|
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||||
|
return new XmlSchemaCompletionData(reader); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
protected override string GetXml() |
||||||
|
{ |
||||||
|
return "<html>\r\n" + |
||||||
|
"\t<body>\r\n" + |
||||||
|
"\t\t<p>some text here</p>\r\n" + |
||||||
|
"\t</body>\r\n" + |
||||||
|
"</html>"; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,105 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows.Forms; |
||||||
|
using System.Xml; |
||||||
|
using ICSharpCode.SharpDevelop.Gui; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class RemoveTextNodesFromTreeControlTestFixture |
||||||
|
{ |
||||||
|
XmlDocument doc; |
||||||
|
XmlTreeViewContainerControl treeViewContainerControl; |
||||||
|
XmlTreeViewControl treeView; |
||||||
|
XmlElementTreeNode topElementTreeNode; |
||||||
|
XmlElementTreeNode childElementTreeNode; |
||||||
|
XmlTextTreeNode topTextTreeNode; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void SetUp() |
||||||
|
{ |
||||||
|
XmlCompletionDataProvider completionDataProvider = new XmlCompletionDataProvider(new XmlSchemaCompletionDataCollection(), null, String.Empty); |
||||||
|
treeViewContainerControl = new XmlTreeViewContainerControl(); |
||||||
|
treeView = treeViewContainerControl.TreeView; |
||||||
|
treeViewContainerControl.LoadXml("<root><top>text</top><bottom><child>text</child></bottom></root>", completionDataProvider); |
||||||
|
doc = treeViewContainerControl.Document; |
||||||
|
|
||||||
|
ExtTreeNode rootNode = (ExtTreeNode)treeView.Nodes[0]; |
||||||
|
rootNode.Expanding(); |
||||||
|
|
||||||
|
topElementTreeNode = (XmlElementTreeNode)rootNode.Nodes[0]; |
||||||
|
topElementTreeNode.Expanding(); |
||||||
|
|
||||||
|
topTextTreeNode = (XmlTextTreeNode)topElementTreeNode.Nodes[0]; |
||||||
|
|
||||||
|
ExtTreeNode bottomNode = (ExtTreeNode)rootNode.Nodes[1]; |
||||||
|
bottomNode.Expanding(); |
||||||
|
|
||||||
|
childElementTreeNode = (XmlElementTreeNode)bottomNode.Nodes[0]; |
||||||
|
childElementTreeNode.Expanding(); |
||||||
|
} |
||||||
|
|
||||||
|
[TearDown] |
||||||
|
public void TearDown() |
||||||
|
{ |
||||||
|
if (treeViewContainerControl != null) { |
||||||
|
treeViewContainerControl.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveTextNode() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = topTextTreeNode; |
||||||
|
treeView.RemoveTextNode(topTextTreeNode.XmlText); |
||||||
|
|
||||||
|
Assert.AreEqual(0, topElementTreeNode.Nodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes sure that nothing happens if we try to remove a text
|
||||||
|
/// node when there is no currently selected node.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void RemoveTextNodeWhenNoTreeNodeSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = null; |
||||||
|
XmlText newTextNode = doc.CreateTextNode(String.Empty); |
||||||
|
treeView.RemoveTextNode(newTextNode); |
||||||
|
|
||||||
|
Assert.AreEqual(1, topElementTreeNode.Nodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Makes sure that nothing happens if we try to remove a text
|
||||||
|
/// node that is not in the tree.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void RemoveUnknownTextNode() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = topElementTreeNode; |
||||||
|
XmlText newTextNode = doc.CreateTextNode(String.Empty); |
||||||
|
treeView.RemoveTextNode(newTextNode); |
||||||
|
|
||||||
|
Assert.AreEqual(1, topElementTreeNode.Nodes.Count); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RemoveKnownTextNodeWhenNothingSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = null; |
||||||
|
treeView.RemoveTextNode(topTextTreeNode.XmlText); |
||||||
|
|
||||||
|
Assert.AreEqual(0, topElementTreeNode.Nodes.Count); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,334 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows.Forms; |
||||||
|
using System.Xml; |
||||||
|
|
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
using NUnit.Framework; |
||||||
|
using XmlEditor.Tests.Utils; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Tree |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Various tests for the XmlTreeViewContainerControl. These
|
||||||
|
/// tests do not really fit into any other test fixture.
|
||||||
|
/// </summary>
|
||||||
|
[TestFixture] |
||||||
|
public class XmlTreeViewContainerTestFixture |
||||||
|
{ |
||||||
|
XmlDocument doc; |
||||||
|
XmlTreeViewControl treeView; |
||||||
|
DerivedXmlTreeViewContainerControl treeViewContainer; |
||||||
|
RichTextBox textBox; |
||||||
|
XmlCompletionDataProvider provider; |
||||||
|
PropertyGrid attributesGrid; |
||||||
|
SplitContainer splitContainer; |
||||||
|
RichTextBox errorMessageTextBox; |
||||||
|
bool dirtyChanged; |
||||||
|
XmlElementTreeNode htmlTreeNode; |
||||||
|
XmlTextTreeNode textTreeNode; |
||||||
|
|
||||||
|
[SetUp] |
||||||
|
public void Init() |
||||||
|
{ |
||||||
|
treeViewContainer = new DerivedXmlTreeViewContainerControl(); |
||||||
|
treeViewContainer.DirtyChanged += TreeViewContainerDirtyChanged; |
||||||
|
|
||||||
|
XmlTextReader reader = ResourceManager.GetXhtmlStrictSchema(); |
||||||
|
XmlSchemaCompletionData xhtmlSchema = new XmlSchemaCompletionData(reader); |
||||||
|
XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection(); |
||||||
|
provider = new XmlCompletionDataProvider(schemas, xhtmlSchema, String.Empty); |
||||||
|
|
||||||
|
treeViewContainer.LoadXml("<html id='a'>text<body></body></html>", provider); |
||||||
|
doc = treeViewContainer.Document; |
||||||
|
treeView = treeViewContainer.TreeView; |
||||||
|
|
||||||
|
htmlTreeNode = (XmlElementTreeNode)treeView.Nodes[0]; |
||||||
|
htmlTreeNode.Expanding(); |
||||||
|
textTreeNode = (XmlTextTreeNode)htmlTreeNode.Nodes[0]; |
||||||
|
|
||||||
|
splitContainer = (SplitContainer)treeViewContainer.Controls["splitContainer"]; |
||||||
|
|
||||||
|
textBox = (RichTextBox)splitContainer.Panel2.Controls["textBox"]; |
||||||
|
errorMessageTextBox = (RichTextBox)splitContainer.Panel2.Controls["errorMessageTextBox"]; |
||||||
|
attributesGrid = (PropertyGrid)splitContainer.Panel2.Controls["attributesGrid"]; |
||||||
|
} |
||||||
|
|
||||||
|
[TearDown] |
||||||
|
public void TearDown() |
||||||
|
{ |
||||||
|
if (treeViewContainer != null) { |
||||||
|
treeViewContainer.DirtyChanged -= TreeViewContainerDirtyChanged; |
||||||
|
treeViewContainer.Dispose(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ErrorMessageTextBoxVisibleAtStart() |
||||||
|
{ |
||||||
|
Assert.IsFalse(treeViewContainer.IsErrorMessageTextBoxVisible); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextBoxIsNotTabStopAtStart() |
||||||
|
{ |
||||||
|
Assert.IsFalse(textBox.TabStop); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextBoxIsEmptyAtStart() |
||||||
|
{ |
||||||
|
Assert.AreEqual(String.Empty, textBox.Text); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AttributesGridIsTabStopAtStart() |
||||||
|
{ |
||||||
|
Assert.IsTrue(attributesGrid.TabStop); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check that the XmlTreeViewContainer brought the
|
||||||
|
/// AttributesGrid to the front.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void AttributesGridOnTop() |
||||||
|
{ |
||||||
|
Assert.AreEqual(0, splitContainer.Panel2.Controls.IndexOf(attributesGrid), |
||||||
|
"AttributesGrid is not on top"); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks that the text box shows the specified text and
|
||||||
|
/// is visible in the control.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void ShowTextContent() |
||||||
|
{ |
||||||
|
string text = "test"; |
||||||
|
treeViewContainer.ShowTextContent(text); |
||||||
|
|
||||||
|
Assert.AreEqual(text, treeViewContainer.TextContent); |
||||||
|
Assert.AreEqual(text, textBox.Text); |
||||||
|
Assert.IsTrue(textBox.TabStop); |
||||||
|
Assert.AreEqual(0, splitContainer.Panel2.Controls.IndexOf(textBox)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextBoxClearedAfterLoadXml() |
||||||
|
{ |
||||||
|
treeViewContainer.ShowTextContent("test"); |
||||||
|
treeViewContainer.LoadXml("<html/>", provider); |
||||||
|
|
||||||
|
Assert.AreEqual(String.Empty, textBox.Text); |
||||||
|
AttributesGridOnTop(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void RootNodeExpanded() |
||||||
|
{ |
||||||
|
Assert.IsTrue(treeView.Nodes[0].IsExpanded); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AttributesClearedAfterLoadXml() |
||||||
|
{ |
||||||
|
// Make sure some attributes are showing.
|
||||||
|
treeViewContainer.ShowAttributes(doc.DocumentElement.Attributes); |
||||||
|
|
||||||
|
Assert.IsTrue(doc.DocumentElement.HasAttributes, "Sanity check that the root element has some attributes"); |
||||||
|
Assert.IsNotNull(attributesGrid.SelectedObject); |
||||||
|
|
||||||
|
// Loading new xml should clear the attributes grid.
|
||||||
|
treeViewContainer.LoadXml("<html/>", provider); |
||||||
|
|
||||||
|
Assert.IsNull(attributesGrid.SelectedObject, |
||||||
|
"Should be no SelectedObject in the attributes grid after loading new xml."); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ErrorMessageTextBoxNotTabStop() |
||||||
|
{ |
||||||
|
Assert.IsFalse(errorMessageTextBox.TabStop); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ErrorMessageTextBoxNotOnTop() |
||||||
|
{ |
||||||
|
Assert.AreNotEqual(0, splitContainer.Panel2.Controls.IndexOf(errorMessageTextBox)); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ShowXmlNotWellFormed() |
||||||
|
{ |
||||||
|
XmlException ex = new XmlException("Message"); |
||||||
|
treeViewContainer.ShowXmlIsNotWellFormedMessage(ex); |
||||||
|
|
||||||
|
Assert.AreEqual(0, treeView.Nodes.Count, "TreeView should be cleared."); |
||||||
|
Assert.AreEqual(ex.Message, treeViewContainer.ErrorMessage); |
||||||
|
Assert.AreEqual(0, splitContainer.Panel2.Controls.IndexOf(errorMessageTextBox), "ErrorMessageTextBox should be on top"); |
||||||
|
Assert.AreEqual(ex.Message, errorMessageTextBox.Text); |
||||||
|
Assert.IsTrue(errorMessageTextBox.TabStop); |
||||||
|
Assert.IsFalse(attributesGrid.TabStop); |
||||||
|
Assert.IsFalse(textBox.TabStop); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks that the text box is not a tab stop after showing
|
||||||
|
/// an error.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void ShowTextContentBeforeShowingError() |
||||||
|
{ |
||||||
|
treeViewContainer.ShowTextContent("Test"); |
||||||
|
ShowXmlNotWellFormed(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void DirtyChanged() |
||||||
|
{ |
||||||
|
treeViewContainer.IsDirty = true; |
||||||
|
Assert.IsTrue(dirtyChanged); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextChanged() |
||||||
|
{ |
||||||
|
// Select the text node.
|
||||||
|
treeView.SelectedNode = textTreeNode; |
||||||
|
|
||||||
|
string newText = "changed text"; |
||||||
|
textBox.Text = newText; |
||||||
|
|
||||||
|
// Make sure the dirty flag is changed by changing
|
||||||
|
// the text.
|
||||||
|
treeViewContainer.IsDirty = false; |
||||||
|
dirtyChanged = false; |
||||||
|
|
||||||
|
treeViewContainer.CallTextBoxTextChanged(); |
||||||
|
|
||||||
|
Assert.AreEqual(newText, textTreeNode.XmlText.Value); |
||||||
|
Assert.AreEqual(newText, textTreeNode.Text, "Tree node text should be updated with new XmlText's value"); |
||||||
|
Assert.IsTrue(treeViewContainer.IsDirty); |
||||||
|
Assert.IsTrue(dirtyChanged); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tests that when the XmlTreeView's UpdateTextNode method
|
||||||
|
/// is called we do not get a null exception if the
|
||||||
|
/// text node cannot be found in the tree.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void UpdateUnknownTextNodeText() |
||||||
|
{ |
||||||
|
// Select the text node.
|
||||||
|
treeView.SelectedNode = textTreeNode; |
||||||
|
|
||||||
|
XmlText textNode = doc.CreateTextNode(String.Empty); |
||||||
|
treeView.UpdateTextNode(textNode); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the text node when no text node is selected in the
|
||||||
|
/// tree.
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void UpdateTextNodeText() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = null; |
||||||
|
|
||||||
|
textTreeNode.XmlText.Value = "New value"; |
||||||
|
treeView.UpdateTextNode(textTreeNode.XmlText); |
||||||
|
Assert.AreEqual("New value", textTreeNode.Text); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check that the DirtyChanged event is not fired
|
||||||
|
/// </summary>
|
||||||
|
[Test] |
||||||
|
public void TextChangedDirtyUnchanged() |
||||||
|
{ |
||||||
|
// Select the text node.
|
||||||
|
treeView.SelectedNode = textTreeNode; |
||||||
|
|
||||||
|
textBox.Text = "changed text"; |
||||||
|
|
||||||
|
// Make sure the dirty flag is changed by changing
|
||||||
|
// the text.
|
||||||
|
treeViewContainer.IsDirty = true; |
||||||
|
dirtyChanged = false; |
||||||
|
|
||||||
|
treeViewContainer.CallTextBoxTextChanged(); |
||||||
|
|
||||||
|
Assert.AreEqual("changed text", textTreeNode.XmlText.Value); |
||||||
|
Assert.IsTrue(treeViewContainer.IsDirty); |
||||||
|
Assert.IsFalse(dirtyChanged); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AttributeValueChanged() |
||||||
|
{ |
||||||
|
// Select the html node.
|
||||||
|
treeView.SelectedNode = htmlTreeNode; |
||||||
|
treeViewContainer.ShowAttributes(doc.DocumentElement.Attributes); |
||||||
|
|
||||||
|
Assert.IsNotNull(attributesGrid.SelectedGridItem); |
||||||
|
|
||||||
|
treeViewContainer.IsDirty = false; |
||||||
|
dirtyChanged = false; |
||||||
|
treeViewContainer.CallAttributesGridPropertyValueChanged(); |
||||||
|
|
||||||
|
Assert.IsTrue(treeViewContainer.IsDirty); |
||||||
|
Assert.IsTrue(dirtyChanged); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void AttributeValueChangedDirtyUnchanged() |
||||||
|
{ |
||||||
|
// Select the html node.
|
||||||
|
treeView.SelectedNode = htmlTreeNode; |
||||||
|
treeViewContainer.ShowAttributes(doc.DocumentElement.Attributes); |
||||||
|
|
||||||
|
Assert.IsNotNull(attributesGrid.SelectedGridItem); |
||||||
|
|
||||||
|
treeViewContainer.IsDirty = true; |
||||||
|
dirtyChanged = false; |
||||||
|
treeViewContainer.CallAttributesGridPropertyValueChanged(); |
||||||
|
|
||||||
|
Assert.IsTrue(treeViewContainer.IsDirty); |
||||||
|
Assert.IsFalse(dirtyChanged); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void TextNodeSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = textTreeNode; |
||||||
|
treeViewContainer.ShowTextContent(String.Empty); |
||||||
|
treeViewContainer.CallXmlElementTreeViewAfterSelect(); |
||||||
|
|
||||||
|
Assert.AreEqual("text", textBox.Text); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void HtmlElementNodeSelected() |
||||||
|
{ |
||||||
|
treeView.SelectedNode = htmlTreeNode; |
||||||
|
treeViewContainer.CallXmlElementTreeViewAfterSelect(); |
||||||
|
|
||||||
|
Assert.IsNotNull(attributesGrid.SelectedGridItem); |
||||||
|
Assert.AreEqual("id", attributesGrid.SelectedGridItem.Label); |
||||||
|
} |
||||||
|
|
||||||
|
void TreeViewContainerDirtyChanged(object source, EventArgs e) |
||||||
|
{ |
||||||
|
dirtyChanged = true; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Utils |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Test utility class that has the XmlTreeViewControl as a base class
|
||||||
|
/// and gives access to protected methods.
|
||||||
|
/// </summary>
|
||||||
|
public class DerivedXmlTreeViewControl : XmlTreeViewControl |
||||||
|
{ |
||||||
|
public DerivedXmlTreeViewControl() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public void CallMouseDown(MouseEventArgs e) |
||||||
|
{ |
||||||
|
base.OnMouseDown(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,125 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Windows.Forms; |
||||||
|
|
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Utils |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Derived version of the XmlTreeViewContainerControl which
|
||||||
|
/// allows us to override the code that shows the various dialogs
|
||||||
|
/// that ask for user input so we can fake the data allowing us
|
||||||
|
/// to test the class.
|
||||||
|
/// </summary>
|
||||||
|
public class DerivedXmlTreeViewContainerControl : XmlTreeViewContainerControl |
||||||
|
{ |
||||||
|
List<string> addElementDialogElementNamesReturned = new List<string>(); |
||||||
|
DialogResult addElementDialogResult = DialogResult.OK; |
||||||
|
List<string> addAttributeDialogAttributeNamesReturned = new List<string>(); |
||||||
|
DialogResult addAttributeDialogResult = DialogResult.OK; |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This is the list of element names that will be returned from
|
||||||
|
/// the mock AddElementDialog.
|
||||||
|
/// </summary>
|
||||||
|
public List<string> AddElementDialogElementNamesReturned { |
||||||
|
get { |
||||||
|
return addElementDialogElementNamesReturned; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the dialog result for the AddElementDialog.
|
||||||
|
/// </summary>
|
||||||
|
public DialogResult AddElementDialogResult { |
||||||
|
get { |
||||||
|
return addElementDialogResult; |
||||||
|
} |
||||||
|
set { |
||||||
|
addElementDialogResult = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the list of attribute names that will be returned
|
||||||
|
/// from the mock AddAttributeDialog.
|
||||||
|
/// </summary>
|
||||||
|
public List<string> AddAttributeDialogAttributeNamesReturned { |
||||||
|
get { |
||||||
|
return addAttributeDialogAttributeNamesReturned; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the dialog result for the AddAttributeDialog.
|
||||||
|
/// </summary>
|
||||||
|
public DialogResult AddAttributeDialogResult { |
||||||
|
get { |
||||||
|
return addAttributeDialogResult; |
||||||
|
} |
||||||
|
set { |
||||||
|
addAttributeDialogResult = value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows us to call the XmlTreeViewContainerControl's
|
||||||
|
/// TextBoxChanged method to fake the user typing in text
|
||||||
|
/// into the text box.
|
||||||
|
/// </summary>
|
||||||
|
public void CallTextBoxTextChanged() |
||||||
|
{ |
||||||
|
base.TextBoxTextChanged(this, new EventArgs()); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows us to call the XmlTreeViewContainerControl's
|
||||||
|
/// AttributesGridPropertyValueChanged to fake the user
|
||||||
|
/// changing the property value.
|
||||||
|
/// </summary>
|
||||||
|
public void CallAttributesGridPropertyValueChanged() |
||||||
|
{ |
||||||
|
base.AttributesGridPropertyValueChanged(this, new PropertyValueChangedEventArgs(null, null)); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows us to call the XmlTreeViewContainerControl's
|
||||||
|
/// XmlElementTreeViewAfterSelect to fake the user selecting
|
||||||
|
/// a tree node.
|
||||||
|
/// </summary>
|
||||||
|
public void CallXmlElementTreeViewAfterSelect() |
||||||
|
{ |
||||||
|
base.XmlElementTreeViewAfterSelect(this, new TreeViewEventArgs(null, TreeViewAction.ByMouse)); |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a new MockAddElementDialog for testing.
|
||||||
|
/// </summary>
|
||||||
|
protected override IAddElementDialog CreateAddElementDialog(string[] elementNames) |
||||||
|
{ |
||||||
|
MockAddElementDialog dialog = new MockAddElementDialog(); |
||||||
|
dialog.SetElementNamesToReturn(addElementDialogElementNamesReturned.ToArray()); |
||||||
|
dialog.SetDialogResult(addElementDialogResult); |
||||||
|
return dialog; |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a new MockAddAttributeDialog for testing.
|
||||||
|
/// </summary>
|
||||||
|
protected override IAddAttributeDialog CreateAddAttributeDialog(string[] attributeNames) |
||||||
|
{ |
||||||
|
MockAddAttributeDialog dialog = new MockAddAttributeDialog(); |
||||||
|
dialog.SetAttributeNamesToReturn(addAttributeDialogAttributeNamesReturned.ToArray()); |
||||||
|
dialog.SetDialogResult(addAttributeDialogResult); |
||||||
|
return dialog; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,65 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Utils |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Mocks the AddAttributeDialog so we can test the
|
||||||
|
/// XmlTreeViewContainerControl class when it displays
|
||||||
|
/// the AddAttributeDialog.
|
||||||
|
/// </summary>
|
||||||
|
public class MockAddAttributeDialog : IAddAttributeDialog |
||||||
|
{ |
||||||
|
DialogResult dialogResult = DialogResult.OK; |
||||||
|
List<string> attributeNames = new List<string>(); |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies the attribute names to return from the
|
||||||
|
/// IAddAttributeDialog.AttributeNames property.
|
||||||
|
/// </summary>
|
||||||
|
public void SetAttributeNamesToReturn(string[] names) |
||||||
|
{ |
||||||
|
attributeNames.Clear(); |
||||||
|
foreach (string name in names) { |
||||||
|
attributeNames.Add(name); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies the dialog result to return from the
|
||||||
|
/// IAddAttributeDialog.ShowDialog method.
|
||||||
|
/// </summary>
|
||||||
|
public void SetDialogResult(DialogResult result) |
||||||
|
{ |
||||||
|
dialogResult = result; |
||||||
|
} |
||||||
|
|
||||||
|
#region IAddAttributeDialog implementation
|
||||||
|
|
||||||
|
public string[] AttributeNames { |
||||||
|
get { |
||||||
|
return attributeNames.ToArray(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public DialogResult ShowDialog() |
||||||
|
{ |
||||||
|
return dialogResult; |
||||||
|
} |
||||||
|
|
||||||
|
public void Dispose() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,65 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Collections.Generic; |
||||||
|
using System.Windows.Forms; |
||||||
|
using ICSharpCode.XmlEditor; |
||||||
|
|
||||||
|
namespace XmlEditor.Tests.Utils |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Mocks the AddElementDialog so we can test the
|
||||||
|
/// XmlTreeViewContainerControl class when it displays
|
||||||
|
/// the AddElementDialog.
|
||||||
|
/// </summary>
|
||||||
|
public class MockAddElementDialog : IAddElementDialog |
||||||
|
{ |
||||||
|
DialogResult dialogResult = DialogResult.OK; |
||||||
|
List<string> elementNames = new List<string>(); |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies the element names to return from the
|
||||||
|
/// IAddElementDialog.ElementNames property.
|
||||||
|
/// </summary>
|
||||||
|
public void SetElementNamesToReturn(string[] names) |
||||||
|
{ |
||||||
|
elementNames.Clear(); |
||||||
|
foreach (string name in names) { |
||||||
|
elementNames.Add(name); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies the dialog result to return from the
|
||||||
|
/// IAddElementDialog.ShowDialog method.
|
||||||
|
/// </summary>
|
||||||
|
public void SetDialogResult(DialogResult result) |
||||||
|
{ |
||||||
|
dialogResult = result; |
||||||
|
} |
||||||
|
|
||||||
|
#region IAddElementDialog implementation
|
||||||
|
|
||||||
|
public string[] ElementNames { |
||||||
|
get { |
||||||
|
return elementNames.ToArray(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public DialogResult ShowDialog() |
||||||
|
{ |
||||||
|
return dialogResult; |
||||||
|
} |
||||||
|
|
||||||
|
public void Dispose() |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
#endregion
|
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
<configuration> |
||||||
|
<configSections> |
||||||
|
<sectionGroup name="NUnit"> |
||||||
|
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler" /> |
||||||
|
</sectionGroup> |
||||||
|
</configSections> |
||||||
|
<NUnit> |
||||||
|
<TestRunner> |
||||||
|
<!-- Valid values are STA,MTA. Others ignored. --> |
||||||
|
<add key="ApartmentState" value="STA" /> |
||||||
|
</TestRunner> |
||||||
|
</NUnit> |
||||||
|
</configuration> |
||||||
Loading…
Reference in new issue