do not check order sequence if option /order was not used
[mono.git] / mcs / class / System / Test / System.ComponentModel / CollectionConverterTest.cs
1 //
2 // System.ComponentModel.CollectionConverterTest.cs -
3 //      NUnit Test Cases for System.ComponentModel.CollectionConverter
4 //
5 // Author:
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using NUnit.Framework;
31 using System;
32 using System.IO;
33 using System.Collections.Specialized;
34 using System.ComponentModel;
35 using System.Xml.Serialization;
36
37 namespace MonoTests.System.ComponentModel {
38
39         [TestFixture]
40         public class CollectionConverterTest {
41
42                 private CollectionConverter cc;
43                 private StringCollection sc;
44
45                 [TestFixtureSetUp]
46                 public void FixtureSetUp ()
47                 {
48                         cc = new CollectionConverter ();
49                         sc = new StringCollection ();
50                 }
51
52                 [Test]
53                 public void ApplicableTypes ()
54                 {
55                         Type t = cc.GetType ();
56                         Assert.AreEqual (t, TypeDescriptor.GetConverter (typeof (StringCollection)).GetType (), "StringCollection");
57                 }
58
59                 [Test]
60                 [ExpectedException (typeof (NotSupportedException))]
61                 public void ConvertFromString_Null ()
62                 {
63                         cc.ConvertFromString (null);
64                 }
65
66                 [Test]
67                 [ExpectedException (typeof (NotSupportedException))]
68                 public void ConvertFromString_Empty ()
69                 {
70                         cc.ConvertFromString (String.Empty);
71                 }
72
73                 private const string array_of_strings  = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<ArrayOfString xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <string>go</string>\r\n  <string>mono</string>\r\n  </ArrayOfString>";
74
75                 [Test]
76                 [ExpectedException (typeof (NotSupportedException))]
77                 public void ConvertFromString ()
78                 {
79                         cc.ConvertFromString (array_of_strings);
80                 }
81
82                 [Test]
83                 [ExpectedException (typeof (NotSupportedException))]
84                 public void ConvertFrom ()
85                 {
86                         cc.ConvertFrom (array_of_strings);
87                 }
88
89                 [Test]
90                 [ExpectedException (typeof (NotSupportedException))]
91                 public void ConvertFrom_XmlSerializer ()
92                 {
93                         XmlSerializer xs = new XmlSerializer (typeof (string[]));
94                         object o = xs.Deserialize (new StringReader (array_of_strings));
95                         cc.ConvertFrom (o);
96                 }
97
98                 [Test]
99                 public void ConvertTo ()
100                 {
101                         Assert.AreEqual (String.Empty, cc.ConvertTo (null, null, null, typeof (string)), "null");
102                         Assert.AreEqual ("(Collection)", cc.ConvertTo (null, null, sc, typeof (string)), "0");
103                         sc.Add ("some string value");
104                         Assert.AreEqual ("(Collection)", cc.ConvertTo (null, null, sc, typeof (string)), "1");
105                         sc.Clear ();
106                 }
107
108                 [Test]
109                 [ExpectedException (typeof (ArgumentNullException))]
110                 public void ConvertTo_TypeNull ()
111                 {
112                         cc.ConvertTo (null, null, sc, null);
113                 }
114
115                 [Test]
116                 [ExpectedException (typeof (NotSupportedException))]
117                 public void ConvertTo_TypeNotString ()
118                 {
119                         cc.ConvertTo (null, null, sc, typeof (int));
120                 }
121
122                 [Test]
123                 public void GetProperties ()
124                 {
125                         // documented to always return null
126                         Assert.IsNull (cc.GetProperties (null), "null");
127                         Assert.IsNull (cc.GetProperties (null, null), "null,null");
128                         Assert.IsNull (cc.GetProperties (null, null, null), "null,null,null");
129                 }
130
131                 [Test]
132                 public void GetPropertiesSupported ()
133                 {
134                         // documented to always return false
135                         Assert.IsFalse (cc.GetPropertiesSupported (), "empty");
136                         Assert.IsFalse (cc.GetPropertiesSupported (null), "null");
137                 }
138         }
139 }