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