2 // Parser.cs - NUnit Test Cases for the xaml object builder
5 // Iain McCoy (iain@mccoy.id.au)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
33 using System.Diagnostics;
36 using System.Reflection;
38 using System.CodeDom.Compiler;
39 using Mono.Windows.Serialization;
40 using System.Windows.Serialization;
41 using Xaml.TestVocab.Console;
43 namespace MonoTests.System.Windows.Serialization
47 public class ParserTest {
51 public void GetReady()
62 public void TestTopLevel()
64 code = "<ConsoleApp xmlns=\"console\"></ConsoleApp>";
65 ConsoleApp app = new ConsoleApp();
70 public void TestTopLevelWithClassName()
72 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" x:Class=\"nnn\">\n"+
74 ConsoleApp app = new ConsoleApp();
79 public void TestTopLevelWithClassNameAndNamespace()
81 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" x:Class=\"Test.Thing.nnn\">\n"+
83 ConsoleApp app = new ConsoleApp();
88 public void TestSimplestAddChild()
91 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
92 "<ConsoleWriter></ConsoleWriter>" +
94 ConsoleApp app = new ConsoleApp();
95 ConsoleWriter writer = new ConsoleWriter();
102 public void TestSimplestAddChildWithInstanceName()
104 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
105 "<ConsoleWriter x:Name=\"XXX\"></ConsoleWriter>" +
108 ConsoleApp app = new ConsoleApp();
109 ConsoleWriter writer = new ConsoleWriter();
110 app.AddChild(writer);
117 public void TestSimplestAddChildAndText()
119 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
120 "<ConsoleWriter>Hello</ConsoleWriter>" +
123 ConsoleApp app = new ConsoleApp();
124 ConsoleWriter writer = new ConsoleWriter();
125 writer.AddText("Hello");
126 app.AddChild(writer);
132 public void TestTextProperty()
134 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
135 "<ConsoleWriter Text=\"Hello\" />" +
138 ConsoleApp app = new ConsoleApp();
139 ConsoleWriter writer = new ConsoleWriter();
140 writer.Text = new ConsoleValueString("Hello");
141 app.AddChild(writer);
147 public void TestDependencyProperty()
149 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
150 "<ConsoleWriter ConsoleApp.Repetitions=\"3\" />" +
153 ConsoleApp app = new ConsoleApp();
154 ConsoleWriter writer = new ConsoleWriter();
155 ConsoleApp.SetRepetitions(writer, 3);
156 app.AddChild(writer);
162 public void TestObjectAsPropertyValue()
164 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
165 "<ConsoleReader>\n" +
166 "<ConsoleReader.Prompt><ConsoleWriter /></ConsoleReader.Prompt>\n" +
167 "</ConsoleReader>\n" +
170 ConsoleApp app = new ConsoleApp();
171 ConsoleReader reader = new ConsoleReader();
172 ConsoleWriter writer = new ConsoleWriter();
173 reader.Prompt = writer;
174 app.AddChild(reader);
180 private void compare(object expected)
182 string mapping = "<?Mapping ClrNamespace=\"Xaml.TestVocab.Console\" Assembly=\"./TestVocab.dll\" XmlNamespace=\"console\" ?>\n";
183 object o = Parser.LoadXml(new XmlTextReader(new StringReader(mapping + code)));
184 Assert.AreEqual(expected, o);