Merge pull request #2396 from akoeplinger/flaky-osx-socket-test
[mono.git] / mcs / class / System / Test / System.Net.Mime / ContentDispositionTest.cs
1 //
2 // ContentDispositionTest.cs - NUnit Test Cases for System.Net.Mime.ContentDisposition
3 //
4 // Authors:
5 //   John Luke (john.luke@gmail.com)
6 //
7 // (C) 2005 John Luke
8 //
9
10
11 using NUnit.Framework;
12 using System;
13 using System.Net.Mime;
14
15 namespace MonoTests.System.Net.Mime
16 {
17         [TestFixture]
18         public class ContentDispositionTest
19         {
20                 ContentDisposition cd;
21                 
22                 [SetUp]
23                 public void GetReady ()
24                 {
25                         cd = new ContentDisposition ();
26                         cd.FileName = "genome.jpeg";
27                         cd.ModificationDate = DateTime.MaxValue;
28                 }
29
30                 [Test]
31                 public void DispositionType ()
32                 {
33                         Assert.AreEqual ("attachment", cd.DispositionType);
34                 }
35
36                 [Test]
37                 [ExpectedException (typeof (ArgumentNullException))]
38                 public void DispositionTypeNull ()
39                 {
40                         cd.DispositionType = null;
41                 }
42
43                 [Test]
44                 [ExpectedException (typeof (ArgumentException))]
45                 public void DispositionTypeEmpty ()
46                 {
47                         cd.DispositionType = "";
48                 }
49
50                 [Test]
51                 public void EqualsHashCode ()
52                 {
53                         ContentDisposition dummy1 = new ContentDisposition ();
54                         dummy1.Inline = true;
55                         ContentDisposition dummy2 = new ContentDisposition ("inline");
56                         Assert.IsTrue (dummy1.Equals (dummy2));
57                         Assert.IsFalse (dummy1 == dummy2);
58                         Assert.IsTrue (dummy1.GetHashCode () == dummy2.GetHashCode ());
59                 }
60
61                 [Test]
62                 public void Equals ()
63                 {
64                         ContentDisposition dummy1 = new ContentDisposition ();
65                         dummy1.FileName = "genome.jpeg";
66                         ContentDisposition dummy2 = new ContentDisposition ("attachment; filename=genome.jpeg");
67                         Assert.IsTrue (dummy1.Equals (dummy2));
68                 }
69
70                 [Test]
71                 public void FileName ()
72                 {
73                         Assert.AreEqual ("genome.jpeg", cd.FileName);
74                 }
75
76                 [Test]
77                 public void Size ()
78                 {
79                         Assert.AreEqual (-1, cd.Size);
80                 }
81
82                 [Test]
83                 [ExpectedException (typeof (ArgumentNullException))]
84                 public void ArgumentNullException ()
85                 {
86                         new ContentDisposition (null);
87                 }
88
89                 [Test]
90                 [ExpectedException (typeof (FormatException))]
91                 public void FormatException ()
92                 {
93                         new ContentDisposition ("");
94                 }
95
96                 [Test]
97                 public void NoFormatException ()
98                 {
99                         new ContentDisposition ("attachment; foo=bar");
100                 }
101
102                 [Test]
103                 public void IsInline ()
104                 {
105                         Assert.IsFalse (cd.Inline);
106                 }
107
108                 [Test]
109                 public void Parameters ()
110                 {
111                         Assert.IsNotNull (cd.Parameters, "is not null");
112                         Assert.AreEqual (2, cd.Parameters.Count);
113                 }
114
115                 [Test]
116                 public void ToStringTest ()
117                 {
118                         string rfc822 = "dd MMM yyyy HH':'mm':'ss zz00";
119                         string modification_date = DateTime.MaxValue.ToString (rfc822);
120                         string to_string = cd.ToString ();
121                         Assert.IsTrue (to_string.StartsWith ("attachment; "), "#1");
122                         Assert.IsTrue (to_string.Contains ("modification-date=\"" + modification_date + "\""), "#2");
123                         Assert.IsTrue (to_string.Contains ("filename=genome.jpeg"), "#3");
124                 }
125
126                 [Test]
127                 public void ToStringTest2 ()
128                 {
129                         ContentDisposition dummy = new ContentDisposition ();
130                         Assert.AreEqual ("attachment", dummy.ToString ());
131                 }
132
133                 [Test]
134                 public void ToStringTest3 ()
135                 {
136                         ContentDisposition dummy = new ContentDisposition ();
137                         dummy.Size = 0;
138                         Assert.AreEqual ("attachment; size=0", dummy.ToString ());
139                 }
140
141                 [Test]
142                 public void ToStringTest4 ()
143                 {
144                         ContentDisposition dummy = new ContentDisposition ("attachment");
145                         dummy.Parameters.Add ("foo", "bar");
146                         Assert.AreEqual (1, dummy.Parameters.Count);
147                         Assert.AreEqual ("attachment; foo=bar", dummy.ToString ());
148                 }
149         }
150 }