2 // ContentTypeTest.cs - NUnit Test Cases for System.Net.Mime.ContentType
5 // John Luke (john.luke@gmail.com)
11 using System.Net.Mime;
13 namespace MonoTests.System.Net.Mime
16 public class ContentTypeTest
21 public void GetReady ()
23 ct = new ContentType ();
27 [ExpectedException (typeof (ArgumentNullException))]
28 public void ArgumentNullException ()
30 new ContentType (null);
34 [ExpectedException (typeof (ArgumentException))]
35 public void ArgumentException ()
41 [ExpectedException (typeof (FormatException))]
42 public void FormatException ()
44 new ContentType ("attachment; foo=bar"); // missing '/'
48 public void ArbitraryParameter ()
50 new ContentType ("application/xml; foo=bar");
54 public void Boundary ()
56 Assert.IsNull (ct.Boundary);
60 public void CharSet ()
62 Assert.IsNull (ct.CharSet);
68 Assert.IsTrue (ct.Equals (new ContentType ()));
69 Assert.IsFalse (ct == new ContentType ());
73 public void GetHashCodeTest ()
75 Assert.IsTrue (ct.GetHashCode () == new ContentType ().GetHashCode ());
79 public void MediaType ()
81 Assert.IsTrue (ct.MediaType == "application/octet-stream");
85 [ExpectedException (typeof (ArgumentNullException))]
86 public void MediaTypeNullException ()
92 [ExpectedException (typeof (ArgumentException))]
93 public void MediaTypeEmptyException ()
99 [ExpectedException (typeof (FormatException))]
100 public void MediaTypeFormatException ()
102 ct.MediaType = "application/x-myType;";
106 public void Parameters ()
108 ContentType dummy = new ContentType ();
109 Assert.IsTrue (dummy.Parameters.Count == 0);
110 dummy.CharSet = "us-ascii";
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");
122 public void ToStringTest ()
124 Assert.AreEqual ("application/octet-stream", ct.ToString ());
128 public void ToStringTest2 ()
130 ContentType dummy = new ContentType ("text/plain; charset=us-ascii");
131 Assert.AreEqual ("text/plain; charset=us-ascii", dummy.ToString ());
135 public void ToStringTest3 ()
137 ct.Parameters.Add ("foo", "bar");
138 Assert.AreEqual ("application/octet-stream; foo=bar", ct.ToString ());
142 public void ToStringTest4 ()
144 ct.Parameters.Add ("start", "urn:foo");
145 Assert.AreEqual ("application/octet-stream; start=\"urn:foo\"", ct.ToString ());
149 public void ToStringTest5 ()
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 ());
159 public void ToStringTest6 ()
161 ct.Parameters.Add ("start", "urn:foo\"bar\"");
162 Assert.AreEqual ("application/octet-stream; start=\"urn:foo\\\"bar\\\"\"", ct.ToString ());
166 public void EncodedChars ()
168 ContentType ct = new ContentType ();
169 ct.Parameters.Add ("ASCII", "This is ASCII");