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.
31 using NUnit.Framework;
34 using System.Collections;
35 using System.Security.Cryptography;
36 using System.Security.Cryptography.Pkcs;
38 namespace MonoTests.System.Security.Cryptography.Pkcs {
41 public class Pkcs9DocumentNameTest {
44 public void Constructor_Empty ()
46 Pkcs9DocumentName dn = new Pkcs9DocumentName ();
47 Assert.IsNull (dn.Oid.FriendlyName, "Oid.FriendlyName");
48 Assert.AreEqual ("1.3.6.1.4.1.311.88.2.1", dn.Oid.Value, "Oid.Value");
49 Assert.IsNull (dn.RawData, "RawData");
50 Assert.AreEqual (String.Empty, dn.Format (true), "Format(true)");
51 Assert.AreEqual (String.Empty, dn.Format (false), "Format(false)");
55 // FIXME: throws a NullReferenceException in beta 1 - still true in Dec CTP
56 [Category ("NotDotNet")] // MS throws [ExpectedException (typeof (NullReferenceException))]
57 public void Constructor_Empty_MessageDigest ()
59 Pkcs9DocumentName dn = new Pkcs9DocumentName ();
60 Assert.IsNull (dn.DocumentName, "DocumentName");
64 public void Constructor_String ()
66 Pkcs9DocumentName dn = new Pkcs9DocumentName ("mono");
67 Assert.IsNull (dn.Oid.FriendlyName, "Oid.FriendlyName");
68 Assert.AreEqual ("1.3.6.1.4.1.311.88.2.1", dn.Oid.Value, "Oid.Value");
69 Assert.AreEqual ("mono", dn.DocumentName, "DocumentName");
70 Assert.AreEqual (12, dn.RawData.Length, "RawData.Length");
71 Assert.AreEqual ("04-0A-6D-00-6F-00-6E-00-6F-00-00-00", BitConverter.ToString (dn.RawData), "RawData");
72 Assert.AreEqual ("04 0a 6d 00 6f 00 6e 00 6f 00 00 00", dn.Format (true), "Format(true)");
73 Assert.AreEqual ("04 0a 6d 00 6f 00 6e 00 6f 00 00 00", dn.Format (false), "Format(false)");
77 [ExpectedException (typeof (ArgumentNullException))]
78 public void Constructor_StringNull ()
81 Pkcs9DocumentName dn = new Pkcs9DocumentName (name);
85 public void Constructor_Array ()
87 byte[] name = { 0x04, 0x0A, 0x6D, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x6F, 0x00, 0x00, 0x00 };
88 Pkcs9DocumentName dn = new Pkcs9DocumentName (name);
89 Assert.AreEqual ("1.3.6.1.4.1.311.88.2.1", dn.Oid.Value, "Oid.Value");
90 Assert.IsNull (dn.Oid.FriendlyName, "Oid.FriendlyName");
91 Assert.AreEqual ("mono", dn.DocumentName, "DocumentName");
92 Assert.AreEqual (12, dn.RawData.Length, "RawData.Length");
93 Assert.AreEqual ("04-0A-6D-00-6F-00-6E-00-6F-00-00-00", BitConverter.ToString (dn.RawData), "RawData");
94 Assert.AreEqual ("04 0a 6d 00 6f 00 6e 00 6f 00 00 00", dn.Format (true), "Format(true)");
95 Assert.AreEqual ("04 0a 6d 00 6f 00 6e 00 6f 00 00 00", dn.Format (false), "Format(false)");
99 [ExpectedException (typeof (ArgumentNullException))]
100 public void Constructor_ArrayNull ()
103 Pkcs9DocumentName dn = new Pkcs9DocumentName (name);
107 [ExpectedException (typeof (ArgumentNullException))]
108 public void CopyFrom_Null ()
110 new Pkcs9DocumentName ().CopyFrom (null);