Browse Source

XML editor now supports an xml schema defined in multiple documents (e.g. Sandcastle MAML schemas).

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5304 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Matt Ward 16 years ago
parent
commit
1e6bf9d942
  1. 10
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/RegisteredXmlSchemas.cs
  2. 2
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs
  3. 76
      src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionCollection.cs
  4. 7
      src/AddIns/DisplayBindings/XmlEditor/Test/Editor/RegisteredSchemaWithSameNamespaceAddedTwiceTestFixture.cs
  5. 6
      src/AddIns/DisplayBindings/XmlEditor/Test/Editor/TwoRegisteredSchemasTestFixture.cs
  6. 292
      src/AddIns/DisplayBindings/XmlEditor/Test/Schema.Multiple/DuplicateSchemaNamespaceAddedToCollectionTestFixture.cs
  7. 58
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/XmlSchemaCompletionCollectionFileNamesTests.cs
  8. 29
      src/AddIns/DisplayBindings/XmlEditor/Test/Utils/XmlSchemaCompletionCollectionFileNames.cs
  9. 3
      src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj
  10. 2
      src/AddIns/DisplayBindings/XmlEditor/XmlEditor.sln

10
src/AddIns/DisplayBindings/XmlEditor/Project/Src/RegisteredXmlSchemas.cs

@ -144,8 +144,8 @@ namespace ICSharpCode.XmlEditor @@ -144,8 +144,8 @@ namespace ICSharpCode.XmlEditor
string baseUri = XmlSchemaCompletion.GetUri(fileName);
XmlSchemaCompletion schema = factory.CreateXmlSchemaCompletionData(baseUri, fileName);
schema.FileName = fileName;
schema.IsReadOnly = readOnly;
return schema;
schema.IsReadOnly = readOnly;
return schema;
} catch (Exception ex) {
schemaErrors.Add(new RegisteredXmlSchemaError("Unable to read schema '" + fileName + "'.", ex));
}
@ -160,11 +160,7 @@ namespace ICSharpCode.XmlEditor @@ -160,11 +160,7 @@ namespace ICSharpCode.XmlEditor
void AddSchema(XmlSchemaCompletion schema)
{
if (schema.HasNamespaceUri) {
if (!schemas.Contains(schema.NamespaceUri)) {
schemas.Add(schema);
} else {
schemaErrors.Add(new RegisteredXmlSchemaError("Ignoring duplicate schema namespace '" + schema.NamespaceUri + "'. File '" + schema.FileName + "'."));
}
schemas.Add(schema);
} else {
schemaErrors.Add(new RegisteredXmlSchemaError("Ignoring schema with no namespace '" + schema.FileName + "'."));
}

2
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletion.cs

@ -358,7 +358,7 @@ namespace ICSharpCode.XmlEditor @@ -358,7 +358,7 @@ namespace ICSharpCode.XmlEditor
void ReadSchema(XmlReader reader)
{
try {
schema = XmlSchema.Read(reader, new ValidationEventHandler(SchemaValidation));
schema = XmlSchema.Read(reader, SchemaValidation);
if (schema != null) {
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.ValidationEventHandler += SchemaValidation;

76
src/AddIns/DisplayBindings/XmlEditor/Project/Src/XmlSchemaCompletionCollection.cs

@ -41,8 +41,10 @@ namespace ICSharpCode.XmlEditor @@ -41,8 +41,10 @@ namespace ICSharpCode.XmlEditor
XmlCompletionItemCollection completionItems = new XmlCompletionItemCollection();
foreach (XmlSchemaCompletion schema in this) {
XmlCompletionItem completionData = new XmlCompletionItem(schema.NamespaceUri, XmlCompletionItemType.NamespaceUri);
completionItems.Add(completionData);
XmlCompletionItem completionItem = new XmlCompletionItem(schema.NamespaceUri, XmlCompletionItemType.NamespaceUri);
if (!completionItems.Contains(completionItem)) {
completionItems.Add(completionItem);
}
}
return completionItems;
@ -82,14 +84,10 @@ namespace ICSharpCode.XmlEditor @@ -82,14 +84,10 @@ namespace ICSharpCode.XmlEditor
public void AddRange(XmlSchemaCompletionCollection schemas)
{
for (int i = 0; i < schemas.Count; i++) {
this.Add(schemas[i]);
Add(schemas[i]);
}
}
/// <summary>
/// Gets the schema completion data with the same filename.
/// </summary>
/// <returns><see langword="null"/> if no matching schema found.</returns>
public XmlSchemaCompletion GetSchemaFromFileName(string fileName)
{
foreach (XmlSchemaCompletion schema in this) {
@ -100,32 +98,43 @@ namespace ICSharpCode.XmlEditor @@ -100,32 +98,43 @@ namespace ICSharpCode.XmlEditor
return null;
}
public XmlSchemaCompletion FindSchema(XmlElementPath path, XmlSchemaCompletion defaultSchema)
public XmlSchemaCompletionCollection GetSchemas(string namespaceUri)
{
if (path.Elements.HasItems) {
string namespaceUri = path.GetRootNamespace();
if (namespaceUri.Length > 0) {
return this[namespaceUri];
} else if (defaultSchema != null) {
path.SetNamespaceForUnqualifiedNames(defaultSchema.NamespaceUri);
return defaultSchema;
XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
foreach (XmlSchemaCompletion schema in this) {
if (schema.NamespaceUri == namespaceUri) {
schemas.Add(schema);
}
}
return null;
return schemas;
}
public XmlCompletionItemCollection GetChildElementCompletion(XmlElementPath path)
public XmlSchemaCompletionCollection GetSchemas(XmlElementPath path, XmlSchemaCompletion defaultSchema)
{
return GetChildElementCompletion(path, null);
string namespaceUri = path.GetRootNamespace();
if (String.IsNullOrEmpty(namespaceUri)) {
return GetSchemaCollectionUsingDefaultSchema(path, defaultSchema);
}
return GetSchemas(namespaceUri);
}
public XmlCompletionItemCollection GetChildElementCompletion(XmlElementPath path, XmlSchemaCompletion defaultSchema)
XmlSchemaCompletionCollection GetSchemaCollectionUsingDefaultSchema(XmlElementPath path, XmlSchemaCompletion defaultSchema)
{
XmlSchemaCompletion schema = FindSchema(path, defaultSchema);
if (schema != null) {
return schema.GetChildElementCompletion(path);
}
return new XmlCompletionItemCollection();
XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
if (defaultSchema != null) {
path.SetNamespaceForUnqualifiedNames(defaultSchema.NamespaceUri);
schemas.Add(defaultSchema);
}
return schemas;
}
public XmlCompletionItemCollection GetChildElementCompletion(XmlElementPath path)
{
XmlCompletionItemCollection items = new XmlCompletionItemCollection();
foreach (XmlSchemaCompletion schema in GetSchemas(path, null)) {
items.AddRange(schema.GetChildElementCompletion(path));
}
return items;
}
public XmlCompletionItemCollection GetElementCompletionForAllNamespaces(XmlElementPath path, XmlSchemaCompletion defaultSchema)
@ -161,8 +170,7 @@ namespace ICSharpCode.XmlEditor @@ -161,8 +170,7 @@ namespace ICSharpCode.XmlEditor
{
XmlCompletionItemCollection items = new XmlCompletionItemCollection();
foreach (XmlNamespace ns in namespaces) {
XmlSchemaCompletion schema = this[ns.Name];
if (schema != null) {
foreach (XmlSchemaCompletion schema in GetSchemas(ns.Name)) {
items.AddRange(schema.GetRootElementCompletion(ns.Prefix));
}
}
@ -171,11 +179,11 @@ namespace ICSharpCode.XmlEditor @@ -171,11 +179,11 @@ namespace ICSharpCode.XmlEditor
public XmlCompletionItemCollection GetAttributeCompletion(XmlElementPath path, XmlSchemaCompletion defaultSchema)
{
XmlSchemaCompletion schema = FindSchema(path, defaultSchema);
if (schema != null) {
return schema.GetAttributeCompletion(path);
XmlCompletionItemCollection items = new XmlCompletionItemCollection();
foreach (XmlSchemaCompletion schema in GetSchemas(path, defaultSchema)) {
items.AddRange(schema.GetAttributeCompletion(path));
}
return new XmlCompletionItemCollection();
return items;
}
public XmlCompletionItemCollection GetElementCompletion(string textUpToCursor, XmlSchemaCompletion defaultSchema)
@ -221,11 +229,11 @@ namespace ICSharpCode.XmlEditor @@ -221,11 +229,11 @@ namespace ICSharpCode.XmlEditor
public XmlCompletionItemCollection GetAttributeValueCompletion(XmlElementPath path, string attributeName, XmlSchemaCompletion defaultSchema)
{
path.Compact();
XmlSchemaCompletion schema = FindSchema(path, defaultSchema);
if (schema != null) {
return schema.GetAttributeValueCompletion(path, attributeName);
XmlCompletionItemCollection items = new XmlCompletionItemCollection();
foreach (XmlSchemaCompletion schema in GetSchemas(path, defaultSchema)) {
items.AddRange(schema.GetAttributeValueCompletion(path, attributeName));
}
return new XmlCompletionItemCollection();
return items;
}
}
}

7
src/AddIns/DisplayBindings/XmlEditor/Test/Editor/RegisteredSchemaWithSameNamespaceAddedTwiceTestFixture.cs

@ -51,12 +51,9 @@ namespace XmlEditor.Tests.Editor @@ -51,12 +51,9 @@ namespace XmlEditor.Tests.Editor
}
[Test]
public void SchemaNamespaceAlreadyAddedRecordedAsError()
public void NoSchemaErrorsRecordedForDuplicateSchemaNamespace()
{
string message = @"Ignoring duplicate schema namespace 'http://test'. File 'c:\users\user\schemas\test2.xsd'.";
RegisteredXmlSchemaError error = new RegisteredXmlSchemaError(message);
RegisteredXmlSchemaError[] expectedErrors = new RegisteredXmlSchemaError[] { error };
Assert.AreEqual(expectedErrors, registeredXmlSchemas.GetSchemaErrors());
Assert.AreEqual(0, registeredXmlSchemas.GetSchemaErrors().Length);
}
}
}

6
src/AddIns/DisplayBindings/XmlEditor/Test/Editor/TwoRegisteredSchemasTestFixture.cs

@ -133,15 +133,15 @@ namespace XmlEditor.Tests.Editor @@ -133,15 +133,15 @@ namespace XmlEditor.Tests.Editor
[Test]
public void RemoveTestSchemaFiresUserSchemaRemovedEvent()
{
registeredXmlSchemas.RemoveUserDefinedSchema("http://test");
registeredXmlSchemas.RemoveUserDefinedSchema("http://test");
Assert.AreEqual(1, userSchemaRemovedEventFiredCount);
}
[Test]
public void TrytoRemoveTestSchemaTwiceButSchemaRemovedEventShouldOnlyFireOnce()
{
registeredXmlSchemas.RemoveUserDefinedSchema("http://test");
registeredXmlSchemas.RemoveUserDefinedSchema("http://test");
registeredXmlSchemas.RemoveUserDefinedSchema("http://test");
registeredXmlSchemas.RemoveUserDefinedSchema("http://test");
Assert.AreEqual(1, userSchemaRemovedEventFiredCount);
}

292
src/AddIns/DisplayBindings/XmlEditor/Test/Schema.Multiple/DuplicateSchemaNamespaceAddedToCollectionTestFixture.cs

@ -0,0 +1,292 @@ @@ -0,0 +1,292 @@
// <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.IO;
using ICSharpCode.XmlEditor;
using NUnit.Framework;
using XmlEditor.Tests.Utils;
namespace XmlEditor.Tests.Schema.Multiple
{
[TestFixture]
public class DuplicateSchemaNamespaceAddedToCollectionTestFixture
{
XmlSchemaCompletionCollection schemas;
XmlSchemaCompletion fooSchema;
XmlSchemaCompletion barSchema;
XmlSchemaCompletion duplicateFooSchema;
[SetUp]
public void Init()
{
CreateBarSchema();
CreateFooSchema();
CreateDuplicateFooSchema();
schemas = new XmlSchemaCompletionCollection();
schemas.Add(fooSchema);
schemas.Add(barSchema);
schemas.Add(duplicateFooSchema);
}
void CreateFooSchema()
{
string xml =
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"foo\" xmlns=\"foo\" elementFormDefault=\"qualified\">\r\n" +
" <xs:element name=\"foo-note\">\r\n" +
" <xs:complexType> \r\n" +
" <xs:sequence>\r\n" +
" <xs:element name=\"foo-text\" type=\"text-type\"/>\r\n" +
" </xs:sequence>\r\n" +
" </xs:complexType>\r\n" +
" </xs:element>\r\n" +
" <xs:complexType name=\"text-type\">\r\n" +
" <xs:attribute name=\"foo-text-attribute\">\r\n" +
" <xs:simpleType>\r\n" +
" <xs:restriction base=\"xs:string\">\r\n" +
" <xs:enumeration value=\"first\"/>\r\n" +
" <xs:enumeration value=\"second\"/>\r\n" +
" <xs:enumeration value=\"third\"/>\r\n" +
" <xs:enumeration value=\"fourth\"/>\r\n" +
" </xs:restriction>\r\n" +
" </xs:simpleType>\r\n" +
" </xs:attribute>\r\n" +
" </xs:complexType>\r\n" +
"</xs:schema>";
fooSchema = new XmlSchemaCompletion(new StringReader(xml));
fooSchema.FileName = "foo.xsd";
}
void CreateBarSchema()
{
string xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='bar' />";
barSchema = new XmlSchemaCompletion(new StringReader(xml));
barSchema.FileName = "bar.xsd";
}
void CreateDuplicateFooSchema()
{
string xml =
"<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"foo\" xmlns=\"foo\" elementFormDefault=\"qualified\">\r\n" +
" <xs:element name=\"duplicate-foo-note\">\r\n" +
" <xs:complexType> \r\n" +
" <xs:sequence>\r\n" +
" <xs:element name=\"duplicate-foo-text\" type=\"duplicate-text-type\"/>\r\n" +
" </xs:sequence>\r\n" +
" </xs:complexType>\r\n" +
" </xs:element>\r\n" +
" <xs:complexType name=\"duplicate-text-type\">\r\n" +
" <xs:attribute name=\"duplicate-foo-text-attribute\">\r\n" +
" <xs:simpleType>\r\n" +
" <xs:restriction base=\"xs:string\">\r\n" +
" <xs:enumeration value=\"first\"/>\r\n" +
" <xs:enumeration value=\"second\"/>\r\n" +
" <xs:enumeration value=\"third\"/>\r\n" +
" <xs:enumeration value=\"fourth\"/>\r\n" +
" </xs:restriction>\r\n" +
" </xs:simpleType>\r\n" +
" </xs:attribute>\r\n" +
" </xs:complexType>\r\n" +
" <xs:element name=\"foo-note\">\r\n" +
" <xs:complexType> \r\n" +
" <xs:sequence>\r\n" +
" <xs:element name=\"foo-text\" type=\"text-type\"/>\r\n" +
" </xs:sequence>\r\n" +
" </xs:complexType>\r\n" +
" </xs:element>\r\n" +
" <xs:complexType name=\"text-type\">\r\n" +
" <xs:attribute name=\"foo-text-attribute\">\r\n" +
" <xs:simpleType>\r\n" +
" <xs:restriction base=\"xs:string\">\r\n" +
" <xs:enumeration value=\"first\"/>\r\n" +
" <xs:enumeration value=\"second\"/>\r\n" +
" <xs:enumeration value=\"third\"/>\r\n" +
" <xs:enumeration value=\"fourth\"/>\r\n" +
" </xs:restriction>\r\n" +
" </xs:simpleType>\r\n" +
" </xs:attribute>\r\n" +
" </xs:complexType>\r\n" +
"</xs:schema>";
duplicateFooSchema = new XmlSchemaCompletion(new StringReader(xml));
duplicateFooSchema.FileName = "duplicate-foo.xsd";
}
[Test]
public void SchemasHaveTheSameNamespace()
{
Assert.AreEqual(fooSchema.NamespaceUri, duplicateFooSchema.NamespaceUri);
}
[Test]
public void SchemaNamespaceIsNotEmptyString()
{
Assert.AreEqual("foo", fooSchema.NamespaceUri);
}
[Test]
public void ThreeSchemasInCollection()
{
Assert.AreEqual(3, schemas.Count);
}
[Test]
public void GetSchemasForFooNamespaceReturnsTwoSchemas()
{
Assert.AreEqual(2, schemas.GetSchemas("foo").Count);
}
[Test]
public void GetSchemasForFooNamespaceReturnedSchemasContainDuplicateSchemas()
{
XmlSchemaCompletionCollection matchedSchemas = schemas.GetSchemas("foo");
string[] expectedFileNames = new string[] {"foo.xsd", "duplicate-foo.xsd"};
Assert.AreEqual(expectedFileNames, XmlSchemaCompletionCollectionFileNames.GetFileNames(matchedSchemas));
}
[Test]
public void GetSchemasForElementPathReturnsEmptyCollectionWhenNoNamespaceUsedInPathAndNoDefaultSchema()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("root", String.Empty));
XmlSchemaCompletionCollection foundSchemas = schemas.GetSchemas(path, null);
Assert.AreEqual(0, foundSchemas.Count);
}
[Test]
public void GetSchemasForElementPathReturnsDefaultSchemaWhenNoNamespaceUsedInPathButHasDefaultSchema()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("root", String.Empty));
XmlSchemaCompletion defaultSchema = new XmlSchemaCompletion();
defaultSchema.FileName = "default.xsd";
XmlSchemaCompletionCollection foundSchemas = schemas.GetSchemas(path, defaultSchema);
string[] expectedFileNames = new string[] {"default.xsd"};
Assert.AreEqual(expectedFileNames, XmlSchemaCompletionCollectionFileNames.GetFileNames(foundSchemas));
}
[Test]
public void GetSchemasForElementPathUpdatesElementNamespacesUsingDefaultSchemaNamespace()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("root", String.Empty));
path.AddElement(new QualifiedName("different-ns-element", "unknown-namespace"));
path.AddElement(new QualifiedName("child", String.Empty));
string xml = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='default-ns' />";
XmlSchemaCompletion defaultSchema = new XmlSchemaCompletion(new StringReader(xml));
defaultSchema.FileName = "default.xsd";
schemas.GetSchemas(path, defaultSchema);
XmlElementPath expectedPath = new XmlElementPath();
expectedPath.AddElement(new QualifiedName("root", "default-ns"));
expectedPath.AddElement(new QualifiedName("different-ns-element", "unknown-namespace"));
expectedPath.AddElement(new QualifiedName("child", "default-ns"));
Assert.AreEqual(expectedPath, path);
}
[Test]
public void GetSchemasForElementPathReturnsDuplicateFooSchemasWhenFooNamespaceUsedInPath()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("root", "foo"));
XmlSchemaCompletionCollection foundSchemas = schemas.GetSchemas(path, null);
string[] expectedFileNames = new string[] {"foo.xsd", "duplicate-foo.xsd"};
Assert.AreEqual(expectedFileNames, XmlSchemaCompletionCollectionFileNames.GetFileNames(foundSchemas));
}
[Test]
public void NamespaceCompletionDoesNotContainDuplicateNamespaces()
{
XmlCompletionItemCollection items = schemas.GetNamespaceCompletion();
items.Sort();
List<XmlCompletionItem> expectedItems = new List<XmlCompletionItem>();
expectedItems.Add(new XmlCompletionItem("bar", XmlCompletionItemType.NamespaceUri));
expectedItems.Add(new XmlCompletionItem("foo", XmlCompletionItemType.NamespaceUri));
Assert.AreEqual(expectedItems.ToArray(), items.ToArray());
}
[Test]
public void GetRootElementCompletionReturnsRootElementsFromBothFooSchemas()
{
XmlNamespaceCollection namespaces = new XmlNamespaceCollection();
namespaces.Add(new XmlNamespace(String.Empty, "foo"));
XmlCompletionItemCollection items = schemas.GetRootElementCompletion(namespaces);
items.Sort();
List<XmlCompletionItem> expectedItems = new List<XmlCompletionItem>();
expectedItems.Add(new XmlCompletionItem("duplicate-foo-note", XmlCompletionItemType.XmlElement));
expectedItems.Add(new XmlCompletionItem("foo-note", XmlCompletionItemType.XmlElement));
Assert.AreEqual(expectedItems.ToArray(), items.ToArray());
}
[Test]
public void GetChildElementCompletionForDuplicateFooRootElement()
{
XmlElementPath path = new XmlElementPath();
path.AddElement(new QualifiedName("duplicate-foo-note", "foo"));
XmlCompletionItemCollection items = schemas.GetChildElementCompletion(path);
items.Sort();
List<XmlCompletionItem> expectedItems = new List<XmlCompletionItem>();
expectedItems.Add(new XmlCompletionItem("duplicate-foo-text", XmlCompletionItemType.XmlElement));
Assert.AreEqual(expectedItems.ToArray(), items.ToArray());
}
[Test]
public void GetAttributeCompletionReturnsAttributesFromDuplicateFooSchema()
{
string xml =
"<duplicate-foo-note xmlns='foo'>\r\n" +
" <duplicate-foo-text ";
XmlCompletionItemCollection items = schemas.GetAttributeCompletion(xml, null);
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("duplicate-foo-text-attribute", XmlCompletionItemType.XmlAttribute));
Assert.AreEqual(expectedItems, items);
}
[Test]
public void GetAttributeValueCompletionReturnsValuesForDuplicateFooSchema()
{
string xml =
"<duplicate-foo-note xmlns='foo'>\r\n" +
" <duplicate-foo-text duplicate-foo-text-attribute='f'";
string xmlUpToCursor = xml.Substring(0, xml.Length - 1);
XmlCompletionItemCollection items = schemas.GetAttributeValueCompletion('f', xmlUpToCursor, null);
items.Sort();
XmlCompletionItemCollection expectedItems = new XmlCompletionItemCollection();
expectedItems.Add(new XmlCompletionItem("first", XmlCompletionItemType.XmlAttributeValue));
expectedItems.Add(new XmlCompletionItem("fourth", XmlCompletionItemType.XmlAttributeValue));
expectedItems.Add(new XmlCompletionItem("second", XmlCompletionItemType.XmlAttributeValue));
expectedItems.Add(new XmlCompletionItem("third", XmlCompletionItemType.XmlAttributeValue));
Assert.AreEqual(expectedItems, items);
}
}
}

58
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/Tests/XmlSchemaCompletionCollectionFileNamesTests.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// <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.XmlEditor;
using NUnit.Framework;
namespace XmlEditor.Tests.Utils.Tests
{
[TestFixture]
public class XmlSchemaCompletionCollectionFileNamesTests
{
XmlSchemaCompletionCollection schemas;
[SetUp]
public void Init()
{
schemas = new XmlSchemaCompletionCollection();
}
[Test]
public void NoItemsInSchemaCollection()
{
Assert.AreEqual(0, XmlSchemaCompletionCollectionFileNames.GetFileNames(schemas).Length);
}
[Test]
public void OneSchemaWithFileName()
{
XmlSchemaCompletion schema = new XmlSchemaCompletion();
schema.FileName = "a.xsd";
schemas.Add(schema);
string[] expectedFileNames = new string[] {"a.xsd"};
Assert.AreEqual(expectedFileNames, XmlSchemaCompletionCollectionFileNames.GetFileNames(schemas));
}
[Test]
public void TwoSchemasWithFileName()
{
XmlSchemaCompletion schema = new XmlSchemaCompletion();
schema.FileName = "a.xsd";
schemas.Add(schema);
schema = new XmlSchemaCompletion();
schema.FileName = "b.xsd";
schemas.Add(schema);
string[] expectedFileNames = new string[] {"a.xsd", "b.xsd"};
Assert.AreEqual(expectedFileNames, XmlSchemaCompletionCollectionFileNames.GetFileNames(schemas));
}
}
}

29
src/AddIns/DisplayBindings/XmlEditor/Test/Utils/XmlSchemaCompletionCollectionFileNames.cs

@ -0,0 +1,29 @@ @@ -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.Collections.Generic;
using ICSharpCode.XmlEditor;
namespace XmlEditor.Tests.Utils
{
public class XmlSchemaCompletionCollectionFileNames
{
XmlSchemaCompletionCollectionFileNames()
{
}
public static string[] GetFileNames(XmlSchemaCompletionCollection schemas)
{
List<string> fileNames = new List<string>();
foreach (XmlSchemaCompletion schema in schemas) {
fileNames.Add(schema.FileName);
}
return fileNames.ToArray();
}
}
}

3
src/AddIns/DisplayBindings/XmlEditor/Test/XmlEditor.Tests.csproj

@ -154,6 +154,7 @@ @@ -154,6 +154,7 @@
<Compile Include="Paths\QualifiedNameToStringTests.cs" />
<Compile Include="Paths\SingleElementPathByNamespaceTestFixture.cs" />
<Compile Include="Paths\TwoElementPathsByNamespaceTestFixture.cs" />
<Compile Include="Schema.Multiple\DuplicateSchemaNamespaceAddedToCollectionTestFixture.cs" />
<Compile Include="Schema.Multiple\TwoSchemaChildElementCompletionTestFixture.cs" />
<Compile Include="Schema\SchemaHasNamespaceTests.cs" />
<Compile Include="Schema\SingleElementSchemaTestFixture.cs" />
@ -258,7 +259,9 @@ @@ -258,7 +259,9 @@
<Compile Include="Utils\Tests\MockTextEditorTests.cs" />
<Compile Include="Utils\Tests\MockXmlSchemaCompletionDataFactoryTests.cs" />
<Compile Include="Utils\Tests\MockXmlSchemasPanelTests.cs" />
<Compile Include="Utils\Tests\XmlSchemaCompletionCollectionFileNamesTests.cs" />
<Compile Include="Utils\TextSection.cs" />
<Compile Include="Utils\XmlSchemaCompletionCollectionFileNames.cs" />
<Compile Include="XPathQuery\XmlNamespaceTests.cs" />
<Compile Include="XPathQuery\GetNamespacesFromListViewTestFixture.cs" />
<Compile Include="XPathQuery\RunXPathQueryTests.cs" />

2
src/AddIns/DisplayBindings/XmlEditor/XmlEditor.sln

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
# SharpDevelop 4.0.0.5201
# SharpDevelop 4.0.0.5293
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor", "Project\XmlEditor.csproj", "{DCA2703D-250A-463E-A68A-07ED105AE6BD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XmlEditor.Tests", "Test\XmlEditor.Tests.csproj", "{FC0FE702-A87D-4D70-A9B6-1ECCD611125F}"

Loading…
Cancel
Save