CollectionConverterTest.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // System.ComponentModel.CollectionConverterTest.cs -
  3. // NUnit Test Cases for System.ComponentModel.CollectionConverter
  4. //
  5. // Author:
  6. // Sebastien Pouliot <[email protected]>
  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. using NUnit.Framework;
  30. using System;
  31. using System.IO;
  32. using System.Collections.Specialized;
  33. using System.ComponentModel;
  34. using System.Xml.Serialization;
  35. namespace MonoTests.System.ComponentModel {
  36. [TestFixture]
  37. public class CollectionConverterTest {
  38. private CollectionConverter cc;
  39. private StringCollection sc;
  40. [TestFixtureSetUp]
  41. public void FixtureSetUp ()
  42. {
  43. cc = new CollectionConverter ();
  44. sc = new StringCollection ();
  45. }
  46. [Test]
  47. public void ApplicableTypes ()
  48. {
  49. Type t = cc.GetType ();
  50. Assert.AreEqual (t, TypeDescriptor.GetConverter (typeof (StringCollection)).GetType (), "StringCollection");
  51. }
  52. [Test]
  53. [ExpectedException (typeof (NotSupportedException))]
  54. public void ConvertFromString_Null ()
  55. {
  56. cc.ConvertFromString (null);
  57. }
  58. [Test]
  59. [ExpectedException (typeof (NotSupportedException))]
  60. public void ConvertFromString_Empty ()
  61. {
  62. cc.ConvertFromString (String.Empty);
  63. }
  64. 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>";
  65. [Test]
  66. [ExpectedException (typeof (NotSupportedException))]
  67. public void ConvertFromString ()
  68. {
  69. cc.ConvertFromString (array_of_strings);
  70. }
  71. [Test]
  72. [ExpectedException (typeof (NotSupportedException))]
  73. public void ConvertFrom ()
  74. {
  75. cc.ConvertFrom (array_of_strings);
  76. }
  77. [Test]
  78. [ExpectedException (typeof (NotSupportedException))]
  79. public void ConvertFrom_XmlSerializer ()
  80. {
  81. XmlSerializer xs = new XmlSerializer (typeof (string[]));
  82. object o = xs.Deserialize (new StringReader (array_of_strings));
  83. cc.ConvertFrom (o);
  84. }
  85. [Test]
  86. public void ConvertTo ()
  87. {
  88. Assert.AreEqual (String.Empty, cc.ConvertTo (null, null, null, typeof (string)), "null");
  89. Assert.AreEqual ("(Collection)", cc.ConvertTo (null, null, sc, typeof (string)), "0");
  90. sc.Add ("some string value");
  91. Assert.AreEqual ("(Collection)", cc.ConvertTo (null, null, sc, typeof (string)), "1");
  92. sc.Clear ();
  93. }
  94. [Test]
  95. [ExpectedException (typeof (ArgumentNullException))]
  96. public void ConvertTo_TypeNull ()
  97. {
  98. cc.ConvertTo (null, null, sc, null);
  99. }
  100. [Test]
  101. [ExpectedException (typeof (NotSupportedException))]
  102. public void ConvertTo_TypeNotString ()
  103. {
  104. cc.ConvertTo (null, null, sc, typeof (int));
  105. }
  106. [Test]
  107. public void GetProperties ()
  108. {
  109. // documented to always return null
  110. Assert.IsNull (cc.GetProperties (null), "null");
  111. Assert.IsNull (cc.GetProperties (null, null), "null,null");
  112. Assert.IsNull (cc.GetProperties (null, null, null), "null,null,null");
  113. }
  114. [Test]
  115. public void GetPropertiesSupported ()
  116. {
  117. // documented to always return false
  118. Assert.IsFalse (cc.GetPropertiesSupported (), "empty");
  119. Assert.IsFalse (cc.GetPropertiesSupported (null), "null");
  120. }
  121. }
  122. }