2 // Copyright (C) 2010 Novell Inc. http://novell.com
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 using System.Collections.Generic;
25 using System.ComponentModel;
26 using System.Reflection;
29 using System.Xaml.Schema;
31 using NUnit.Framework;
33 namespace MonoTests.System.Xaml.Schema
36 public class XamlValueConverterTest
39 [ExpectedException (typeof (ArgumentException))]
40 public void ConstructorNullConverterTypeTargetType ()
42 // either of them must be non-null.
43 new XamlValueConverter<TypeConverter> (null, null);
47 [ExpectedException (typeof (ArgumentException))]
48 public void ConstructorNullConverterTypeTargetTypeNull ()
50 // either of them must be non-null.
51 new XamlValueConverter<TypeConverter> (null, null, null);
55 public void ConstructorOnlyWithName ()
58 new XamlValueConverter<TypeConverter> (null, null, "Foo");
62 public void ConstructorNullConverterType ()
65 var c = new XamlValueConverter<TypeConverter> (null, XamlLanguage.Int32);
66 Assert.IsNull (c.ConverterInstance, "#1");
70 public void ConstructorNullTargetType ()
73 var c = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), null);
74 Assert.IsTrue (c.ConverterInstance is Int32Converter, "#1");
78 public void ConstructorNullName ()
81 new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32, null);
85 public void ConverterTargetMismatch ()
88 var c = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.String, null);
89 Assert.IsTrue (c.ConverterInstance is Int32Converter, "#1");
93 [ExpectedException (typeof (XamlSchemaException))]
94 public void InconsistentConverterType ()
96 var c = new XamlValueConverter<TypeConverter> (typeof (int), XamlLanguage.String, null);
97 Assert.IsNull (c.ConverterInstance, "#1");
101 public void ObjectType ()
103 // This test asserts that XamlLanguage.Object.TypeConverter.ConverterType is null for different reason.
104 var c = new XamlValueConverter<TypeConverter> (typeof (TypeConverter), XamlLanguage.Object, null);
105 Assert.IsNotNull (c.ConverterInstance, "#1");
106 Assert.IsNull (XamlLanguage.Object.TypeConverter.ConverterInstance, "#2");
110 public void Equality ()
113 var c1 = new XamlValueConverter<TypeConverter> (null, XamlLanguage.Int32);
114 var c2 = new XamlValueConverter<TypeConverter> (null, XamlLanguage.Int32);
115 var c3 = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32);
116 var c4 = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32, null);
117 var c5 = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32, "Foo");
118 Assert.IsTrue (c1 == c2, "#1");
119 Assert.IsFalse (c1 == c3, "#2");
120 Assert.IsTrue (c3 == c4, "#3");
121 Assert.IsFalse (c4 == c5, "#4");
125 public void TestToString ()
127 Assert.AreEqual ("Int32Converter(Int32)", new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32).ToString (), "#1");
128 Assert.AreEqual ("Foo", new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32, "Foo").ToString (), "#2");
129 Assert.AreEqual ("Int32Converter", new XamlValueConverter<TypeConverter> (typeof (Int32Converter), null).ToString (), "#1");
130 Assert.AreEqual ("Int32", new XamlValueConverter<TypeConverter> (null, XamlLanguage.Int32).ToString (), "#3"); // huh, really? no difference from ConverterType?