[bcl] Remove NET_4_0 defines from class libs
[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 // Authors:
6 //      Chris Toshok  <toshok@ximian.com>
7 //      Sebastien Pouliot  <sebastien@ximian.com>
8 //
9 // Copyright (C) 2005, 2010 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
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                 [Test]
40                 public void CanConvertFrom ()
41                 {
42                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
43
44                         Assert.IsTrue (cv.CanConvertFrom (null, typeof (string)), "A1");
45                         Assert.IsFalse (cv.CanConvertFrom (null, typeof (TimeSpan)), "A2");
46                         Assert.IsFalse (cv.CanConvertFrom (null, typeof (int)), "A3");
47                         Assert.IsFalse (cv.CanConvertFrom (null, typeof (object)), "A4");
48                 }
49
50                 [Test]
51                 public void CanConvertTo ()
52                 {
53                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
54
55                         Assert.IsTrue (cv.CanConvertTo (null, typeof (string)), "A1");
56                         Assert.IsFalse (cv.CanConvertTo (null, typeof (TimeSpan)), "A2");
57                         Assert.IsFalse (cv.CanConvertTo (null, typeof (int)), "A3");
58                         Assert.IsFalse (cv.CanConvertTo (null, typeof (object)), "A4");
59                 }
60
61                 [Test]
62                 public void ConvertFrom ()
63                 {
64                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
65                         object o;
66
67                         o = cv.ConvertFrom (null, null, "MD5");
68                         Assert.AreEqual (typeof (MachineKeyValidation), o.GetType (), "typeof");
69                         Assert.AreEqual ("MD5", o.ToString (), "MD5");
70
71                         o = cv.ConvertFrom (null, null, "SHA1");
72                         Assert.AreEqual ("SHA1", o.ToString (), "SHA1");
73
74                         // 3DES in, TripleDES out
75                         o = cv.ConvertFrom (null, null, "3DES");
76                         Assert.AreEqual ("TripleDES", o.ToString (), "3DES");
77
78                         o = cv.ConvertFrom (null, null, "AES");
79                         Assert.AreEqual ("AES", o.ToString (), "AES");
80                         o = cv.ConvertFrom (null, null, "HMACSHA256");
81                         Assert.AreEqual ("HMACSHA256", o.ToString (), "HMACSHA256");
82
83                         o = cv.ConvertFrom (null, null, "HMACSHA384");
84                         Assert.AreEqual ("HMACSHA384", o.ToString (), "HMACSHA384");
85
86                         o = cv.ConvertFrom (null, null, "HMACSHA512");
87                         Assert.AreEqual ("HMACSHA512", o.ToString (), "HMACSHA512");
88                 }
89
90                 [Test]
91                 [ExpectedException (typeof (ArgumentException))]
92                 public void ConvertFrom_Custom ()
93                 {
94                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
95                         cv.ConvertFrom (null, null, "Custom");
96                 }
97
98                 [Test]
99                 [ExpectedException (typeof (ArgumentException))]
100                 public void ConvertFrom_CaseSensitive ()
101                 {
102                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
103                         cv.ConvertFrom (null, null, "sha1");
104                 }
105
106                 [Test]
107                 [ExpectedException (typeof (InvalidCastException))]
108                 public void ConvertFrom_TypeError ()
109                 {
110                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
111                         object o;
112
113                         o = cv.ConvertFrom (null, null, 6);
114                         Assert.IsNull (o, "A1");
115                 }
116
117                 [Test]
118                 public void ConvertTo ()
119                 {
120                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
121
122                         Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, typeof (string)), "A1");
123                         Assert.AreEqual ("SHA1", cv.ConvertTo (null, null, MachineKeyValidation.SHA1, typeof (string)), "A2");
124                         Assert.AreEqual ("3DES", cv.ConvertTo (null, null, MachineKeyValidation.TripleDES, typeof (string)), "A3");
125                         Assert.AreEqual ("HMACSHA256", cv.ConvertTo (null, null, MachineKeyValidation.HMACSHA256, typeof (string)), "HMACSHA256");
126                         Assert.AreEqual ("HMACSHA384", cv.ConvertTo (null, null, MachineKeyValidation.HMACSHA384, typeof (string)), "HMACSHA384");
127                         Assert.AreEqual ("HMACSHA512", cv.ConvertTo (null, null, MachineKeyValidation.HMACSHA512, typeof (string)), "HMACSHA512");
128                 }
129
130                 [Test]
131                 [ExpectedException (typeof (ArgumentException))]
132                 public void ConvertTo_Custom ()
133                 {
134                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
135                         cv.ConvertTo (null, null, MachineKeyValidation.Custom, typeof (string));
136                 }
137
138                 [Test]
139                 [ExpectedException (typeof (ArgumentException))]
140                 public void ConvertTo_NullError ()
141                 {
142                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
143
144                         Assert.AreEqual ("", cv.ConvertTo (null, null, null, typeof (string)), "A1");
145                 }
146
147                 [Test]
148                 [ExpectedException (typeof (ArgumentException))]
149                 public void ConvertTo_TypeError1 ()
150                 {
151                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
152
153                         Assert.AreEqual ("6", cv.ConvertTo (null, null, 6, typeof (string)), "A1");
154                 }
155
156                 [Test]
157                 public void ConvertTo_TypeError2 ()
158                 {
159                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
160
161                         Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, typeof (int)), "A1");
162                         Assert.AreEqual ("MD5", cv.ConvertTo (null, null, MachineKeyValidation.MD5, null), "A2");
163                 }
164
165                 [Test]
166                 [ExpectedException (typeof (ArgumentException))]
167                 public void ConvertTo_TypeError3 ()
168                 {
169                         MachineKeyValidationConverter cv = new MachineKeyValidationConverter ();
170                         cv.ConvertTo (null, null, (MachineKeyValidation)Int32.MinValue, typeof (string));
171                 }
172         }
173 }
174