- dnnunittesting_src.zip
- DnnUnitTesting
- bin
- DnnUnitTesting.sln
- DnnUnitTesting.vsmdi
- DnnUnitTesting
- iFinity.DnnUtilities
- localtestrun.testrunconfig
- Readme.txt
- TestResults
- Bruce_WOMBAT 2007-06-08 09_08_45
- Bruce_WOMBAT 2007-06-08 09_10_02
- Bruce_WOMBAT 2007-06-08 09_11_13
- Bruce_WOMBAT 2007-06-08 09_15_14
- Bruce_WOMBAT 2007-06-08 09_16_18
- Bruce_WOMBAT 2007-06-08 09_16_52
- Bruce_WOMBAT 2007-06-08 09_20_35
- dnnunittesting_demo.zip
- iFinity.DNN.Utilities.dll
|
/*
*
* iFinity Smart Business Solutions - http://www.ifinity.com.au
* Copyright (c) 2006
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), the rights to use, copy, modify, merge, publish, distribute, sublicense
* copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
* 1. The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
* 2. The software may not be claimed as the original work and may not be sold as a stand alone product
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Some portions of the source code in this file were adapted from internet sources with no rights restrictions.
* Any perceived copyright violations should be directed to the above website.
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Hosting;
using System.Web;
using System.IO;
namespace iFinity.DNN.Utilities.Testing
{
public static class UnitTestHelper
{
/// <summary>
/// Sets the HTTP context with a valid simulated request
/// </summary>
/// <param name="host">Host.</param>
/// <param name="application">Application.</param>
public static void SetHttpContextWithSimulatedRequest(string host, string application, string appPhysicalDir, string pageName)
{
string appVirtualDir = "/";
string page = application.Replace("/", string.Empty) + pageName;
string query = string.Empty;
TextWriter output = null;
SimulatedHttpRequest workerRequest = new SimulatedHttpRequest(appVirtualDir, appPhysicalDir, page, query, output, host);
HttpContext.Current = new HttpContext(workerRequest);
}
}
/// <summary>
/// Used to simulate an HttpRequest.
/// </summary>
public class SimulatedHttpRequest : SimpleWorkerRequest
{
string _host;
/// <summary>
/// Creates a new <see cref="SimulatedHttpRequest"/> instance.
/// </summary>
/// <param name="appVirtualDir">App virtual dir.</param>
/// <param name="appPhysicalDir">App physical dir.</param>
/// <param name="page">Page.</param>
/// <param name="query">Query.</param>
/// <param name="output">Output.</param>
/// <param name="host">Host.</param>
public SimulatedHttpRequest(string appVirtualDir, string appPhysicalDir, string page, string query, TextWriter output, string host)
: base(appVirtualDir, appPhysicalDir, page, query, output)
{
if (host == null || host.Length == 0)
throw new ArgumentNullException("host", "Host cannot be null nor empty.");
_host = host;
}
/// <summary>
/// Gets the name of the server.
/// </summary>
/// <returns></returns>
public override string GetServerName()
{
return _host;
}
/// <summary>
/// Maps the path to a filesystem path.
/// </summary>
/// <param name="virtualPath">Virtual path.</param>
/// <returns></returns>
public override string MapPath(string virtualPath)
{
return Path.Combine(this.GetAppPath(), virtualPath);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.