MachineKeyValidationConverterTest.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //
  2. // System.Web.Configuration.MachineKeyValidationConverterTest.cs - Unit tests
  3. // for System.Web.Configuration.MachineKeyValidationConverter.
  4. //
  5. // Author:
  6. // Chris Toshok <[email protected]>
  7. //
  8. // Copyright (C) 2005 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. #if NET_2_0
  30. using System;
  31. using System.Web.Configuration;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Web.Configuration {
  34. [TestFixture]
  35. public class MachineKeyValidationConverterTest
  36. {
  37. [Test]
  38. public void CanConvertFrom ()
  39. {
  40. MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
  41. Assert.IsTrue (cv.CanConvertFrom (null, typeof (string)), "A1");
  42. Assert.IsFalse (cv.CanConvertFrom (null, typeof (TimeSpan)), "A2");
  43. Assert.IsFalse (cv.CanConvertFrom (null, typeof (int)), "A3");
  44. Assert.IsFalse (cv.CanConvertFrom (null, typeof (object)), "A4");
  45. }
  46. [Test]
  47. public void CanConvertTo ()
  48. {
  49. MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
  50. Assert.IsTrue (cv.CanConvertTo (null, typeof (string)), "A1");
  51. Assert.IsFalse (cv.CanConvertTo (null, typeof (TimeSpan)), "A2");
  52. Assert.IsFalse (cv.CanConvertTo (null, typeof (int)), "A3");
  53. Assert.IsFalse (cv.CanConvertTo (null, typeof (object)), "A4");
  54. }
  55. [Test]
  56. public void ConvertFrom ()
  57. {
  58. MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
  59. object o;
  60. o = cv.ConvertFrom (null, null, "MD5");
  61. Assert.AreEqual (typeof (MachineKeyValidation), o.GetType(), "A1");
  62. Assert.AreEqual ("MD5", o.ToString(), "A2");
  63. o = cv.ConvertFrom (null, null, "AES");
  64. Assert.AreEqual ("AES", o.ToString(), "A3");
  65. }
  66. [Test]
  67. [ExpectedException (typeof (InvalidCastException))]
  68. public void ConvertFrom_TypeError ()
  69. {
  70. MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
  71. object o;
  72. o = cv.ConvertFrom (null, null, 6);
  73. Assert.IsNull (o, "A1");
  74. }
  75. [Test]
  76. public void ConvertTo ()
  77. {
  78. MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
  79. Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, typeof (string)), "A1");
  80. Assert.AreEqual ("SHA1", cv.ConvertTo (null, null, MachineKeyValidation.SHA1, typeof (string)), "A2");
  81. Assert.AreEqual ("3DES", cv.ConvertTo (null, null, MachineKeyValidation.TripleDES, typeof (string)), "A3");
  82. }
  83. [Test]
  84. [ExpectedException (typeof (NullReferenceException))]
  85. public void ConvertTo_NullError ()
  86. {
  87. MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
  88. Assert.AreEqual ("", cv.ConvertTo (null, null, null, typeof (string)), "A1");
  89. }
  90. [Test]
  91. [ExpectedException (typeof (FormatException))]
  92. public void ConvertTo_TypeError1 ()
  93. {
  94. MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
  95. Assert.AreEqual ("6", cv.ConvertTo (null, null, 6, typeof (string)), "A1");
  96. }
  97. [Test]
  98. public void ConvertTo_TypeError2 ()
  99. {
  100. MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
  101. Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, typeof (int)), "A1");
  102. Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, null), "A2");
  103. }
  104. }
  105. }
  106. #endif