2 // System.Web.Configuration.MachineKeyValidationConverterTest.cs - Unit tests
3 // for System.Web.Configuration.MachineKeyValidationConverter.
6 // Chris Toshok <toshok@ximian.com>
8 // Copyright (C) 2005 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.
33 using System.Web.Configuration;
34 using NUnit.Framework;
36 namespace MonoTests.System.Web.Configuration {
38 public class MachineKeyValidationConverterTest
41 public void CanConvertFrom ()
43 MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
45 Assert.IsTrue (cv.CanConvertFrom (null, typeof (string)), "A1");
46 Assert.IsFalse (cv.CanConvertFrom (null, typeof (TimeSpan)), "A2");
47 Assert.IsFalse (cv.CanConvertFrom (null, typeof (int)), "A3");
48 Assert.IsFalse (cv.CanConvertFrom (null, typeof (object)), "A4");
52 public void CanConvertTo ()
54 MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
56 Assert.IsTrue (cv.CanConvertTo (null, typeof (string)), "A1");
57 Assert.IsFalse (cv.CanConvertTo (null, typeof (TimeSpan)), "A2");
58 Assert.IsFalse (cv.CanConvertTo (null, typeof (int)), "A3");
59 Assert.IsFalse (cv.CanConvertTo (null, typeof (object)), "A4");
63 public void ConvertFrom ()
65 MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
68 o = cv.ConvertFrom (null, null, "MD5");
69 Assert.AreEqual (typeof (MachineKeyValidation), o.GetType(), "A1");
70 Assert.AreEqual ("MD5", o.ToString(), "A2");
71 o = cv.ConvertFrom (null, null, "AES");
72 Assert.AreEqual ("AES", o.ToString(), "A3");
76 [ExpectedException (typeof (InvalidCastException))]
77 public void ConvertFrom_TypeError ()
79 MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
82 o = cv.ConvertFrom (null, null, 6);
83 Assert.IsNull (o, "A1");
87 public void ConvertTo ()
89 MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
91 Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, typeof (string)), "A1");
92 Assert.AreEqual ("SHA1", cv.ConvertTo (null, null, MachineKeyValidation.SHA1, typeof (string)), "A2");
93 Assert.AreEqual ("3DES", cv.ConvertTo (null, null, MachineKeyValidation.TripleDES, typeof (string)), "A3");
97 [ExpectedException (typeof (NullReferenceException))]
98 public void ConvertTo_NullError ()
100 MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
102 Assert.AreEqual ("", cv.ConvertTo (null, null, null, typeof (string)), "A1");
106 [ExpectedException (typeof (FormatException))]
107 public void ConvertTo_TypeError1 ()
109 MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
111 Assert.AreEqual ("6", cv.ConvertTo (null, null, 6, typeof (string)), "A1");
115 public void ConvertTo_TypeError2 ()
117 MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
119 Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, typeof (int)), "A1");
120 Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, null), "A2");