SignerInfoCollectionTest.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. //
  2. // SignerInfoCollectionTest.cs - NUnit tests for SignerInfoCollection
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. #if NET_2_0
  29. using NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.Security.Cryptography;
  33. using System.Security.Cryptography.Pkcs;
  34. using System.Security.Cryptography.X509Certificates;
  35. using System.Security.Cryptography.Xml;
  36. namespace MonoTests.System.Security.Cryptography.Pkcs {
  37. [TestFixture]
  38. public class SignerInfoCollectionTest {
  39. private SignerInfoCollection GetCollection ()
  40. {
  41. SignerInfo si = SignerInfoTest.GetSignerInfo (SignerInfoTest.subjectKeyIdentifierSignature);
  42. return si.CounterSignerInfos;
  43. }
  44. [Test]
  45. public void EmptyCollection ()
  46. {
  47. SignerInfoCollection sic = GetCollection ();
  48. Assert.AreEqual (0, sic.Count, "Count");
  49. Assert.IsFalse (sic.IsSynchronized, "IsSynchronized");
  50. Assert.IsNotNull (sic.SyncRoot, "SyncRoot");
  51. Assert.IsNotNull (sic.GetEnumerator (), "GetEnumerator");
  52. }
  53. [Test]
  54. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  55. public void Indexer_MinusOne ()
  56. {
  57. SignerInfoCollection sic = GetCollection ();
  58. Assert.IsNotNull (sic[-1]);
  59. }
  60. [Test]
  61. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  62. public void Indexer_One ()
  63. {
  64. SignerInfoCollection sic = GetCollection ();
  65. Assert.IsNotNull (sic[1]);
  66. }
  67. [Test]
  68. [ExpectedException (typeof (ArgumentNullException))]
  69. public void CopyTo_ArrayInt_Null ()
  70. {
  71. SignerInfoCollection sic = GetCollection ();
  72. sic.CopyTo ((Array)null, 0);
  73. }
  74. [Test]
  75. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  76. public void CopyTo_ArrayInt_MinusOne ()
  77. {
  78. ArrayList al = new ArrayList ();
  79. SignerInfoCollection sic = GetCollection ();
  80. sic.CopyTo (al.ToArray (), -1);
  81. }
  82. [Test]
  83. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  84. public void CopyTo_ArrayInt_One ()
  85. {
  86. ArrayList al = new ArrayList ();
  87. SignerInfoCollection sic = GetCollection ();
  88. sic.CopyTo (al.ToArray (), 1);
  89. }
  90. [Test]
  91. [ExpectedException (typeof (ArgumentNullException))]
  92. public void CopyTo_SignerInfoInt_Null ()
  93. {
  94. SignerInfoCollection sic = GetCollection ();
  95. sic.CopyTo ((SignerInfo[])null, 0);
  96. }
  97. [Test]
  98. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  99. public void CopyTo_SignerInfoInt_MinusOne ()
  100. {
  101. SignerInfo[] sis = new SignerInfo[1];
  102. SignerInfoCollection sic = GetCollection ();
  103. sic.CopyTo (sis, -1);
  104. }
  105. [Test]
  106. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  107. public void CopyTo_SignerInfoInt_One ()
  108. {
  109. SignerInfo[] sis = new SignerInfo[1];
  110. SignerInfoCollection sic = GetCollection ();
  111. sic.CopyTo (sis, 1);
  112. }
  113. [Test]
  114. public void CopyTo_SignerInfoInt_Zero ()
  115. {
  116. SignerInfo[] sis = new SignerInfo[1];
  117. SignerInfoCollection sic = GetCollection ();
  118. sic.CopyTo (sis, 0);
  119. }
  120. }
  121. }
  122. #endif