Fixing an issue with output parameters that are of type IntPtr
[castle.git] / MonoRail / Castle.MonoRail.Framework / Test / MockServerUtility.cs
blob5fc5c1a57b62f98a322415f5a6d584d8319bddea
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.MonoRail.Framework.Test
17 using System;
18 using System.IO;
19 using System.Web;
21 /// <summary>
22 /// Represents a mock implementation of <see cref="IServerUtility"/> for unit test purposes.
23 /// </summary>
24 public class MockServerUtility : IServerUtility
26 /// <summary>
27 /// Returns the physical path for the
28 /// specified virtual path.
29 /// </summary>
30 /// <param name="virtualPath">The virtual path.</param>
31 /// <returns>The mapped path</returns>
32 public virtual string MapPath(string virtualPath)
34 return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, virtualPath);
37 /// <summary>
38 /// HTML encodes a string and returns the encoded string.
39 /// </summary>
40 /// <param name="content">The text string to HTML encode.</param>
41 /// <returns>The HTML encoded text.</returns>
42 public virtual string HtmlEncode(string content)
44 return HttpUtility.HtmlEncode(content);
47 /// <summary>
48 /// URL encodes a string and returns the encoded string.
49 /// </summary>
50 /// <param name="content">The text to URL encode.</param>
51 /// <returns>The URL encoded text.</returns>
52 public virtual string UrlEncode(string content)
54 return HttpUtility.UrlEncode(content);
57 /// <summary>
58 /// URL decodes a string and returns the decoded string.
59 /// </summary>
60 /// <param name="content">The text to URL decode.</param>
61 /// <returns>The URL decoded text.</returns>
62 public virtual string UrlDecode(string content)
64 return HttpUtility.UrlDecode(content);
67 /// <summary>
68 /// URL encodes the path portion of a URL string and returns the encoded string.
69 /// </summary>
70 /// <param name="content">The text to URL encode.</param>
71 /// <returns>The URL encoded text.</returns>
72 public virtual string UrlPathEncode(string content)
74 return HttpUtility.UrlPathEncode(content);
77 /// <summary>
78 /// Escapes JavaScript with Url encoding and returns the encoded string.
79 /// </summary>
80 /// <param name="content">The text to URL encode and escape JavaScript within.</param>
81 /// <returns>
82 /// The URL encoded and JavaScript escaped text.
83 /// </returns>
84 /// <remarks>
85 /// Converts quotes, single quotes and CR/LFs to their representation as an escape character.
86 /// </remarks>
87 public virtual string JavaScriptEscape(string content)
89 return content.
90 Replace("\"", "\\\"").
91 Replace("\r", "").
92 Replace("\n", "\\n").
93 Replace("'", "\\'");