Giter VIP home page Giter VIP logo

httpcontext-simulator's Introduction

httpcontext-simulator Build Status HttpSimulator

A simple library used for simulating http context during unit or integration testing

Can simulate:

  • form get with querystring
  • form post
  • session
  • user agent
  • cookie
  • browser capabilities
  • logon user identity
  • response headers

Introduction

The following shows how to use HttpSimulator?.

using System;
using System.Collections.Specialized;

/**
 *
 * The following spike was created to show an example of how to use the HttpSimuator library
 *
 *
 */
using System.Web;
using NUnit.Framework;
using Http.TestLibrary;

namespace UsingHttpSimulator
{
    [TestFixture]
    public class UsingHttpSimulatorTest
    {
        /// <summary>
        /// Determines whether this instance [can get set session].
        /// </summary>
        [Test]
        public void CanGetSetSession()
        {
            using (new HttpSimulator("/", @"c:\inetpub\").SimulateRequest())
            {
                HttpContext.Current.Session["Test"] = "Success";
                Assert.AreEqual("Success", HttpContext.Current.Session["Test"]);
            }
        }

        /// <summary>
        /// Determines whether this instance [can simulate form post].
        /// </summary>
        [Test]
        public void CanSimulateFormPost()
        {
            using (HttpSimulator simulator = new HttpSimulator())
            {
                NameValueCollection form = new NameValueCollection();
                form.Add("Test1", "Value1");
                form.Add("Test2", "Value2");
                simulator.SimulateRequest(new Uri("http://localhost/Test.aspx"), form);

                Assert.AreEqual("Value1", HttpContext.Current.Request.Form["Test1"]);
                Assert.AreEqual("Value2", HttpContext.Current.Request.Form["Test2"]);
            }

            using (HttpSimulator simulator = new HttpSimulator())
            {
                simulator.SetFormVariable("Test1", "Value1")
                  .SetFormVariable("Test2", "Value2")
                  .SimulateRequest(new Uri("http://localhost/Test.aspx"));

                Assert.AreEqual("Value1", HttpContext.Current.Request.Form["Test1"]);
                Assert.AreEqual("Value2", HttpContext.Current.Request.Form["Test2"]);
            }
        }
    }
}

httpcontext-simulator's People

Contributors

ackava avatar ferronrsmith avatar jamesdunlop avatar kronikza avatar mathew-weaver avatar rferstl avatar wallymathieu avatar zpavic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

httpcontext-simulator's Issues

Information license

Hello,

i see the nuget package is under GPL License and the based source is under MIT License.

What is the real License?

image

Cordially,
VILLERS M.

travis build for mono 3.12 and 3.10 run into error

Hi Ferron,
I try to send a pull request but the travis build for mono 3.12 and 3.10 run into errors.
Also without any changes to current master brunch, does it work on your side?

Target CoreCompile: Tool /usr/lib/mono/4.5/mcs.exe execution started with arguments: /noconfig /debug:pdbonly /optimize+ /out:obj/Release/HttpSimulator.dll BaseWrapped/HttpSessionState.cs BaseWrapped/HttpContext.cs HttpSimulator.cs IHttpContext.cs IHttpRequest.cs IHttpResponse.cs IHttpServerUtility.cs Properties/AssemblyInfo.cs ReflectionHelper.cs SimulatedHttpRequest.cs BaseWrapped/SimulatedHttpRequest.cs BaseWrapped/HttpServerUtility.cs obj/Release/.NETFramework,Version=v4.0.AssemblyAttribute.cs /target:library /define:TRACE /nostdlib /reference:/usr/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll /reference:/usr/lib/mono/gac/System.Web/4.0.0.0__b03f5f7f11d50a3a/System.Web.dll /reference:/usr/lib/mono/gac/System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll /warn:4 CSC: error CS0518: The predefined type System.Object is not defined or imported CSC: error CS0518: The predefined type System.ValueType is not defined or imported CSC: error CS0518: The predefined type System.Attribute is not defined or imported ...

Best regards Roland

HttpSimulator is not a strongly-Named assembly

Hello,

We are using your assembly in the Unitary Tests (UT) of one our company projects for a long time but we are having some problems now because we are strongly-naming our assemblies (we use still .Net framework) and an exceptiong raise (saying that your assembly is not a strongly-named one) when we try to run those UT....

There is any way that you fix it?

Best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.