2 // ContentTypeTest.cs - NUnit Test Cases for System.Net.Mime.ContentType
5 // John Luke (john.luke@gmail.com)
10 using NUnit.Framework;
12 using System.Net.Mime;
14 namespace MonoTests.System.Net.Mime
17 public class ContentTypeTest
22 public void GetReady ()
24 ct = new ContentType ();
28 [ExpectedException (typeof (ArgumentNullException))]
29 public void ArgumentNullException ()
31 new ContentType (null);
35 [ExpectedException (typeof (ArgumentException))]
36 public void ArgumentException ()
42 [ExpectedException (typeof (FormatException))]
43 public void FormatException ()
45 new ContentType ("attachment; foo=bar"); // missing '/'
49 public void ArbitraryParameter ()
51 new ContentType ("application/xml; foo=bar");
55 public void Boundary ()
57 Assert.IsNull (ct.Boundary);
61 public void CharSet ()
63 Assert.IsNull (ct.CharSet);
69 Assert.IsTrue (ct.Equals (new ContentType ()));
70 Assert.IsFalse (ct == new ContentType ());
74 public void GetHashCode ()
76 Assert.IsTrue (ct.GetHashCode () == new ContentType ().GetHashCode ());
80 public void MediaType ()
82 Assert.IsTrue (ct.MediaType == "application/octet-stream");
86 [ExpectedException (typeof (ArgumentNullException))]
87 public void MediaTypeNullException ()
93 [ExpectedException (typeof (ArgumentException))]
94 public void MediaTypeEmptyException ()
100 [ExpectedException (typeof (FormatException))]
101 public void MediaTypeFormatException ()
103 ct.MediaType = "application/x-myType;";
107 public void Parameters ()
109 ContentType dummy = new ContentType ();
110 Assert.IsTrue (dummy.Parameters.Count == 0);
111 dummy.CharSet = "us-ascii";
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");
123 public void ToStringTest ()
125 Assert.AreEqual ("application/octet-stream", ct.ToString ());
129 public void ToStringTest2 ()
131 ContentType dummy = new ContentType ("text/plain; charset=us-ascii");
132 Assert.AreEqual ("text/plain; charset=us-ascii", dummy.ToString ());
136 public void ToStringTest3 ()
138 ct.Parameters.Add ("foo", "bar");
139 Assert.AreEqual ("application/octet-stream; foo=bar", ct.ToString ());
143 public void ToStringTest4 ()
145 ct.Parameters.Add ("start", "urn:foo");
146 Assert.AreEqual ("application/octet-stream; start=\"urn:foo\"", ct.ToString ());
150 public void ToStringTest5 ()
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 ());
160 public void ToStringTest6 ()
162 ct.Parameters.Add ("start", "urn:foo\"bar\"");
163 Assert.AreEqual ("application/octet-stream; start=\"urn:foo\\\"bar\\\"\"", ct.ToString ());
167 public void EncodedChars ()
169 ContentType ct = new ContentType ();
170 ct.Parameters.Add ("ASCII", "This is ASCII");