blob: cabd53a3c951fe0343e93ebf5660faf03db50108 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
using NUnit.Framework;
using System.IO;
using System.Text;
using System.Xml;
using MonoDevelop.Xml.Editor;
namespace MonoDevelop.Xml.Tests.Schema
{
[TestFixture]
public class SchemaAssociationTests
{
StringBuilder xml;
XmlWriter writer;
[SetUp]
public void Init ()
{
xml = new StringBuilder ();
XmlWriterSettings settings = new XmlWriterSettings ();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
settings.IndentChars = "\t";
writer = XmlWriter.Create (xml, settings);
}
[Test]
public void ToXml()
{
XmlFileAssociation schema = new XmlFileAssociation (".xml", "http://mono-project.com", null);
schema.WriteTo(writer);
writer.Close ();
string expectedXml = "<SchemaAssociation extension=\".xml\" namespace=\"http://mono-project.com\" prefix=\"\" />";
Assert.AreEqual(expectedXml, xml.ToString());
}
[Test]
public void FromXml()
{
XmlFileAssociation expectedSchema = new XmlFileAssociation (".xml", "http://mono-project.com", null);
expectedSchema.WriteTo(writer);
writer.Close ();
string propertiesXml = "<SerializedNode>" + xml.ToString() + "</SerializedNode>";
XmlTextReader reader = new XmlTextReader (new StringReader(propertiesXml));
XmlFileAssociation schema = new XmlFileAssociation ();
schema = (XmlFileAssociation)schema.ReadFrom (reader);
Assert.AreEqual(expectedSchema.Extension, schema.Extension);
Assert.AreEqual(expectedSchema.NamespacePrefix, schema.NamespacePrefix);
Assert.AreEqual(expectedSchema.NamespaceUri, schema.NamespaceUri);
}
[Test]
public void FromXmlMissingSchemaAssociation()
{
string propertiesXml = "<SerializedNode/>";
XmlTextReader reader = new XmlTextReader(new StringReader(propertiesXml));
XmlFileAssociation schema = new XmlFileAssociation();
Assert.IsNull(schema.ReadFrom (reader));
}
}
}
|