Merge pull request #1407 from chrisvire/bug-24587
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Pkcs / Pkcs9DocumentNameTest.cs
1 //
2 // Pkcs9DocumentNameTest.cs - NUnit tests for Pkcs9DocumentName
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-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 NUnit.Framework;
33
34 using System;
35 using System.Collections;
36 using System.Security.Cryptography;
37 using System.Security.Cryptography.Pkcs;
38
39 namespace MonoTests.System.Security.Cryptography.Pkcs {
40
41         [TestFixture]
42         public class Pkcs9DocumentNameTest {
43
44                 [Test]
45                 public void Constructor_Empty ()
46                 {
47                         Pkcs9DocumentName dn = new Pkcs9DocumentName ();
48                         Assert.IsNull (dn.Oid.FriendlyName, "Oid.FriendlyName");
49                         Assert.AreEqual ("1.3.6.1.4.1.311.88.2.1", dn.Oid.Value, "Oid.Value");
50                         Assert.IsNull (dn.RawData, "RawData");
51                         Assert.AreEqual (String.Empty, dn.Format (true), "Format(true)");
52                         Assert.AreEqual (String.Empty, dn.Format (false), "Format(false)");
53                 }
54
55                 [Test]
56                 // FIXME: throws a NullReferenceException in beta 1 - still true in Dec CTP
57                 [Category ("NotDotNet")] // MS throws [ExpectedException (typeof (NullReferenceException))]
58                 public void Constructor_Empty_MessageDigest ()
59                 {
60                         Pkcs9DocumentName dn = new Pkcs9DocumentName ();
61                         Assert.IsNull (dn.DocumentName, "DocumentName");
62                 }
63
64                 [Test]
65                 public void Constructor_String () 
66                 {
67                         Pkcs9DocumentName dn = new Pkcs9DocumentName ("mono");
68                         Assert.IsNull (dn.Oid.FriendlyName, "Oid.FriendlyName");
69                         Assert.AreEqual ("1.3.6.1.4.1.311.88.2.1", dn.Oid.Value, "Oid.Value");
70                         Assert.AreEqual ("mono", dn.DocumentName, "DocumentName");
71                         Assert.AreEqual (12, dn.RawData.Length, "RawData.Length");
72                         Assert.AreEqual ("04-0A-6D-00-6F-00-6E-00-6F-00-00-00", BitConverter.ToString (dn.RawData), "RawData");
73                         Assert.AreEqual ("04 0a 6d 00 6f 00 6e 00 6f 00 00 00", dn.Format (true), "Format(true)");
74                         Assert.AreEqual ("04 0a 6d 00 6f 00 6e 00 6f 00 00 00", dn.Format (false), "Format(false)");
75                 }
76
77                 [Test]
78                 [ExpectedException (typeof (ArgumentNullException))]
79                 public void Constructor_StringNull ()
80                 {
81                         string name = null;
82                         Pkcs9DocumentName dn = new Pkcs9DocumentName (name);
83                 }
84
85                 [Test]
86                 public void Constructor_Array ()
87                 {
88                         byte[] name = { 0x04, 0x0A, 0x6D, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x6F, 0x00, 0x00, 0x00 };
89                         Pkcs9DocumentName dn = new Pkcs9DocumentName (name);
90                         Assert.AreEqual ("1.3.6.1.4.1.311.88.2.1", dn.Oid.Value, "Oid.Value");
91                         Assert.IsNull (dn.Oid.FriendlyName, "Oid.FriendlyName");
92                         Assert.AreEqual ("mono", dn.DocumentName, "DocumentName");
93                         Assert.AreEqual (12, dn.RawData.Length, "RawData.Length");
94                         Assert.AreEqual ("04-0A-6D-00-6F-00-6E-00-6F-00-00-00", BitConverter.ToString (dn.RawData), "RawData");
95                         Assert.AreEqual ("04 0a 6d 00 6f 00 6e 00 6f 00 00 00", dn.Format (true), "Format(true)");
96                         Assert.AreEqual ("04 0a 6d 00 6f 00 6e 00 6f 00 00 00", dn.Format (false), "Format(false)");
97                 }
98
99                 [Test]
100                 [ExpectedException (typeof (ArgumentNullException))]
101                 public void Constructor_ArrayNull ()
102                 {
103                         byte[] name = null;
104                         Pkcs9DocumentName dn = new Pkcs9DocumentName (name);
105                 }
106
107                 [Test]
108                 [ExpectedException (typeof (ArgumentNullException))]
109                 public void CopyFrom_Null ()
110                 {
111                         new Pkcs9DocumentName ().CopyFrom (null);
112                 }
113         }
114 }
115
116 #endif