[bcl] Remove NET_4_0 defines from class libs
[mono.git] / mcs / class / System.Web.Routing / Test / System.Web.Routing / FakeHttpWorkerRequest.cs
1 //
2 // System.Web.HttpResponseTest.cs - Unit tests for System.Web.HttpResponse
3 //
4 // Author:
5 //      Miguel de Icaza  <miguel@ximian.com>
6 //
7 // Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System.Text;
30 using System.Web;
31 using System;
32 using System.Collections;
33 using System.Collections.Specialized;
34 using NUnit.Framework;
35
36 namespace MonoTests.Common
37 {
38
39     public class FakeHttpWorkerRequest : HttpWorkerRequest
40     {
41         const string appPath = "/";
42         string queryString;
43         public Hashtable KnownResponseHeaders;
44         public Hashtable UnknownResponseHeaders;
45         public int return_kind;
46
47         public FakeHttpWorkerRequest ()
48             : this (1)
49         {
50                 // for Mono
51                 AppDomain.CurrentDomain.SetData (".appVPath", appPath);
52         }
53
54         public FakeHttpWorkerRequest (int re)
55         {
56             KnownResponseHeaders = CollectionsUtil.CreateCaseInsensitiveHashtable ();
57             UnknownResponseHeaders = CollectionsUtil.CreateCaseInsensitiveHashtable ();
58             return_kind = re;
59             queryString = String.Empty;
60         }
61
62         public override string GetUriPath ()
63         {
64             return "/fake";
65         }
66
67         public override string GetFilePath ()
68         {
69             return GetUriPath ();
70         }
71
72         public override string GetQueryString ()
73         {
74             return queryString;
75         }
76
77         public void SetQueryString (string queryString)
78         {
79             this.queryString = queryString;
80         }
81
82         public override string GetRawUrl ()
83         {
84             return "/GetRawUrl";
85         }
86
87         public override string GetHttpVerbName ()
88         {
89             return "GET";
90         }
91
92         public override string GetHttpVersion ()
93         {
94             if (return_kind == 1)
95                 return "HTTP/1.0";
96             else
97                 return "HTTP/1.1";
98         }
99
100         public override string GetRemoteAddress ()
101         {
102             return "__GetRemoteAddress";
103         }
104
105         public override int GetRemotePort ()
106         {
107             return 1010;
108         }
109
110         public override string GetLocalAddress ()
111         {
112             return "GetLocalAddress";
113         }
114
115         public override string GetAppPath ()
116         {
117             return appPath;
118         }
119
120         public override int GetLocalPort ()
121         {
122             return 2020;
123         }
124
125         public override string MapPath (string virtualPath)
126         {
127 #if TARGET_DOTNET
128                 return "c:\\fakefile";
129 #else
130                 return "/fakefile";
131 #endif
132         }
133
134         public bool status_sent;
135         public int status_code;
136         public string status_string;
137
138         public override void SendStatus (int s, string x)
139         {
140             status_sent = true;
141             status_code = s;
142             status_string = x;
143         }
144
145         void AddHeader (Hashtable table, string header_name, object header)
146         {
147             object o = table[header_name];
148             if (o == null)
149                 table.Add (header_name, header);
150             else {
151                 ArrayList al = o as ArrayList;
152                 if (al == null) {
153                     al = new ArrayList ();
154                     al.Add (o);
155                     table[header_name] = al;
156                 } else
157                     al = o as ArrayList;
158
159                 al.Add (header);
160             }
161         }
162
163         bool headers_sent;
164         public override void SendKnownResponseHeader (int x, string j)
165         {
166             string header_name = HttpWorkerRequest.GetKnownRequestHeaderName (x);
167             AddHeader (KnownResponseHeaders, header_name, new KnownResponseHeader (x, j));
168             headers_sent = true;
169         }
170
171         public override void SendUnknownResponseHeader (string a, string b)
172         {
173             AddHeader (UnknownResponseHeaders, a, new UnknownResponseHeader (a, b));
174             headers_sent = true;
175         }
176
177         bool data_sent;
178         public byte[] data;
179         public int data_len;
180         public int total = 0;
181
182         public override void SendResponseFromMemory (byte[] arr, int x)
183         {
184             data_sent = true;
185             data = new byte[x];
186             for (int i = 0; i < x; i++)
187                 data[i] = arr[i];
188             data_len = x;
189             total += data_len;
190         }
191
192         public override void SendResponseFromFile (string a, long b, long c)
193         {
194             data_sent = true;
195         }
196
197         public override void SendResponseFromFile (IntPtr a, long b, long c)
198         {
199             data_sent = true;
200         }
201
202         public override void FlushResponse (bool x)
203         {
204         }
205
206         public override void EndOfRequest ()
207         {
208         }
209
210         public override string GetKnownRequestHeader (int index)
211         {
212             return null;
213         }
214
215         public bool OutputProduced
216         {
217             get
218             {
219                 return headers_sent || data_sent;
220             }
221         }
222     }
223 }