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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
//
// Copyright (C) 2010 Novell Inc. http://novell.com
//
// 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 System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Text;
using System.Xaml;
using System.Xaml.Schema;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.Xaml.Schema
{
[TestFixture]
public class XamlValueConverterTest
{
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorNullConverterTypeTargetType ()
{
// either of them must be non-null.
new XamlValueConverter<TypeConverter> (null, null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorNullConverterTypeTargetTypeNull ()
{
// either of them must be non-null.
new XamlValueConverter<TypeConverter> (null, null, null);
}
[Test]
public void ConstructorOnlyWithName ()
{
// ok
new XamlValueConverter<TypeConverter> (null, null, "Foo");
}
[Test]
public void ConstructorNullConverterType ()
{
// ok
var c = new XamlValueConverter<TypeConverter> (null, XamlLanguage.Int32);
Assert.IsNull (c.ConverterInstance, "#1");
}
[Test]
public void ConstructorNullTargetType ()
{
// ok
var c = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), null);
Assert.IsTrue (c.ConverterInstance is Int32Converter, "#1");
}
[Test]
public void ConstructorNullName ()
{
// ok
new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32, null);
}
[Test]
public void ConverterTargetMismatch ()
{
// ok
var c = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.String, null);
Assert.IsTrue (c.ConverterInstance is Int32Converter, "#1");
}
[Test]
[ExpectedException (typeof (XamlSchemaException))]
public void InconsistentConverterType ()
{
var c = new XamlValueConverter<TypeConverter> (typeof (int), XamlLanguage.String, null);
Assert.IsNull (c.ConverterInstance, "#1");
}
[Test]
public void ObjectType ()
{
// This test asserts that XamlLanguage.Object.TypeConverter.ConverterType is null for different reason.
var c = new XamlValueConverter<TypeConverter> (typeof (TypeConverter), XamlLanguage.Object, null);
Assert.IsNotNull (c.ConverterInstance, "#1");
Assert.IsNull (XamlLanguage.Object.TypeConverter.ConverterInstance, "#2");
}
[Test]
public void Equality ()
{
// ok
var c1 = new XamlValueConverter<TypeConverter> (null, XamlLanguage.Int32);
var c2 = new XamlValueConverter<TypeConverter> (null, XamlLanguage.Int32);
var c3 = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32);
var c4 = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32, null);
var c5 = new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32, "Foo");
Assert.IsTrue (c1 == c2, "#1");
Assert.IsFalse (c1 == c3, "#2");
Assert.IsTrue (c3 == c4, "#3");
Assert.IsFalse (c4 == c5, "#4");
}
[Test]
public void TestToString ()
{
Assert.AreEqual ("Int32Converter(Int32)", new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32).ToString (), "#1");
Assert.AreEqual ("Foo", new XamlValueConverter<TypeConverter> (typeof (Int32Converter), XamlLanguage.Int32, "Foo").ToString (), "#2");
Assert.AreEqual ("Int32Converter", new XamlValueConverter<TypeConverter> (typeof (Int32Converter), null).ToString (), "#1");
Assert.AreEqual ("Int32", new XamlValueConverter<TypeConverter> (null, XamlLanguage.Int32).ToString (), "#3"); // huh, really? no difference from ConverterType?
}
}
}
|