correct asserts in the test
[mono.git] / mcs / class / System / Test / System.ComponentModel / ArrayConverterTests.cs
1 //
2 // System.ComponentModel.ArrayConverter test cases
3 //
4 // Authors:
5 //      Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (c) 2006 Gert Driesen
8 //
9
10 using System;
11 using System.ComponentModel;
12 using System.Globalization;
13
14 using NUnit.Framework;
15
16 namespace MonoTests.System.ComponentModel
17 {
18         [TestFixture]
19         public class ArrayConverterTests
20         {
21                 private ArrayConverter converter;
22                 
23                 [SetUp]
24                 public void SetUp ()
25                 {
26                         converter = new ArrayConverter ();
27                 }
28
29                 [Test]
30                 public void ConvertTo ()
31                 {
32                         int [] numbers = new int [] { 5, 7 };
33                         string text = (string) converter.ConvertTo (null, CultureInfo.InvariantCulture,
34                                 numbers, typeof (string));
35                         Assert.AreEqual ("Int32[] Array", text);
36                 }
37
38                 [Test]
39                 public void ConvertTo_DestinationType_Null ()
40                 {
41                         int[] numbers = new int[] { 5, 7 };
42
43                         try {
44                                 converter.ConvertTo (null, CultureInfo.InvariantCulture,
45                                         numbers, (Type) null);
46                                 Assert.Fail ("#1");
47                         } catch (ArgumentNullException ex) {
48                                 Assert.AreEqual ("destinationType", ex.ParamName, "#2");
49                         }
50                 }
51
52                 [Test]
53                 public void GetProperties ()
54                 {
55                         int [] numbers = new int [] { 5, 7 };
56                         PropertyDescriptorCollection pds = converter.GetProperties (null,
57                                 numbers, null);
58                         Assert.IsNotNull (pds, "#A1");
59                         Assert.AreEqual (2, pds.Count, "#A2");
60
61                         PropertyDescriptor pd = pds [0];
62                         Assert.AreEqual (numbers.GetType (), pd.ComponentType, "#B1");
63                         Assert.AreEqual (false, pd.IsReadOnly, "#B2");
64                         Assert.AreEqual ("[0]", pd.Name, "#B3");
65                         Assert.AreEqual (typeof (int), pd.PropertyType, "#B4");
66                         Assert.IsFalse (pd.CanResetValue (numbers), "#B5");
67                         Assert.AreEqual (5, pd.GetValue (numbers), "#B6");
68                         pd.SetValue (numbers, 9);
69                         Assert.AreEqual (9, pd.GetValue (numbers), "#B7");
70                         pd.ResetValue (numbers);
71                         Assert.AreEqual (9, pd.GetValue (numbers), "#B8");
72                         Assert.IsFalse (pd.ShouldSerializeValue (numbers), "#B9");
73
74                         pd = pds [1];
75                         Assert.AreEqual (numbers.GetType (), pd.ComponentType, "#C1");
76                         Assert.AreEqual (false, pd.IsReadOnly, "#C2");
77                         Assert.AreEqual ("[1]", pd.Name, "#C3");
78                         Assert.AreEqual (typeof (int), pd.PropertyType, "#C4");
79                         Assert.IsFalse (pd.CanResetValue (numbers), "#C5");
80                         Assert.AreEqual (7, pd.GetValue (numbers), "#C6");
81                         pd.SetValue (numbers, 3);
82                         Assert.AreEqual (3, pd.GetValue (numbers), "#C7");
83                         pd.ResetValue (numbers);
84                         Assert.AreEqual (3, pd.GetValue (numbers), "#C8");
85                         Assert.IsFalse (pd.ShouldSerializeValue (numbers), "#C9");
86                 }
87
88                 [Test]
89                 [ExpectedException (typeof (NullReferenceException))]
90                 public void GetProperties_Value_Null ()
91                 {
92                         converter.GetProperties (null, null, null);
93                 }
94
95                 [Test]
96                 public void GetPropertiesSupported ()
97                 {
98                         Assert.IsTrue (converter.GetPropertiesSupported (null));
99                 }
100         }
101 }