2 // GenericIdentityTest.cs - NUnit Test Cases for GenericIdentity
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
11 using NUnit
.Framework
;
14 using System
.Runtime
.Serialization
;
15 using System
.Runtime
.Serialization
.Formatters
.Binary
;
16 using System
.Security
.Principal
;
18 namespace MonoTests
.System
.Security
.Principal
{
21 public class GenericIdentityTest
{
24 [ExpectedException (typeof (ArgumentNullException
))]
25 public void NullName ()
27 GenericIdentity gi
= new GenericIdentity (null);
31 [ExpectedException (typeof (ArgumentNullException
))]
32 public void NullAuthenticationType ()
34 GenericIdentity gi
= new GenericIdentity ("user", null);
40 GenericIdentity gi
= new GenericIdentity ("user");
41 Assert
.AreEqual ("user", gi
.Name
, "Name");
42 Assert
.AreEqual (String
.Empty
, gi
.AuthenticationType
, "AuthenticationType");
43 Assert
.IsTrue (gi
.IsAuthenticated
, "IsAuthenticated");
47 public void NameAuthenticationType ()
49 GenericIdentity gi
= new GenericIdentity ("user", "blood oath");
50 Assert
.AreEqual ("user", gi
.Name
, "Name");
51 Assert
.AreEqual ("blood oath", gi
.AuthenticationType
, "AuthenticationType");
52 Assert
.IsTrue (gi
.IsAuthenticated
, "IsAuthenticated");
56 public void EmptyName ()
58 GenericIdentity gi
= new GenericIdentity ("");
59 Assert
.AreEqual (String
.Empty
, gi
.Name
, "Name");
60 Assert
.AreEqual (String
.Empty
, gi
.AuthenticationType
, "AuthenticationType");
61 Assert
.IsFalse (gi
.IsAuthenticated
, "IsAuthenticated");
65 public void SerializationRoundtrip ()
67 GenericIdentity gi
= new GenericIdentity ("mono", "dna");
68 BinaryFormatter bf
= new BinaryFormatter ();
69 MemoryStream ms
= new MemoryStream ();
70 bf
.Serialize (ms
, gi
);
72 //Console.WriteLine (BitConverter.ToString (ms.ToArray ()));
75 GenericIdentity clone
= (GenericIdentity
) bf
.Deserialize (ms
);
76 Assert
.AreEqual (gi
.Name
, clone
.Name
, "Name");
77 Assert
.AreEqual (gi
.AuthenticationType
, clone
.AuthenticationType
, "AuthenticationType");
78 Assert
.AreEqual (gi
.IsAuthenticated
, clone
.IsAuthenticated
, "IsAuthenticated");
82 static byte[] identity
= { 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x29, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x2E, 0x50, 0x72, 0x69, 0x6E, 0x63, 0x69, 0x70, 0x61, 0x6C, 0x2E, 0x47, 0x65, 0x6E, 0x65, 0x72, 0x69, 0x63, 0x49, 0x64, 0x65, 0x6E, 0x74, 0x69, 0x74, 0x79, 0x02, 0x00, 0x00, 0x00, 0x06, 0x6D, 0x5F, 0x6E, 0x61, 0x6D, 0x65, 0x06, 0x6D, 0x5F, 0x74, 0x79, 0x70, 0x65, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x00, 0x04, 0x6D, 0x6F, 0x6E, 0x6F, 0x06, 0x03, 0x00, 0x00, 0x00, 0x03, 0x64, 0x6E, 0x61, 0x0B }
;
84 static byte[] identity
= { 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x29, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79, 0x2E, 0x50, 0x72, 0x69, 0x6E, 0x63, 0x69, 0x70, 0x61, 0x6C, 0x2E, 0x47, 0x65, 0x6E, 0x65, 0x72, 0x69, 0x63, 0x49, 0x64, 0x65, 0x6E, 0x74, 0x69, 0x74, 0x79, 0x02, 0x00, 0x00, 0x00, 0x06, 0x6D, 0x5F, 0x6E, 0x61, 0x6D, 0x65, 0x06, 0x6D, 0x5F, 0x74, 0x79, 0x70, 0x65, 0x01, 0x01, 0x06, 0x02, 0x00, 0x00, 0x00, 0x04, 0x6D, 0x6F, 0x6E, 0x6F, 0x06, 0x03, 0x00, 0x00, 0x00, 0x03, 0x64, 0x6E, 0x61, 0x0B }
;
88 public void Deserialize ()
90 BinaryFormatter bf
= new BinaryFormatter ();
91 MemoryStream ms
= new MemoryStream (identity
);
92 GenericIdentity gi
= (GenericIdentity
) bf
.Deserialize (ms
);
93 Assert
.AreEqual ("mono", gi
.Name
, "Name");
94 Assert
.AreEqual ("dna", gi
.AuthenticationType
, "AuthenticationType");
95 Assert
.IsTrue (gi
.IsAuthenticated
, "IsAuthenticated");