Merge pull request #1222 from LogosBible/uri-trycreate
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / SignedInfoTest.cs
index 55bf56b82af46ceebfb969c4bce788228b1345e6..d96e26fd0b4ba0ca08565ad785dfa41b586e26a9 100644 (file)
@@ -1,11 +1,11 @@
 //
 // SignedInfoTest.cs - NUnit Test Cases for SignedInfo
 //
-// Author:\r
-//     Sebastien Pouliot <sebastien@ximian.com>\r
+// Author:
+//     Sebastien Pouliot <sebastien@ximian.com>
 //
-// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)\r
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)\r
+// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
+// Copyright (C) 2005, 2009 Novell, Inc (http://www.novell.com)
 //
 
 using System;
@@ -18,7 +18,7 @@ using NUnit.Framework;
 namespace MonoTests.System.Security.Cryptography.Xml {
 
        [TestFixture]
-       public class SignedInfoTest : Assertion {
+       public class SignedInfoTest {
 
                protected SignedInfo info;
 
@@ -31,13 +31,13 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                [Test]
                public void Empty () 
                {
-                       AssertEquals ("CanonicalizationMethod", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", info.CanonicalizationMethod);
-                       AssertNull ("Id", info.Id);
-                       AssertNotNull ("References", info.References);
-                       AssertEquals ("References.Count", 0, info.References.Count);
-                       AssertNull ("SignatureLength", info.SignatureLength);
-                       AssertNull ("SignatureMethod", info.SignatureMethod);
-                       AssertEquals ("ToString()", "System.Security.Cryptography.Xml.SignedInfo", info.ToString ());
+                       Assert.AreEqual ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", info.CanonicalizationMethod, "CanonicalizationMethod");
+                       Assert.IsNull (info.Id, "Id");
+                       Assert.IsNotNull (info.References, "References");
+                       Assert.AreEqual (0, info.References.Count, "References.Count");
+                       Assert.IsNull (info.SignatureLength, "SignatureLength");
+                       Assert.IsNull (info.SignatureMethod, "SignatureMethod");
+                       Assert.AreEqual ("System.Security.Cryptography.Xml.SignedInfo", info.ToString (), "ToString()");
                }
 
                [Test]
@@ -51,9 +51,9 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                public void Properties () 
                {
                        info.CanonicalizationMethod = "http://www.go-mono.com/";
-                       AssertEquals ("CanonicalizationMethod", "http://www.go-mono.com/", info.CanonicalizationMethod);
+                       Assert.AreEqual ("http://www.go-mono.com/", info.CanonicalizationMethod, "CanonicalizationMethod");
                        info.Id = "Mono::";
-                       AssertEquals ("Id", "Mono::", info.Id);
+                       Assert.AreEqual ("Mono::", info.Id, "Id");
                }
 
                [Test]
@@ -63,12 +63,12 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        r1.Uri = "http://www.go-mono.com/";
                        r1.AddTransform (new XmlDsigBase64Transform ());
                        info.AddReference (r1);
-                       AssertEquals ("References.Count 1", 1, info.References.Count);
+                       Assert.AreEqual (1, info.References.Count, "References.Count 1");
 
                        Reference r2 = new Reference ("http://www.motus.com/");
                        r2.AddTransform (new XmlDsigBase64Transform ());
                        info.AddReference (r2);
-                       AssertEquals ("References.Count 2", 2, info.References.Count);
+                       Assert.AreEqual (2, info.References.Count, "References.Count 2");
 
                        info.SignatureMethod = "http://www.w3.org/2000/09/xmldsig#dsa-sha1";
                }
@@ -80,10 +80,10 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        XmlDocument doc = new XmlDocument ();
                        doc.LoadXml (xml);
                        info.LoadXml (doc.DocumentElement);
-                       AssertEquals ("LoadXml", xml, (info.GetXml ().OuterXml));
-                       AssertEquals ("LoadXml-C14N", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", info.CanonicalizationMethod);
-                       AssertEquals ("LoadXml-Algo", "http://www.w3.org/2000/09/xmldsig#rsa-sha1", info.SignatureMethod);
-                       AssertEquals ("LoadXml-Ref1", 1, info.References.Count);
+                       Assert.AreEqual (xml, (info.GetXml ().OuterXml), "LoadXml");
+                       Assert.AreEqual ("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", info.CanonicalizationMethod, "LoadXml-C14N");
+                       Assert.AreEqual ("http://www.w3.org/2000/09/xmldsig#rsa-sha1", info.SignatureMethod, "LoadXml-Algo");
+                       Assert.AreEqual (1, info.References.Count, "LoadXml-Ref1");
                }
 
                // there are many (documented) not supported methods in SignedInfo
@@ -142,16 +142,14 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        SignedInfo sig = new SignedInfo ();
                        sig.LoadXml ((XmlElement) doc.SelectSingleNode ("//*[local-name()='SignedInfo']"));
                        XmlElement el = sig.GetXml ();
-                       AssertEquals ("#GetXmlWOSetProperty.document", doc, el.OwnerDocument);
-                       AssertEquals ("#GetXmlWOSetProperty.outerxml", result, el.OuterXml);
+                       Assert.AreEqual (doc, el.OwnerDocument, "#GetXmlWOSetProperty.document");
+                       Assert.AreEqual (result, el.OuterXml, "#GetXmlWOSetProperty.outerxml");
                }
 
                [Test]
-#if NET_2_0\r
-               // urn:foo is'nt accepted when calling GetXml\r
-               [ExpectedException (typeof (CryptographicException))]\r
-               [Category ("NotWorking")]\r
-#endif
+               // urn:foo is'nt accepted when calling GetXml
+               [ExpectedException (typeof (CryptographicException))]
+               [Category ("NotWorking")]
                public void GetXmlWithSetProperty ()
                {
                        XmlDocument doc = new XmlDocument ();
@@ -160,7 +158,7 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        sig.LoadXml ((XmlElement) doc.SelectSingleNode ("//*[local-name()='SignedInfo']"));
                        sig.CanonicalizationMethod = "urn:foo";
                        XmlElement el = sig.GetXml ();
-                       Assert ("#GetXmlWithSetProperty.document", doc != el.OwnerDocument);
+                       Assert.IsTrue (doc != el.OwnerDocument, "#GetXmlWithSetProperty.document");
                }
 
                [Test] // never fails
@@ -190,5 +188,27 @@ namespace MonoTests.System.Security.Cryptography.Xml {
                        sig.CanonicalizationMethod = "urn:foo";
                        XmlElement el = sig.GetXml ();
                }
+
+               [Test]
+               public void SignatureLength ()
+               {
+                       // we can set the length before the algorithm
+                       SignedInfo si = new SignedInfo ();
+                       si.SignatureLength = "128";
+                       Assert.AreEqual ("128", si.SignatureLength, "SignatureLength-1");
+                       Assert.IsNull (si.SignatureMethod, "SignatureMethod-1");
+
+                       // zero
+                       si.SignatureMethod = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
+                       si.SignatureLength = "0";
+                       Assert.AreEqual ("0", si.SignatureLength, "SignatureLength-2");
+                       Assert.AreEqual ("http://www.w3.org/2000/09/xmldsig#rsa-sha1", si.SignatureMethod, "SignatureMethod-2");
+
+                       // mixup length and method
+                       si.SignatureLength = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
+                       si.SignatureMethod = "0";
+                       Assert.AreEqual ("http://www.w3.org/2000/09/xmldsig#rsa-sha1", si.SignatureLength, "SignatureLength-3");
+                       Assert.AreEqual ("0", si.SignatureMethod, "SignatureMethod-3");
+               }
        }
 }