New test.
[mono.git] / mcs / class / System / Test / System.Net / FtpWebRequestTest.cs
1 //
2 // FtpWebRequestTest.cs - NUnit Test Cases for System.Net.FtpWebRequest
3 //
4 // Author: Carlos Alberto Cortez <calberto.cortez@gmail.com>
5 //
6 // Copyright (c) 2006 Novell, Inc. (http://www.novell.com)
7 //
8
9 using NUnit.Framework;
10 using System;
11 using System.Net;
12
13 #if NET_2_0
14
15 namespace MonoTests.System.Net 
16 {
17         [TestFixture]
18         public class FtpWebRequestTest
19         {
20                 FtpWebRequest defaultRequest;
21                 
22                 [TestFixtureSetUp]
23                 public void Init ()
24                 {
25                         defaultRequest = (FtpWebRequest) WebRequest.Create ("ftp://www.contoso.com");
26                 }
27                 
28                 [Test]
29                 public void ContentLength ()
30                 {
31                         try {
32                                 long l = defaultRequest.ContentLength;
33                         } catch (NotSupportedException) {
34                                 Assert.Fail ("#1"); // Not overriden
35                         }
36
37                         try {
38                                 defaultRequest.ContentLength = 2;
39                         } catch (NotSupportedException) {
40                                 Assert.Fail ("#2"); // Not overriden
41                         }
42                 }
43
44                 [Test]
45                 public void ContentType ()
46                 {
47                         try {
48                                 string t = defaultRequest.ContentType;
49                                 Assert.Fail ("#1");
50                         } catch (NotSupportedException) {
51                         }
52
53                         try {
54                                 defaultRequest.ContentType = String.Empty;
55                                 Assert.Fail ("#2");
56                         } catch (NotSupportedException) {
57                         }
58                 }
59
60                 [Test]
61                 public void ContentOffset ()
62                 {
63                         try {
64                                 defaultRequest.ContentOffset = -2;
65                                 Assert.Fail ("#1");
66                         } catch (ArgumentOutOfRangeException) {
67                         }
68                 }
69
70                 [Test]
71                 public void Credentials ()
72                 {
73                         try {
74                                 defaultRequest.Credentials = null;
75                                 Assert.Fail ("#1");
76                         } catch (ArgumentNullException) {
77                         }
78
79                 }
80
81                 [Test]
82                 public void Method ()
83                 {
84                         try {
85                                 defaultRequest.Method = null;
86                                 Assert.Fail ("#1");
87                         } catch (ArgumentNullException) {
88                         }
89
90                         try {
91                                 defaultRequest.Method = String.Empty;
92                                 Assert.Fail ("#2");
93                         } catch (ArgumentException) {
94                         }
95
96                         try {
97                                 defaultRequest.Method = "WrongValue";
98                                 Assert.Fail ("#3");
99                         } catch (ArgumentException) {
100                         }
101                 }
102
103                 [Test]
104                 public void PreAuthenticate ()
105                 {
106                         try {
107                                 bool p = defaultRequest.PreAuthenticate;
108                                 Assert.Fail ("#1");
109                         } catch (NotSupportedException) {
110                         }
111
112                         try {
113                                 defaultRequest.PreAuthenticate = true;
114                         } catch (NotSupportedException) {
115                         }
116                 }
117
118                 [Test]
119                 public void ReadWriteTimeout ()
120                 {
121                         try {
122                                 defaultRequest.ReadWriteTimeout = -2;
123                                 Assert.Fail ("#2");
124                         } catch (ArgumentOutOfRangeException) {
125                         }
126                 }
127
128                 [Test]
129                 public void Timeout ()
130                 {
131                         try {
132                                 defaultRequest.Timeout = -2;
133                                 Assert.Fail ("#2");
134                         } catch (ArgumentOutOfRangeException) {
135                         }
136                 }
137                 
138                 [Test]
139                 public void DefaultValues ()
140                 {
141                         FtpWebRequest request = (FtpWebRequest) WebRequest.Create ("ftp://www.contoso.com");
142                         
143                         Assert.AreEqual (0, request.ContentOffset, "ContentOffset");
144                         Assert.AreEqual (false, request.EnableSsl, "EnableSsl");
145                         Assert.AreEqual (true, request.KeepAlive, "KeepAlive");
146                         Assert.AreEqual (WebRequestMethods.Ftp.DownloadFile, request.Method, "#1");
147                         Assert.AreEqual (300000, request.ReadWriteTimeout, "ReadWriteTimeout");
148                         Assert.IsNull (request.RenameTo, "RenameTo");
149                         Assert.AreEqual (true, request.UseBinary, "UseBinary");
150                         Assert.AreEqual (100000, request.Timeout, "Timeout");
151                         Assert.AreEqual (true, request.UsePassive, "UsePassive");
152                 }
153
154                 [Test]
155                 public void RenameTo ()
156                 {
157                         try {
158                                 defaultRequest.RenameTo = null;
159                                 Assert.Fail ("#1");
160                         } catch (ArgumentException) {
161                         }
162
163                         try {
164                                 defaultRequest.RenameTo = String.Empty;
165                                 Assert.Fail ("#2");
166                         } catch (ArgumentException) {
167                         }
168                 }
169
170         }
171 }
172
173 #endif
174