CookieCollectionTest.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // CookieCollectionTest.cs - NUnit Test Cases for System.Net.CookieCollection
  3. //
  4. // Author:
  5. // Lawrence Pit ([email protected])
  6. //
  7. using NUnit.Framework;
  8. using System;
  9. using System.Net;
  10. using System.Collections;
  11. namespace MonoTests.System.Net
  12. {
  13. public class CookieCollectionTest : TestCase
  14. {
  15. CookieCollection col;
  16. public CookieCollectionTest () :
  17. base ("[MonoTests.System.Net.CookieCollectionTest]") {}
  18. public CookieCollectionTest (string name) : base (name) {}
  19. protected override void SetUp ()
  20. {
  21. col = new CookieCollection ();
  22. col.Add (new Cookie ("name1", "value1"));
  23. col.Add (new Cookie ("name2", "value2", "path2"));
  24. col.Add (new Cookie ("name3", "value3", "path3", "domain3"));
  25. }
  26. protected override void TearDown () {}
  27. public static ITest Suite
  28. {
  29. get {
  30. return new TestSuite (typeof (CookieCollectionTest));
  31. }
  32. }
  33. public void TestCount ()
  34. {
  35. AssertEquals ("#1", col.Count, 3);
  36. }
  37. public void TestIndexer ()
  38. {
  39. Cookie c = null;
  40. try {
  41. c = col [-1];
  42. Fail ("#1");
  43. } catch (ArgumentOutOfRangeException) {
  44. }
  45. try {
  46. c = col [col.Count];
  47. Fail ("#2");
  48. } catch (ArgumentOutOfRangeException) {
  49. }
  50. c = col ["name1"];
  51. AssertEquals ("#3", c.Name, "name1");
  52. c = col ["NAME2"];
  53. AssertEquals ("#4", c.Name, "name2");
  54. }
  55. public void TestAdd ()
  56. {
  57. try {
  58. Cookie c = null;
  59. col.Add (c);
  60. Fail ("#1");
  61. } catch (ArgumentNullException) {
  62. }
  63. // in the microsoft implementation this will fail,
  64. // so we'll have to fail to.
  65. try {
  66. col.Add (col);
  67. Fail ("#2");
  68. } catch (Exception) {
  69. }
  70. AssertEquals ("#3", col.Count, 3);
  71. col.Add (new Cookie("name1", "value1"));
  72. AssertEquals ("#4", col.Count, 3);
  73. CookieCollection col2 = new CookieCollection();
  74. Cookie c4 = new Cookie("name4", "value4");
  75. Cookie c5 = new Cookie("name5", "value5");
  76. col2.Add (c4);
  77. col2.Add (c5);
  78. col.Add (col2);
  79. AssertEquals ("#5", col.Count, 5);
  80. AssertEquals ("#6", col ["NAME4"], c4);
  81. AssertEquals ("#7", col [4], c5);
  82. }
  83. public void TestCopyTo ()
  84. {
  85. Array a = Array.CreateInstance (typeof (Cookie), 3);
  86. col.CopyTo (a, 0);
  87. AssertEquals ("#1", a.GetValue (0), col [0]);
  88. AssertEquals ("#2", a.GetValue (1), col [1]);
  89. AssertEquals ("#3", a.GetValue (2), col [2]);
  90. }
  91. public void TestEnumerator ()
  92. {
  93. IEnumerator enumerator = col.GetEnumerator ();
  94. enumerator.MoveNext ();
  95. Cookie c = (Cookie) enumerator.Current;
  96. AssertEquals ("#1", c, col [0]);
  97. col.Add (new Cookie ("name6", "value6"));
  98. try {
  99. enumerator.MoveNext ();
  100. Fail ("#2");
  101. } catch (InvalidOperationException) {
  102. }
  103. }
  104. }
  105. }