3 using System.Windows.Media.Converters;
4 using System.Windows.Media;
6 namespace MonoTests.System.Windows.Media {
9 public class MatrixValueSerializerTest {
10 const double DELTA = 0.000000001d;
12 void CheckMatrix (Matrix expected, Matrix actual)
14 Assert.AreEqual (expected.M11, actual.M11, DELTA);
15 Assert.AreEqual (expected.M12, actual.M12, DELTA);
16 Assert.AreEqual (expected.M21, actual.M21, DELTA);
17 Assert.AreEqual (expected.M22, actual.M22, DELTA);
18 Assert.AreEqual (expected.OffsetX, actual.OffsetX, DELTA);
19 Assert.AreEqual (expected.OffsetY, actual.OffsetY, DELTA);
23 public void CanConvertFromString ()
25 var serializer = new MatrixValueSerializer ();
26 Assert.IsTrue (serializer.CanConvertFromString ("", null));
30 public void CanConvertToString ()
32 var serializer = new MatrixValueSerializer ();
33 Assert.IsTrue (serializer.CanConvertToString (new Matrix (1, 2, 3, 4, 5 ,6), null));
34 Assert.IsFalse (serializer.CanConvertToString ("", null));
38 public void ConvertFromString ()
40 var serializer = new MatrixValueSerializer ();
41 object obj = serializer.ConvertFromString ("1, 2, 3, 4, 5 ,6", null);
42 Assert.AreEqual (typeof (Matrix), obj.GetType ());
43 CheckMatrix (new Matrix (1, 2, 3, 4, 5, 6), (Matrix)obj);
47 public void RoundTripConvert()
49 var serializer = new MatrixValueSerializer ();
50 var matrix = new Matrix (1.1, 2.2, 3.3, 4.4, 5.5, 6.6);
51 var obj = serializer.ConvertFromString (serializer.ConvertToString (matrix, null), null);
52 CheckMatrix (matrix, (Matrix)obj);
56 [ExpectedException (typeof (FormatException))]
57 public void ConvertFromStringShouldThrowExceptionWhenStringHasInvalidFormat ()
59 var serializer = new MatrixValueSerializer ();
60 serializer.ConvertFromString ("a,b,c,d,e,f", null);
64 [ExpectedException (typeof (NotSupportedException))]
65 public void ConvertFromStringShouldThrowExceptionWhenStringIsNull ()
67 var serializer = new MatrixValueSerializer ();
68 serializer.ConvertFromString (null, null);
72 [ExpectedException (typeof (NotSupportedException))]
73 public void ConvertToStringShouldThrowExceptionWhenInvalidType ()
75 var serializer = new MatrixValueSerializer ();
76 serializer.ConvertToString (10, null);