// // ObjectWriter.cs - NUnit Test Cases for the xaml object builder // // Author: // Iain McCoy (iain@mccoy.id.au) // // (C) 2005 Iain McCoy // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using NUnit.Framework; using System; using System.Diagnostics; using System.IO; using System.Xml; using System.Reflection; using System.Windows; using System.CodeDom.Compiler; using Mono.Windows.Serialization; using Xaml.TestVocab.Console; namespace MonoTests.System.Windows.Serialization { [TestFixture] public class ObjectWriterTest { string code; [SetUp] public void GetReady() { } [TearDown] public void Clean() { code = null; } [Test] public void TestTopLevel() { code = ""; ConsoleApp app = new ConsoleApp(); compare(app); } [Test] public void TestTopLevelWithClassName() { code = "\n"+ ""; ConsoleApp app = new ConsoleApp(); compare(app); } [Test] public void TestTopLevelWithClassNameAndNamespace() { code = "\n"+ ""; ConsoleApp app = new ConsoleApp(); compare(app); } [Test] public void TestSimplestAddChild() { code = "\n"+ "" + ""; ConsoleApp app = new ConsoleApp(); ConsoleWriter writer = new ConsoleWriter(); app.AddChild(writer); compare(app); } [Test] public void TestSimplestAddChildWithInstanceName() { code = "\n"+ "" + ""; ConsoleApp app = new ConsoleApp(); ConsoleWriter writer = new ConsoleWriter(); app.AddChild(writer); compare(app); } [Test] public void TestSimplestAddChildAndText() { code = "\n"+ "Hello" + ""; ConsoleApp app = new ConsoleApp(); ConsoleWriter writer = new ConsoleWriter(); writer.AddText("Hello"); app.AddChild(writer); compare(app); } [Test] public void TestTextProperty() { code = "\n"+ "" + ""; ConsoleApp app = new ConsoleApp(); ConsoleWriter writer = new ConsoleWriter(); writer.Text = new ConsoleValueString("Hello"); app.AddChild(writer); compare(app); } [Test] public void TestDependencyProperty() { code = "\n"+ "" + ""; ConsoleApp app = new ConsoleApp(); ConsoleWriter writer = new ConsoleWriter(); ConsoleApp.SetRepetitions(writer, 3); app.AddChild(writer); compare(app); } [Test] public void TestObjectAsPropertyValue() { code = "\n"+ "\n" + "\n" + "\n" + ""; ConsoleApp app = new ConsoleApp(); ConsoleReader reader = new ConsoleReader(); ConsoleWriter writer = new ConsoleWriter(); reader.Prompt = writer; app.AddChild(reader); compare(app); } private void compare(object expected) { string mapping = "\n"; object o = ObjectWriter.Parse(new XmlTextReader(new StringReader(mapping + code))); Assert.AreEqual(expected, o); } } }