New test.
[mono.git] / mcs / class / System.Web / Test / System.Web.Configuration / MachineKeyValidationConverterTest.cs
1 //
2 // System.Web.Configuration.MachineKeyValidationConverterTest.cs - Unit tests
3 // for System.Web.Configuration.MachineKeyValidationConverter.
4 //
5 // Author:
6 //      Chris Toshok  <toshok@ximian.com>
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
30 #if NET_2_0
31
32 using System;
33 using System.Web.Configuration;
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Web.Configuration {
37         [TestFixture]
38         public class MachineKeyValidationConverterTest
39         {
40                 [Test]
41                 public void CanConvertFrom ()
42                 {
43                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
44
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");
49                 }
50
51                 [Test]
52                 public void CanConvertTo ()
53                 {
54                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
55
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");
60                 }
61
62                 [Test]
63                 public void ConvertFrom ()
64                 {
65                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
66                         object o;
67
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");
73                 }
74
75                 [Test]
76                 [ExpectedException (typeof (InvalidCastException))]
77                 public void ConvertFrom_TypeError ()
78                 {
79                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
80                         object o;
81
82                         o = cv.ConvertFrom (null, null, 6);
83                         Assert.IsNull (o, "A1");
84                 }
85
86                 [Test]
87                 public void ConvertTo ()
88                 {
89                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
90
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");
94                 }
95
96                 [Test]
97                 [ExpectedException (typeof (NullReferenceException))]
98                 public void ConvertTo_NullError ()
99                 {
100                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
101
102                         Assert.AreEqual ("", cv.ConvertTo (null, null, null, typeof (string)), "A1");
103                 }
104
105                 [Test]
106                 [ExpectedException (typeof (FormatException))]
107                 public void ConvertTo_TypeError1 ()
108                 {
109                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
110
111                         Assert.AreEqual ("6", cv.ConvertTo (null, null, 6, typeof (string)), "A1");
112                 }
113
114                 [Test]
115                 public void ConvertTo_TypeError2 ()
116                 {
117                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
118
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");
121                 }
122
123         }
124 }
125
126 #endif