2 // CookieTest.cs - NUnit Test Cases for System.Net.Cookie
\r
5 // Lawrence Pit (loz@cable.a2000.nl)
\r
6 // Martin Willemoes Hansen (mwh@sysrq.dk)
\r
8 // (C) 2003 Martin Willemoes Hansen
\r
11 using NUnit.Framework;
\r
15 namespace MonoTests.System.Net
\r
19 public class CookieTest
\r
22 public void PublicFields ()
\r
27 public void Constructors ()
\r
29 Cookie c = new Cookie ("somename", null, null, null);
\r
31 c = new Cookie (null, null, null, null);
\r
32 Assertion.Fail ("#1: Name cannot be null");
\r
33 } catch (CookieException) {
\r
38 public void Name ()
\r
40 Cookie c = new Cookie ("SomeName", "SomeValue");
\r
41 Assertion.AssertEquals ("#1", c.Name, "SomeName");
\r
44 Assertion.Fail ("#2a");
\r
45 } catch (CookieException) {
\r
46 Assertion.AssertEquals ("#2b", "SomeName", c.Name);
\r
50 Assertion.Fail ("#2c");
\r
51 } catch (CookieException) {
\r
52 Assertion.AssertEquals ("#2d", "SomeName", c.Name);
\r
56 Assertion.Fail ("#2e");
\r
57 } catch (CookieException) {
\r
58 // bah! this fails, yet the name is changed..
\r
59 // inconsistent with previous test
\r
60 Assertion.AssertEquals ("#2f", String.Empty, c.Name);
\r
64 Assertion.Fail ("#2g");
\r
65 } catch (CookieException) {
\r
66 Assertion.AssertEquals ("#2h", String.Empty, c.Name);
\r
69 c.Name = "xxx" + (char) 0x80;
\r
70 } catch (CookieException) {
\r
71 Assertion.Fail ("#2i");
\r
74 c.Name = "$omeName";
\r
75 Assertion.Fail ("#3a: Name cannot start with '$' character");
\r
76 } catch (CookieException) {
\r
77 Assertion.AssertEquals ("#3b", String.Empty, c.Name);
\r
79 c.Name = "SomeName$";
\r
80 Assertion.AssertEquals ("#4", c.Name, "SomeName$");
\r
82 c.Name = "Some=Name";
\r
83 Assertion.Fail ("#5a: Name cannot contain '=' character");
\r
84 } catch (CookieException) {
\r
85 Assertion.AssertEquals ("#5b", String.Empty, c.Name);
\r
88 Assertion.AssertEquals ("#6", c.Name, "domain");
\r
92 public void Value ()
\r
94 // LAMESPEC: According to .Net specs the Value property should not accept
\r
95 // the semicolon and comma characters, yet it does
\r
97 Cookie c = new Cookie("SomeName", "SomeValue");
\r
99 c.Value = "Some;Value";
\r
100 Assertion.Fail ("#1: semicolon should not be accepted");
\r
101 } catch (CookieException) {
\r
104 c.Value = "Some,Value";
\r
105 Assertion.Fail ("#2: comma should not be accepted");
\r
106 } catch (CookieException) {
\r
108 c.Value = "Some\tValue";
\r
109 Assertion.AssertEquals ("#3", c.Value, "Some\tValue");
\r
114 public void Port ()
\r
116 Cookie c = new Cookie ("SomeName", "SomeValue");
\r
119 Assertion.Fail ("#1: port must start and end with double quotes");
\r
120 } catch (CookieException) {
\r
123 c.Port = "\"123\"";
\r
124 } catch (CookieException) {
\r
125 Assertion.Fail ("#2");
\r
128 c.Port = "\"123;124\"";
\r
129 Assertion.Fail ("#3");
\r
130 } catch (CookieException) {
\r
133 c.Port = "\"123,123,124\"";
\r
134 } catch (CookieException) {
\r
135 Assertion.Fail ("#4");
\r
138 c.Port = "\"123,124\"";
\r
139 } catch (CookieException) {
\r
140 Assertion.Fail ("#5");
\r
145 public void Equals ()
\r
147 Cookie c1 = new Cookie ("NAME", "VALUE", "PATH", "DOMAIN");
\r
148 Cookie c2 = new Cookie ("name", "value", "path", "domain");
\r
149 Assertion.Assert("#1", !c1.Equals (c2));
\r
150 c2.Value = "VALUE";
\r
152 Assertion.Assert("#2", c1.Equals (c2));
\r
154 Assertion.Assert("#3", !c1.Equals (c2));
\r