public void CanConvertFrom () {
Assert.IsTrue (colconv.CanConvertFrom (typeof (String)), "CCF#1");
Assert.IsTrue (colconv.CanConvertFrom (null, typeof (String)), "CCF#1a");
- Assert.IsTrue (! colconv.CanConvertFrom (null, typeof (Rectangle)), "CCF#2");
- Assert.IsTrue (! colconv.CanConvertFrom (null, typeof (RectangleF)), "CCF#3");
- Assert.IsTrue (! colconv.CanConvertFrom (null, typeof (Point)), "CCF#4");
- Assert.IsTrue (! colconv.CanConvertFrom (null, typeof (PointF)), "CCF#5");
- Assert.IsTrue (! colconv.CanConvertFrom (null, typeof (Color)), "CCF#6");
- Assert.IsTrue (! colconv.CanConvertFrom (null, typeof (SizeF)), "CCF#7");
- Assert.IsTrue (! colconv.CanConvertFrom (null, typeof (Object)), "CCF#8");
- Assert.IsTrue (! colconv.CanConvertFrom (null, typeof (int)), "CCF#9");
+ Assert.IsFalse (colconv.CanConvertFrom (null, typeof (Rectangle)), "CCF#2");
+ Assert.IsFalse (colconv.CanConvertFrom (null, typeof (RectangleF)), "CCF#3");
+ Assert.IsFalse (colconv.CanConvertFrom (null, typeof (Point)), "CCF#4");
+ Assert.IsFalse (colconv.CanConvertFrom (null, typeof (PointF)), "CCF#5");
+ Assert.IsFalse (colconv.CanConvertFrom (null, typeof (Color)), "CCF#6");
+ Assert.IsFalse (colconv.CanConvertFrom (null, typeof (SizeF)), "CCF#7");
+ Assert.IsFalse (colconv.CanConvertFrom (null, typeof (Object)), "CCF#8");
+ Assert.IsFalse ( colconv.CanConvertFrom (null, typeof (int)), "CCF#9");
+ Assert.IsTrue (colconv.CanConvertFrom (null, typeof (InstanceDescriptor)), "CCF#10");
}
[Test]
public void CanConvertTo () {
Assert.IsTrue (colconv.CanConvertTo (typeof (String)), "CCT#1");
Assert.IsTrue (colconv.CanConvertTo (null, typeof (String)), "CCT#1a");
- Assert.IsTrue (! colconv.CanConvertTo (null, typeof (Rectangle)), "CCT#2");
- Assert.IsTrue (! colconv.CanConvertTo (null, typeof (RectangleF)), "CCT#3");
- Assert.IsTrue (! colconv.CanConvertTo (null, typeof (Point)), "CCT#4");
- Assert.IsTrue (! colconv.CanConvertTo (null, typeof (PointF)), "CCT#5");
- Assert.IsTrue (! colconv.CanConvertTo (null, typeof (Color)), "CCT#6");
- Assert.IsTrue (! colconv.CanConvertTo (null, typeof (SizeF)), "CCT#7");
- Assert.IsTrue (! colconv.CanConvertTo (null, typeof (Object)), "CCT#8");
- Assert.IsTrue (! colconv.CanConvertTo (null, typeof (int)), "CCT#9");
+ Assert.IsFalse (colconv.CanConvertTo (null, typeof (Rectangle)), "CCT#2");
+ Assert.IsFalse (colconv.CanConvertTo (null, typeof (RectangleF)), "CCT#3");
+ Assert.IsFalse (colconv.CanConvertTo (null, typeof (Point)), "CCT#4");
+ Assert.IsFalse (colconv.CanConvertTo (null, typeof (PointF)), "CCT#5");
+ Assert.IsFalse (colconv.CanConvertTo (null, typeof (Color)), "CCT#6");
+ Assert.IsFalse (colconv.CanConvertTo (null, typeof (SizeF)), "CCT#7");
+ Assert.IsFalse (colconv.CanConvertTo (null, typeof (Object)), "CCT#8");
+ Assert.IsFalse (colconv.CanConvertTo (null, typeof (int)), "CCT#9");
Assert.IsTrue (colconv.CanConvertTo (typeof (InstanceDescriptor)), "CCT#10");
}
[Test]
public void ConvertFrom ()
{
+ Color color = (Color) colconv.ConvertFrom (null, CultureInfo.InvariantCulture,
+ "#0x23190A44");
+ Assert.AreEqual (35, color.A, "CF1#1");
+ Assert.AreEqual (25, color.R, "CF1#2");
+ Assert.AreEqual (10, color.G, "CF1#3");
+ Assert.AreEqual (68, color.B, "CF1#4");
+
+ color = (Color) colconv.ConvertFrom (null, CultureInfo.InvariantCulture,
+ "#0X190A44");
+ Assert.AreEqual (0, color.A, "CF2#1");
+ Assert.AreEqual (25, color.R, "CF2#2");
+ Assert.AreEqual (10, color.G, "CF2#3");
+ Assert.AreEqual (68, color.B, "CF2#4");
+
+ color = (Color) colconv.ConvertFrom (null, CultureInfo.InvariantCulture,
+ "0x190A44");
+ Assert.AreEqual (255, color.A, "CF3#1");
+ Assert.AreEqual (25, color.R, "CF3#2");
+ Assert.AreEqual (10, color.G, "CF3#3");
+ Assert.AreEqual (68, color.B, "CF3#4");
+
+ color = (Color) colconv.ConvertFrom (null, CultureInfo.InvariantCulture,
+ "0X190A44");
+ Assert.AreEqual (255, color.A, "CF4#1");
+ Assert.AreEqual (25, color.R, "CF4#2");
+ Assert.AreEqual (10, color.G, "CF4#3");
+ Assert.AreEqual (68, color.B, "CF4#4");
+
+ color = (Color) colconv.ConvertFrom (null, CultureInfo.InvariantCulture,
+ "111111");
+ Assert.AreEqual (0, color.A, "CF5#1");
+ Assert.AreEqual (1, color.R, "CF5#2");
+ Assert.AreEqual (178, color.G, "CF5#3");
+ Assert.AreEqual (7, color.B, "CF5#4");
+
+ color = (Color) colconv.ConvertFrom (null, CultureInfo.InvariantCulture,
+ "10");
+ Assert.AreEqual (0, color.A, "CF6#1");
+ Assert.AreEqual (0, color.R, "CF6#2");
+ Assert.AreEqual (0, color.G, "CF6#3");
+ Assert.AreEqual (10, color.B, "CF6#4");
+
+ color = (Color) colconv.ConvertFrom (null, CultureInfo.InvariantCulture,
+ "0");
+ Assert.AreEqual (0, color.A, "CF7#1");
+ Assert.AreEqual (0, color.R, "CF7#2");
+ Assert.AreEqual (0, color.G, "CF7#3");
+ Assert.AreEqual (0, color.B, "CF7#4");
+
Assert.AreEqual (col, (Color) colconv.ConvertFrom (null,
CultureInfo.InvariantCulture, colStrInvariant), "CF#1");
Assert.AreEqual (colnamed, (Color) colconv.ConvertFrom (null,
Assert.AreEqual (Color.Empty, colconv.ConvertFrom (" "), "CF#4");
Assert.AreEqual (Color.Red, colconv.ConvertFrom ("Red"), "CF#5");
Assert.AreEqual (Color.Red, colconv.ConvertFrom (" Red "), "CF#6");
+
}
[Test]
}
[Test]
- //[ExpectedException (typeof (Exception))]
- //use try-catch, because dotnet throws Exception and
- //mono throws ArgumentException
+ [ExpectedException (typeof (Exception))]
public void ConvertFrom_x4 ()
{
- try {
- colconv.ConvertFrom (null, CultureInfo.InvariantCulture,
- "*1, 1");
- Assert.Fail ("Exception was expected");
- }
- catch (Exception) {
- Assert.IsTrue (true);
- }
+ colconv.ConvertFrom (null, CultureInfo.InvariantCulture,
+ "*1, 1");
}
[Test]
Color.FromArgb (10, 20, 30), typeof (String)), "CT#1");
Assert.AreEqual (colStrInvariant, colconv.ConvertTo (null, CultureInfo.InvariantCulture,
Color.FromArgb (255, 10, 20, 30), typeof (String)), "CT#2");
- Assert.AreEqual ("10" + CultureInfo.InvariantCulture.TextInfo.ListSeparator +
- " 20" + CultureInfo.InvariantCulture.TextInfo.ListSeparator +
- " 30" + CultureInfo.InvariantCulture.TextInfo.ListSeparator +
- " 40",
- colconv.ConvertTo (null, CultureInfo.InvariantCulture,
+ Assert.AreEqual ("10, 20, 30, 40", colconv.ConvertTo (null, CultureInfo.InvariantCulture,
Color.FromArgb (10, 20, 30, 40), typeof (String)), "CT#3");
-
Assert.AreEqual (colnamedStr, colconv.ConvertTo (null, CultureInfo.InvariantCulture,
colnamed, typeof (String)), "CT#4");
[Test]
public void CreateInstance ()
{
- Color colInstance;
-
Hashtable ht = new Hashtable ();
ht.Add ("R", 10); ht.Add ("G", 20); ht.Add ("B", 30);
}
[Test]
- public void GetPropertiesSupported () {
+ public void GetPropertiesSupported ()
+ {
Assert.IsTrue (!colconv.GetPropertiesSupported (), "GPS#1");
Assert.IsTrue (!colconv.GetPropertiesSupported (null), "GPS#2");
}
[Test]
- public void GetProperties () {
+ public void GetProperties ()
+ {
Attribute [] attrs;
Assert.AreEqual (null, colconv.GetProperties (col), "GP1#1");
}
[Test]
- public void ConvertFromInvariantString_string () {
+ public void ConvertFromInvariantString_string ()
+ {
Assert.AreEqual (col, colconv.ConvertFromInvariantString (colStrInvariant), "CFISS#1");
Assert.AreEqual (colnamed, colconv.ConvertFromInvariantString (colnamedStr), "CFISS#2");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
- public void ConvertFromInvariantString_string_exc_1 () {
+ public void ConvertFromInvariantString_InvalidComponentCount ()
+ {
colconv.ConvertFromInvariantString ("1, 2, 3, 4, 5");
}
[Test]
- [NUnit.Framework.Category ("NotDotNet")]
- [ExpectedException (typeof (ArgumentException))]
- public void ConvertFromInvariantString_string_exc_2 () {
- colconv.ConvertFromInvariantString ("hello");
+ public void ConvertFromInvariantString_InvalidNumber ()
+ {
+ try {
+ colconv.ConvertFromInvariantString ("hello");
+ Assert.Fail ("#1");
+ } catch (Exception ex) {
+ Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
+ Assert.IsNotNull (ex.InnerException, "#3");
+ Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
+ }
}
[Test]
- public void ConvertFromString_string () {
+ public void ConvertFromString_string ()
+ {
Assert.AreEqual (col, colconv.ConvertFromString (colStr), "CFSS#1");
Assert.AreEqual (colnamed, colconv.ConvertFromString (colnamedStr), "CFSS#2");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
- public void ConvertFromString_string_exc_1 () {
- colconv.ConvertFromString ("1, 2, 3, 4, 5");
+ public void ConvertFromString_InvalidComponentCount ()
+ {
+ CultureInfo culture = CultureInfo.CurrentCulture;
+ colconv.ConvertFromString (string.Format (culture,
+ "1{0} 2{0} 3{0} 4{0} 5", culture.TextInfo.ListSeparator[0]));
}
[Test]
- [NUnit.Framework.Category ("NotDotNet")]
- [ExpectedException (typeof (ArgumentException))]
- public void ConvertFromString_string_exc_2 () {
- colconv.ConvertFromString ("hello");
+ public void ConvertFromString_InvalidNumber ()
+ {
+ try {
+ colconv.ConvertFromString ("hello");
+ Assert.Fail ("#1");
+ } catch (Exception ex) {
+ Assert.AreEqual (typeof (Exception), ex.GetType (), "#2");
+ Assert.IsNotNull (ex.InnerException, "#3");
+ Assert.AreEqual (typeof (FormatException), ex.InnerException.GetType (), "#3");
+ }
}
[Test]
[Test]
public void ConvertToString_string () {
Assert.AreEqual (colStr, colconv.ConvertToString (col), "CFISS#1");
- Assert.AreEqual (colnamedStr, colconv.ConvertToString (colnamed), "CFISS#2");
+ Assert.AreEqual (colnamedStr, colconv.ConvertToString (colnamed), "CFISS#3");
}
[Test]
public void GetStandardValuesExclusive () {
Assert.AreEqual (false, colconv.GetStandardValuesExclusive ());
}
-
}
}