[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / KeyInfoNameTest.cs
1 //
2 // KeyInfoNameTest.cs - NUnit Test Cases for KeyInfoName
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 using System;
11 using System.Security.Cryptography;
12 using System.Security.Cryptography.Xml;
13 using System.Xml;
14
15 using NUnit.Framework;
16
17 namespace MonoTests.System.Security.Cryptography.Xml {
18
19         [TestFixture]
20         public class KeyInfoNameTest {
21
22                 [Test]
23                 public void NewKeyValue () 
24                 {
25                         string newKeyValue = "Mono::";
26                         KeyInfoName name1 = new KeyInfoName ();
27                         name1.Value = newKeyValue;
28                         XmlElement xel = name1.GetXml ();
29
30                         KeyInfoName name2 = new KeyInfoName ();
31                         name2.LoadXml (xel);
32
33                         Assert.AreEqual (newKeyValue, name1.Value, "newKeyValue==value");
34                         Assert.AreEqual ((name1.GetXml ().OuterXml), (name2.GetXml ().OuterXml), "name1==name2");
35                 }
36
37                 [Test]
38                 public void ImportKeyValue () 
39                 {
40                         string value = "<KeyName xmlns=\"http://www.w3.org/2000/09/xmldsig#\">Mono::</KeyName>";
41                         XmlDocument doc = new XmlDocument ();
42                         doc.LoadXml (value);
43
44                         KeyInfoName name = new KeyInfoName ();
45                         name.LoadXml (doc.DocumentElement);
46                         Assert.AreEqual ("Mono::", name.Value, "import.Name");
47                         Assert.AreEqual (value, name.GetXml ().OuterXml, "import.GetXml");
48                 }
49
50                 [Test]
51                 [ExpectedException (typeof (ArgumentNullException))]
52                 public void InvalidValue1 () 
53                 {
54                         string bad = "<Test></Test>";
55                         XmlDocument doc = new XmlDocument ();
56                         doc.LoadXml (bad);
57
58                         KeyInfoName name = new KeyInfoName ();
59                         name.LoadXml (null);
60                 }
61
62                 [Test]
63                 public void InvalidValue2 () 
64                 {
65                         string bad = "<Test></Test>";
66                         XmlDocument doc = new XmlDocument ();
67                         doc.LoadXml (bad);
68
69                         KeyInfoName name = new KeyInfoName ();
70                         name.LoadXml (doc.DocumentElement);
71                         Assert.AreEqual ("", name.Value, "invalid.Name");
72                         Assert.AreEqual ("<KeyName xmlns=\"http://www.w3.org/2000/09/xmldsig#\"></KeyName>", (name.GetXml ().OuterXml), "invalid.GetXml");
73                 }
74         }
75 }