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