Fix compilation of System.Configuration test suite.
[mono.git] / mcs / class / System / Test / System.Net.Mime / ContentTypeTest.cs
1 //
2 // ContentTypeTest.cs - NUnit Test Cases for System.Net.Mime.ContentType
3 //
4 // Authors:
5 //   John Luke (john.luke@gmail.com)
6 //
7 // (C) 2005 John Luke
8 //
9 #if NET_2_0
10 using NUnit.Framework;
11 using System;
12 using System.Net.Mime;
13
14 namespace MonoTests.System.Net.Mime
15 {
16         [TestFixture]
17         public class ContentTypeTest
18         {
19                 ContentType ct;
20                 
21                 [SetUp]
22                 public void GetReady ()
23                 {
24                         ct = new ContentType ();
25                 }
26
27                 [Test]
28                 [ExpectedException (typeof (ArgumentNullException))]
29                 public void ArgumentNullException ()
30                 {
31                         new ContentType (null);
32                 }
33
34                 [Test]
35                 [ExpectedException (typeof (ArgumentException))]
36                 public void ArgumentException ()
37                 {
38                         new ContentType ("");
39                 }
40
41                 [Test]
42                 [ExpectedException (typeof (FormatException))]
43                 public void FormatException ()
44                 {
45                         new ContentType ("attachment; foo=bar"); // missing '/'
46                 }
47
48                 [Test]
49                 public void ArbitraryParameter ()
50                 {
51                         new ContentType ("application/xml; foo=bar");
52                 }
53
54                 [Test]
55                 public void Boundary ()
56                 {
57                         Assert.IsNull (ct.Boundary);
58                 }
59
60                 [Test]
61                 public void CharSet ()
62                 {
63                         Assert.IsNull (ct.CharSet);
64                 }
65
66                 [Test]
67                 public void Equals ()
68                 {
69                         Assert.IsTrue (ct.Equals (new ContentType ()));
70                         Assert.IsFalse (ct  == new ContentType ());
71                 }
72
73                 [Test]
74                 public void GetHashCode ()
75                 {
76                         Assert.IsTrue (ct.GetHashCode () == new ContentType ().GetHashCode ());
77                 }
78
79                 [Test]
80                 public void MediaType ()
81                 {
82                         Assert.IsTrue (ct.MediaType == "application/octet-stream");
83                 }
84
85                 [Test]
86                 [ExpectedException (typeof (ArgumentNullException))]
87                 public void MediaTypeNullException ()
88                 {
89                         ct.MediaType = null;
90                 }
91
92                 [Test]
93                 [ExpectedException (typeof (ArgumentException))]
94                 public void MediaTypeEmptyException ()
95                 {
96                         ct.MediaType = "";
97                 }
98
99                 [Test]
100                 [ExpectedException (typeof (FormatException))]
101                 public void MediaTypeFormatException ()
102                 {
103                         ct.MediaType = "application/x-myType;";
104                 }
105
106                 [Test]
107                 public void Parameters ()
108                 {
109                         ContentType dummy = new ContentType ();
110                         Assert.IsTrue (dummy.Parameters.Count == 0);
111                         dummy.CharSet = "us-ascii";
112                         dummy.Name = "test";
113                         dummy.Boundary = "-----boundary---0";
114                         dummy.Parameters.Add ("foo", "bar");
115                         Assert.IsTrue (dummy.Parameters.Count == 4);
116                         Assert.IsTrue (dummy.Parameters["charset"] == "us-ascii");
117                         Assert.IsTrue (dummy.Parameters["name"] == "test");
118                         Assert.IsTrue (dummy.Parameters["boundary"] == "-----boundary---0");
119                         Assert.IsTrue (dummy.Parameters["foo"] == "bar");
120                 }
121
122                 [Test]
123                 public void ToStringTest ()
124                 {
125                         Assert.AreEqual ("application/octet-stream", ct.ToString ());
126                 }
127
128                 [Test]
129                 public void ToStringTest2 ()
130                 {
131                         ContentType dummy = new ContentType ("text/plain; charset=us-ascii");
132                         Assert.AreEqual ("text/plain; charset=us-ascii", dummy.ToString ());
133                 }
134
135                 [Test]
136                 public void ToStringTest3 ()
137                 {
138                         ct.Parameters.Add ("foo", "bar");
139                         Assert.AreEqual ("application/octet-stream; foo=bar", ct.ToString ());
140                 }
141
142                 [Test]
143                 public void ToStringTest4 ()
144                 {
145                         ct.Parameters.Add ("start", "urn:foo");
146                         Assert.AreEqual ("application/octet-stream; start=\"urn:foo\"", ct.ToString ());
147                 }
148
149                 [Test]
150                 public void ToStringTest5 ()
151                 {
152                         ct.Parameters.Add ("start", "foo_bar");
153                         Assert.AreEqual ("application/octet-stream; start=foo_bar", ct.ToString ());
154                         ct.Parameters.Clear ();
155                         ct.Parameters.Add ("start", "foo@bar");
156                         Assert.AreEqual ("application/octet-stream; start=\"foo@bar\"", ct.ToString ());
157                 }
158
159                 [Test]
160                 public void ToStringTest6 ()
161                 {
162                         ct.Parameters.Add ("start", "urn:foo\"bar\"");
163                         Assert.AreEqual ("application/octet-stream; start=\"urn:foo\\\"bar\\\"\"", ct.ToString ());
164                 }
165
166                 [Test]
167                 public void EncodedChars ()
168                 {
169                         ContentType ct = new ContentType ();
170                         ct.Parameters.Add ("ASCII", "This is ASCII");
171                 }
172         }
173 }
174 #endif