File: ContentDispositionTest.cs

package info (click to toggle)
mono 1.2.2.1-1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 142,720 kB
  • ctags: 256,408
  • sloc: cs: 1,495,736; ansic: 249,442; sh: 18,327; xml: 12,463; makefile: 5,046; perl: 1,248; asm: 635; yacc: 285; sql: 7
file content (149 lines) | stat: -rw-r--r-- 3,204 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// ContentDispositionTest.cs - NUnit Test Cases for System.Net.Mime.ContentDisposition
//
// Authors:
//   John Luke (john.luke@gmail.com)
//
// (C) 2005 John Luke
//

#if NET_2_0

using NUnit.Framework;
using System;
using System.Net.Mime;

namespace MonoTests.System.Net.Mime
{
	[TestFixture]
	public class ContentDispositionTest
	{
		ContentDisposition cd;
		
		[SetUp]
		public void GetReady ()
		{
			cd = new ContentDisposition ();
			cd.FileName = "genome.jpeg";
			cd.ModificationDate = DateTime.MaxValue;
		}

		[Test]
		public void DispositionType ()
		{
			Assert.AreEqual ("attachment", cd.DispositionType);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void DispositionTypeNull ()
		{
			cd.DispositionType = null;
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void DispositionTypeEmpty ()
		{
			cd.DispositionType = "";
		}

		[Test]
		public void EqualsHashCode ()
		{
			ContentDisposition dummy1 = new ContentDisposition ();
			dummy1.Inline = true;
			ContentDisposition dummy2 = new ContentDisposition ("inline");
			Assert.IsTrue (dummy1.Equals (dummy2));
			Assert.IsFalse (dummy1 == dummy2);
			Assert.IsTrue (dummy1.GetHashCode () == dummy2.GetHashCode ());
		}

		[Test]
		public void Equals ()
		{
			ContentDisposition dummy1 = new ContentDisposition ();
			dummy1.FileName = "genome.jpeg";
			ContentDisposition dummy2 = new ContentDisposition ("attachment; filename=genome.jpeg");
			Assert.IsTrue (dummy1.Equals (dummy2));
		}

		[Test]
		public void FileName ()
		{
			Assert.AreEqual ("genome.jpeg", cd.FileName);
		}

		[Test]
		public void Size ()
		{
			Assert.AreEqual (-1, cd.Size);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void ArgumentNullException ()
		{
			new ContentDisposition (null);
		}

		[Test]
		[ExpectedException (typeof (FormatException))]
		public void FormatException ()
		{
			new ContentDisposition ("");
		}

		[Test]
		public void NoFormatException ()
		{
			new ContentDisposition ("attachment; foo=bar");
		}

		[Test]
		public void IsInline ()
		{
			Assert.IsFalse (cd.Inline);
		}

		[Test]
		public void Parameters ()
		{
			Assert.IsNotNull (cd.Parameters, "is not null");
			Assert.AreEqual (2, cd.Parameters.Count);
		}

		[Test]
		public void ToStringTest ()
		{
			string rfc822 = "dd MMM yyyy HH':'mm':'ss zz00";
			string modification_date = DateTime.MaxValue.ToString (rfc822);
			Assert.AreEqual ("attachment; modification-date=\"" + modification_date + "\"; filename=genome.jpeg", cd.ToString ());
		}

		[Test]
		public void ToStringTest2 ()
		{
			ContentDisposition dummy = new ContentDisposition ();
			Assert.AreEqual ("attachment", dummy.ToString ());
		}

		[Test]
		public void ToStringTest3 ()
		{
			ContentDisposition dummy = new ContentDisposition ();
			dummy.Size = 0;
			Assert.AreEqual ("attachment; size=0", dummy.ToString ());
		}

		[Test]
		public void ToStringTest4 ()
		{
			ContentDisposition dummy = new ContentDisposition ("attachment");
			dummy.Parameters.Add ("foo", "bar");
			Assert.AreEqual (1, dummy.Parameters.Count);
			Assert.AreEqual ("attachment; foo=bar", dummy.ToString ());
		}
	}
}
#endif