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