2 // System.ComponentModel.CollectionConverterTest.cs -
3 // NUnit Test Cases for System.ComponentModel.CollectionConverter
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using NUnit.Framework;
33 using System.Collections.Specialized;
34 using System.ComponentModel;
35 using System.Xml.Serialization;
37 namespace MonoTests.System.ComponentModel {
40 public class CollectionConverterTest {
42 private CollectionConverter cc;
43 private StringCollection sc;
46 public void FixtureSetUp ()
48 cc = new CollectionConverter ();
49 sc = new StringCollection ();
53 public void ApplicableTypes ()
55 Type t = cc.GetType ();
56 Assert.AreEqual (t, TypeDescriptor.GetConverter (typeof (StringCollection)).GetType (), "StringCollection");
60 [ExpectedException (typeof (NotSupportedException))]
61 public void ConvertFromString_Null ()
63 cc.ConvertFromString (null);
67 [ExpectedException (typeof (NotSupportedException))]
68 public void ConvertFromString_Empty ()
70 cc.ConvertFromString (String.Empty);
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>";
76 [ExpectedException (typeof (NotSupportedException))]
77 public void ConvertFromString ()
79 cc.ConvertFromString (array_of_strings);
83 [ExpectedException (typeof (NotSupportedException))]
84 public void ConvertFrom ()
86 cc.ConvertFrom (array_of_strings);
90 [ExpectedException (typeof (NotSupportedException))]
91 public void ConvertFrom_XmlSerializer ()
93 XmlSerializer xs = new XmlSerializer (typeof (string[]));
94 object o = xs.Deserialize (new StringReader (array_of_strings));
99 public void ConvertTo ()
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");
109 [ExpectedException (typeof (ArgumentNullException))]
110 public void ConvertTo_TypeNull ()
112 cc.ConvertTo (null, null, sc, null);
116 [ExpectedException (typeof (NotSupportedException))]
117 public void ConvertTo_TypeNotString ()
119 cc.ConvertTo (null, null, sc, typeof (int));
123 public void GetProperties ()
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");
132 public void GetPropertiesSupported ()
134 // documented to always return false
135 Assert.IsFalse (cc.GetPropertiesSupported (), "empty");
136 Assert.IsFalse (cc.GetPropertiesSupported (null), "null");