2 // ObjectWriter.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 Xaml.TestVocab.Console;
42 namespace MonoTests.System.Windows.Serialization
46 public class ObjectWriterTest {
50 public void GetReady()
61 public void TestTopLevel()
63 code = "<ConsoleApp xmlns=\"console\"></ConsoleApp>";
64 ConsoleApp app = new ConsoleApp();
69 public void TestTopLevelWithClassName()
71 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" x:Class=\"nnn\">\n"+
73 ConsoleApp app = new ConsoleApp();
78 public void TestTopLevelWithClassNameAndNamespace()
80 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\" x:Class=\"Test.Thing.nnn\">\n"+
82 ConsoleApp app = new ConsoleApp();
87 public void TestSimplestAddChild()
90 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
91 "<ConsoleWriter></ConsoleWriter>" +
93 ConsoleApp app = new ConsoleApp();
94 ConsoleWriter writer = new ConsoleWriter();
101 public void TestSimplestAddChildWithInstanceName()
103 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
104 "<ConsoleWriter x:Name=\"XXX\"></ConsoleWriter>" +
107 ConsoleApp app = new ConsoleApp();
108 ConsoleWriter writer = new ConsoleWriter();
109 app.AddChild(writer);
116 public void TestSimplestAddChildAndText()
118 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
119 "<ConsoleWriter>Hello</ConsoleWriter>" +
122 ConsoleApp app = new ConsoleApp();
123 ConsoleWriter writer = new ConsoleWriter();
124 writer.AddText("Hello");
125 app.AddChild(writer);
131 public void TestTextProperty()
133 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
134 "<ConsoleWriter Text=\"Hello\" />" +
137 ConsoleApp app = new ConsoleApp();
138 ConsoleWriter writer = new ConsoleWriter();
139 writer.Text = new ConsoleValueString("Hello");
140 app.AddChild(writer);
146 public void TestDependencyProperty()
148 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
149 "<ConsoleWriter ConsoleApp.Repetitions=\"3\" />" +
152 ConsoleApp app = new ConsoleApp();
153 ConsoleWriter writer = new ConsoleWriter();
154 ConsoleApp.SetRepetitions(writer, 3);
155 app.AddChild(writer);
161 public void TestObjectAsPropertyValue()
163 code = "<ConsoleApp xmlns=\"console\" xmlns:x=\"http://schemas.microsoft.com/winfx/xaml/2005\">\n"+
164 "<ConsoleReader>\n" +
165 "<ConsoleReader.Prompt><ConsoleWriter /></ConsoleReader.Prompt>\n" +
166 "</ConsoleReader>\n" +
169 ConsoleApp app = new ConsoleApp();
170 ConsoleReader reader = new ConsoleReader();
171 ConsoleWriter writer = new ConsoleWriter();
172 reader.Prompt = writer;
173 app.AddChild(reader);
179 private void compare(object expected)
181 string mapping = "<?Mapping ClrNamespace=\"Xaml.TestVocab.Console\" Assembly=\"./TestVocab.dll\" XmlNamespace=\"console\" ?>\n";
182 object o = ObjectWriter.Parse(new XmlTextReader(new StringReader(mapping + code)));
183 Assert.AreEqual(expected, o);