New test + update
[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 #if !TARGET_JVM
49                                 Assert.AreEqual ("destinationType", ex.ParamName, "#2");
50 #endif
51                         }
52                 }
53
54                 [Test]
55                 public void GetProperties ()
56                 {
57                         int [] numbers = new int [] { 5, 7 };
58                         PropertyDescriptorCollection pds = converter.GetProperties (null,
59                                 numbers, null);
60                         Assert.IsNotNull (pds, "#A1");
61                         Assert.AreEqual (2, pds.Count, "#A2");
62
63                         PropertyDescriptor pd = pds [0];
64                         Assert.AreEqual (numbers.GetType (), pd.ComponentType, "#B1");
65                         Assert.AreEqual (false, pd.IsReadOnly, "#B2");
66                         Assert.AreEqual ("[0]", pd.Name, "#B3");
67                         Assert.AreEqual (typeof (int), pd.PropertyType, "#B4");
68                         Assert.IsFalse (pd.CanResetValue (numbers), "#B5");
69                         Assert.AreEqual (5, pd.GetValue (numbers), "#B6");
70                         pd.SetValue (numbers, 9);
71                         Assert.AreEqual (9, pd.GetValue (numbers), "#B7");
72                         pd.ResetValue (numbers);
73                         Assert.AreEqual (9, pd.GetValue (numbers), "#B8");
74                         Assert.IsFalse (pd.ShouldSerializeValue (numbers), "#B9");
75
76                         pd = pds [1];
77                         Assert.AreEqual (numbers.GetType (), pd.ComponentType, "#C1");
78                         Assert.AreEqual (false, pd.IsReadOnly, "#C2");
79                         Assert.AreEqual ("[1]", pd.Name, "#C3");
80                         Assert.AreEqual (typeof (int), pd.PropertyType, "#C4");
81                         Assert.IsFalse (pd.CanResetValue (numbers), "#C5");
82                         Assert.AreEqual (7, pd.GetValue (numbers), "#C6");
83                         pd.SetValue (numbers, 3);
84                         Assert.AreEqual (3, pd.GetValue (numbers), "#C7");
85                         pd.ResetValue (numbers);
86                         Assert.AreEqual (3, pd.GetValue (numbers), "#C8");
87                         Assert.IsFalse (pd.ShouldSerializeValue (numbers), "#C9");
88                 }
89
90                 [Test]
91                 [ExpectedException (typeof (NullReferenceException))]
92                 public void GetProperties_Value_Null ()
93                 {
94                         converter.GetProperties (null, null, null);
95                 }
96
97                 [Test]
98                 public void GetPropertiesSupported ()
99                 {
100                         Assert.IsTrue (converter.GetPropertiesSupported (null));
101                 }
102         }
103 }