2 // Pkcs9DocumentNameTest.cs - NUnit tests for Pkcs9DocumentName
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-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.
32 using NUnit.Framework;
35 using System.Collections;
36 using System.Security.Cryptography;
37 using System.Security.Cryptography.Pkcs;
39 namespace MonoTests.System.Security.Cryptography.Pkcs {
42 public class Pkcs9DocumentNameTest {
45 public void Constructor_Empty ()
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)");
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 ()
60 Pkcs9DocumentName dn = new Pkcs9DocumentName ();
61 Assert.IsNull (dn.DocumentName, "DocumentName");
65 public void Constructor_String ()
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)");
78 [ExpectedException (typeof (ArgumentNullException))]
79 public void Constructor_StringNull ()
82 Pkcs9DocumentName dn = new Pkcs9DocumentName (name);
86 public void Constructor_Array ()
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)");
100 [ExpectedException (typeof (ArgumentNullException))]
101 public void Constructor_ArrayNull ()
104 Pkcs9DocumentName dn = new Pkcs9DocumentName (name);
108 [ExpectedException (typeof (ArgumentNullException))]
109 public void CopyFrom_Null ()
111 new Pkcs9DocumentName ().CopyFrom (null);