2 // MonoTests.System.ComponentModel.NullableConverterTest
5 // Ivan N. Zlatev <contact@i-nz.net>
7 // Copyright (C) 2008 Ivan N. Zlatev
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.ComponentModel;
35 using System.ComponentModel.Design.Serialization;
36 using System.Globalization;
38 using NUnit.Framework;
40 namespace MonoTests.System.ComponentModel
43 public class NullableConverterTest
45 [TypeConverter (typeof(MyTypeConverter))]
51 private class MyTypeConverter : TypeConverter
53 public override bool GetStandardValuesSupported (ITypeDescriptorContext context)
58 public override TypeConverter.StandardValuesCollection GetStandardValues (ITypeDescriptorContext context)
60 return new TypeConverter.StandardValuesCollection (new object[] {});
65 public void PropertyValues ()
67 NullableConverter converter = new NullableConverter (typeof(MyType?));
68 Assert.AreEqual (typeof(MyType?), converter.NullableType, "#1");
69 Assert.AreEqual (typeof(MyType), converter.UnderlyingType, "#2");
70 Assert.AreEqual (typeof(MyTypeConverter), converter.UnderlyingTypeConverter.GetType(), "#2");
74 public void CanConvertFrom ()
76 NullableConverter converter = new NullableConverter (typeof(MyType?));
77 Assert.IsTrue (converter.CanConvertFrom (null, typeof(MyType)), "#1");
78 Assert.IsFalse (converter.CanConvertFrom (null, typeof(object)), "#2");
82 public void CanConvertTo ()
84 NullableConverter converter = new NullableConverter (typeof(MyType?));
85 Assert.IsTrue (converter.CanConvertTo (null, typeof(MyType)), "#1");
86 Assert.IsFalse (converter.CanConvertTo (null, typeof(object)), "#2");
90 public void ConvertFrom_EmptyString ()
92 NullableConverter converter = new NullableConverter (typeof(MyType?));
93 Assert.IsNull (converter.ConvertFrom (null, null, String.Empty), "#1");
97 public void GetStandardValues ()
99 NullableConverter converter = new NullableConverter (typeof(MyType?));
100 Assert.IsTrue (converter.GetStandardValuesSupported (null), "#1");
101 TypeConverter.StandardValuesCollection values = converter.GetStandardValues (null);
102 // MyTypeConverter returns an empty values collection, but
103 // NullableConverter adds a null value to the set.
104 Assert.AreEqual (1, values.Count, "#2");
105 Assert.AreEqual (null, values[0], "#3");