Unit Test Web Code Without A Web Server Using HttpSimulator

Testing code written for the web is challenging. Especially code that makes use of the ASP.NET intrinsic objects such as the HttpRequest object. My goal is to make testing such code easier.

Spider Web (c) FreeFoto.com

A while ago, I wrote some code to simulate the HttpContext in order to make writing such unit tests easier. My goal wasn’t to replace web testing frameworks such as Selenium, Watin, or AspUnit. Instead, I’m a fan of the Pareto principle and I hoped to help people easily reach the 80 of the 80/20 rule before reaching out to one of these tools to cover the last mile.

I’ve spent some time since then refactoring the code and improving the API. I also implemented some features that were lacking such as being able to call MapPath and setting and getting Session and Application variables.

To that end, I introduce the HttpSimulator class. To best demonstrate how to use it, I will present some unit test code.

The following code simulates a simple GET request for the web root with the physical location c:\inetpub. The actual path passed into the simulator doesn’t matter. It’s all simulated. This tests that you can set a session variable and then retrieve it.

[Test]
public void CanGetSetSession()
{
  using (new HttpSimulator("/", @"c:\inetpub\").SimulateRequest())
  {
    HttpContext.Current.Session["Test"] = "Success";
    Assert.AreEqual("Success", HttpContext.Current.Session["Test"]);
  }
}

The following test method demonstrates two different methods for simulating a form post. The second using block shows off the fluent interface.

[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"]);
  }
}

The SimulateRequest method is always called last once you’ve set your form or query string variables and whatnot. For read and write values such as session, you can set them after the call. If you download the code, you can see other usage examples in the unit tests.

One area I’ve had a lot of success with this class is in unit testing custom HttpHandlers. I’ve also use it to test custom control rendering code and helper methods for ASP.NET.

This code can be found in the Subtext.TestLibrary project in our Subversion repository. This project contains code I’ve found useful within my unit tests such as a test SMTP server and a test Web Server using WebServer.WebDev.

To make it easy for you to start using the HttpSimulator, I’ve packaged the relevant files in a zip file including the unit tests.

I must make one confession. I originally tried to do all this by using the public APIs. Unfortunately, so many classes are internal or sealed that I had to get my hands dirty and resort to using reflection. Doing so freed me up to finally get certain features working that I could not before.

And now, for some preemptive answers to expected criticism.

1. You shouldn’t access the HttpContext anyways. You should abstract away the HttpContext by creating your own IContext and using IoC and Dependency Injection.

You’re absolutely right. Next criticism.

2. This isn’t "unit testing", this is "integration testing".

Very astute observation. Well said. Next?

3. You’re not taking our criticisms seriously!

Au contraire! I take such criticisms very seriously. Even if you write a bunch of code to abstract away the web from your code throwing all sorts of injections and inversions at it, you still have to test your abstraction. HttpSimulator to the rescue!

Likewise, whether this is unit testing or integration testing is splitting semantic hairs. Before TDD came along, unit testing meant testing a unit of code. It usually meant walking through the code line by line and executing a single function. If you want to call these integration tests, fine. HttpSimulator to the rescue!

Not to mention that in the real world, you sometimes don’t get to write code from scratch using sound TDD principles. A lot of time you inherit legacy code and the best you can do is try to write tests after-the-fact as you go before you refactor the code. Again, HttpSimulator to the rescue!

Here is the link to download the source files in case you missed it the first time.

Technorati tags: , ,

What others have said

Requesting Gravatar... Julian Birch Jun 20, 2007 1:49 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Extremely nice. Wish I'd had this a year ago...
Requesting Gravatar... Haacked Jun 20, 2007 2:12 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
@Julian - well the original version was written a year ago. ;)
Requesting Gravatar... DotNetKicks.com Jun 20, 2007 5:45 AM
# Unit Test Web Code Without A Web Server Using HttpSimulator
You've been kicked (a good thing) - Trackback from DotNetKicks.com
Requesting Gravatar... Kevin Dente Jun 20, 2007 6:03 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Maybe we need a new term - they're unigration tests! ;)

Have you checked out Plasma?
http://www.codeplex.com/plasma
Requesting Gravatar... Chris May Jun 20, 2007 8:44 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
I am trying to use MVP on some of my webforms for testing purposes.

Do you know if there is in depth/complex examples out there of how to go about doing this?

I know there is a simple form example of MVP on this site, but I am looking for something a little more complex. I basically have 2 questions in my mind:

1) Should the view "pull" its info, or should it be "pushed" to the view. Say for example you have something where a user enteres something in a textbox, clicks a button, and a datagrid is populated. You could have the view do this:
controller.NewSearchEntered(this.txtSearch.Text())
and the controller would do:
void NewSearchEntered(string text){
// get data from DB
view.PopulateResults(someDataset);
}

but I have seen other people doing it where the view asks for it's information from the controller like:
ds = controller.GetSearchResults(this.txtSearch.Text());
this.dg.DataSource = ds;
this.dg.DataBind();

This is a trivial example, but it seems like the controller is losing control in the 2nd example and in many ways is being delegated a kind of data access layer.

I would be interested to see how others deal with this.

2) How much logic should go in the view? (even UI logic). For example, in order to test some of my stuff, I have started adding methods to my view interface like SetErrorMessage(string), HideDetails(), EnableSaveButton() that are called by the controller based on business logic.

But these methods are very shallow wrappers around stuff like "this.lblError.Text = s" or "this.dgDetails.visible = false".

It allows me to test using a mock of my view, b/c I can test that EnableSaveButton was called, meaning that it WAS enabled.

But I am wondering if I am getting too detailed with these things and should put more of this logic in the view/UI.

I have been using your previous HTTP simulator, so I look forward to this upgrade!

Chris May
Requesting Gravatar... Chris May Jun 20, 2007 8:58 AM
# Simulating HttpContext
Requesting Gravatar... Ryan Smith Jun 20, 2007 9:35 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
I'm looking to get into a more test driven style of development, but most the code I write is for the web.

I find it hard to figure out the best way to approach this, but it looks like this might be a good start.

Do you know of any good articles / sites that talk about test driven development for the web?
# HTTPSimulator - Simulating HTTP Requests for unit testing made easier
Phill Haack just released HTTPSimulator - a class to help with running tests against a simulated Http
Requesting Gravatar... Ryan Smith Jun 20, 2007 2:06 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
P.S.

You have a bug on your site:
http://www.dynamicajax.com/haacked_error.png
Requesting Gravatar... Scruffy-Looking Cat Herder Jun 20, 2007 5:45 PM
# Mocking Developments
Mocking Developments
Requesting Gravatar... Sean Jun 20, 2007 7:01 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
I get an error with IConfigMapPath:
'System.Web.Configuration.IConfigMapPath' is inaccessible due to its protection level. Have FW 2 & 3 installed and System.Web.dll included. Any ideas?
Requesting Gravatar... Christopher Steen Jun 20, 2007 8:16 PM
# Link Listing - June 20, 2007
Silverlight on Linux Already [Via: Jesse Ezell ] VS 2008 Multi-Targeting Support [Via: ScottGu ] Model-View-Presenter...
Requesting Gravatar... Haacked Jun 20, 2007 9:58 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
@Sean - That's odd. It compiles on my machine, but it doesn't on our build server. I'm looking into it. Any ideas?
Requesting Gravatar... Haacked Jun 20, 2007 11:16 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
@Sean - It turns out that this is because the accessibility of this interface changes to Public with Vista.

Read up on it here.
Requesting Gravatar... Sean Jun 21, 2007 5:46 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Could you extract that Interface and include in the zip file so it would be possible to run it on non-Vista machines? That would be really helpful. 10x
Requesting Gravatar... Sean Jun 21, 2007 7:58 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
I was trying to extract IConfigMapPath, but this was useless as it has a member of VirtualPath type, which is (as usual) internal with a bunch of other internal utility classes. Would be more practical to supply the System.Web.dll from the .NET 3.0 Vista install? Banging my head over the wall as long as can't use your solution :(
Requesting Gravatar... Mark Jun 21, 2007 8:02 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
You don't need to extract the interface. I had the same problem, what you do is compile a signed version of the HttpSimulator on your vista machine then reference the assembly in your unit test projects. This way, your build server does not compile the code itself. That was my work around.
Requesting Gravatar... Travis Illig Jun 21, 2007 8:10 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
The other alternative is to use TypeMock and mock the HttpContext. That works pretty well and hasn't caused me a build error yet. :)

Of course, it does imply you're willing to go with TypeMock (which I love and highly recommend, and which there is a free "Community" version that should work just fine for this). Not everyone is as gung-ho for TypeMock as I am, but it does solve problems like this very nicely...
Requesting Gravatar... Jacob Jun 21, 2007 8:18 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
@Travis: I just discovered TypeMock and it's got me pretty excited. It's the first mock framework that does what I really want in a mock.
Requesting Gravatar... Don Demsak Jun 21, 2007 8:22 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Have you tried to mock MapPath? I couldn't get that to work. Jason Bock found out the same thing when he tries to mock HttpContext: http://www.jasonbock.net/JB/Default.aspx?blog=entry.b89f5611046d4555be2e39af9dd1448a
Requesting Gravatar... Haacked Jun 21, 2007 5:08 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
@Don Demsak - I did. In fact, I've included unit tests that demonstrate mocking MapPath.
Requesting Gravatar... lb Jun 21, 2007 5:17 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
this is how I mock HttpContext:
"Oooo, Mr Context, aren't we clever! THink we're Mr Big Boots because we know so much! Well shut up, context, you ain't no einstein!"
I find it fairly effective.

What am I missing?

Obligatory serious comment:
Check out http://www.incisif.net/QuickUnit.net/ -- a way of writing simple unit tests as attributes of your functions/classes/properties. much fun.

lb
Requesting Gravatar... Travis Illig Jun 22, 2007 10:30 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Mocking MapPath is no problem with TypeMock. (Again, maybe not your cup of tea, but it does mock pretty much anything with the exception of a few of the System objects.)
Requesting Gravatar... Haacked Jun 22, 2007 10:49 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Well I've heard it's free for community and OSS use, so I may give it a try. A

t this point, I'm just hesitant to find out whether I wasted a lot of time on my impl and should just kick myself for not using it earlier. ;)
Requesting Gravatar... Joshua Flanagan Jun 23, 2007 6:46 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Does it work with System.Web.HostingEnvironment? It was introduced in ASP.NET 2.0 and is supposed to replace a lot of the old uses of HttpContext. Apparently it is a better idea to use this class where you can, so your code is less HTTP specific (keeping in mind the new hosting models available in Vista/Server 2008/WAS).
Clemens Vasters gave us a heads up about it on the Dasblog mailing list.
Requesting Gravatar... Haacked Jun 23, 2007 8:42 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
@Joshua - How do you do this with the HostingEnvironment?
HttpContext.Current.Request.RawUrl
Requesting Gravatar... Jim Bonnie Jun 28, 2007 7:11 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Very nice - thanks for the support of session variables - I am starting to use this for Unit testing DotNetNuke Web applications.
Requesting Gravatar... donkeymaster Jun 28, 2007 11:03 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
i've been using the server from www.neokernel.com to test my ASP.Net pages (and run my website), although it IS a webserver, it runs ASP.NET like IIS does (unlike Webdev.webserver, which sometimes behaves differently).
Requesting Gravatar... Miguel Madero Jul 16, 2007 5:13 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Thanks man, this saved the day!!!!
I heard some guys are having troubles, but I needed to try a really simple stuff and this just did the trick.
Requesting Gravatar... Paraesthesia Aug 02, 2007 3:14 PM
# Mock a Page Request Lifecycle with TypeMock
Mock a Page Request Lifecycle with TypeMock
Requesting Gravatar... Dave Donaldson Aug 08, 2007 12:16 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Adding this comment for future reference... for anyone experiencing the "System.Web.Configuration.IConfigMapPath is inaccessible due to its protection level" problem, the ConfigMapPath class is really only needed if you require programmatic access to the MapPath property within a unit test. If you don't, then comment out the internal ConfigMapPath class and the line that calls it (both in HttpSimulator.cs) and recompile. That gets it to work on your non-Vista dev machine and non-Vista build machine. At least that's how I fixed it anyway.
Requesting Gravatar... you've been HAACKED Aug 19, 2007 9:45 PM
# Why Duck Typing Matters To C# Developers
Why Duck Typing Matters To C# Developers
Requesting Gravatar... Ulu Aug 26, 2007 2:44 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
My recipe is: Plasma + TypeMock. I use Plasma for in-process testing and TypeMock to get access to the HTTPContext and Page objects. So far, I haven't used it in any tests, but I've got a valid reference to my page and verified that its controls are there, and this is a big step. Finally I'm able to use the same level of abstraction that I use in my production code.

So, I'm able to write code like this:
System.Web.UI.Page page = GetPage("~/Default.aspx");
System.Web.UI.WebControls.Label label = page.FindControl("Label1");
Assert.AreEqual("Hello World", label.Text);

The details are here http://dotfresh.blogspot.com/2007/08/aspnet-tesability-finally-way-it-should.html

ulu
Requesting Gravatar... Bruce Chapman Aug 29, 2007 12:38 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
I'm getting a strange error using your code and supplying an appPath value. After calling the SimulateRequest, my system.web.httpContext.Current.Request.AppRelativeCurrentExecutionFilePath shows a value of '~h/page.aspx' where h = the last letter of the path (ie /mypath) and page.aspx is the page name.

This causes my code to later on rewrite a url as mypathpage.aspx (the code works Ok when running in the website). The value changes to this on the call of HttpContext.Current = new HttpContext(workerRequest).

Any ideas? It works OK with a appPath value of "/". I was looking for some string manipulation in the code that had a 1 instead of a -1 or something, but all searches == fruitless.

/hair torn out
-Bruce
Requesting Gravatar... Dirc Oct 03, 2007 5:58 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Excellent work!!

Now... I have a problem trying to use Sessions between calls that I need to simulate. I need to make one call, which saves data to the Session. I then need to make another call using the same session to check stuff that happens if a session already exists.

Is there an existing way to do this or would I need to customise the HttpSimulator?
Requesting Gravatar... Haacked Oct 03, 2007 8:59 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
I think the latest version properly simulates Session.
Requesting Gravatar... Joe Nov 06, 2007 11:24 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator (Bug)
This seems to fall over when using the cache object.

In one unit test, I add an item to the cache, and in another I try to add the item again, but it already exists.

For example when running the following tests together , one will pass and one will fail. When running them one at a time, both will pass.

[Test]
public void Add_Item_To_Cache()
{
using (new HttpSimulator("/", @"c:\inetpub\").SimulateRequest())
{
Assert.IsTrue(HttpContext.Current.Cache.Count == 0, "Cache should be empty");
HttpContext.Current.Cache.Add("myKey", "myObject", null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Low, null);
Assert.IsTrue(HttpContext.Current.Cache.Count == 1, "Cache should have an item");
}
}

[Test]
public void Add_Item_To_Cache_Again()
{
using (new HttpSimulator("/", @"c:\inetpub\").SimulateRequest())
{
Assert.IsTrue(HttpContext.Current.Cache.Count == 0, "Cache should be empty");
HttpContext.Current.Cache.Add("myKey", "myObject", null, DateTime.Now.AddHours(1), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Low, null);
Assert.IsTrue(HttpContext.Current.Cache.Count == 1, "Cache should have an item");
}
}



Requesting Gravatar... Kevin G Nov 09, 2007 12:06 PM
# 'System.Web.Configuration.IConfigMapPath' is inaccessible due to its protection level
So is there no way to solve this without using Vista?

..works on my machine, which is XP, not the build server, so something is being done correctly on my machine (with VS 2005 installed....)

HttpSimulator.cs(722,38): error CS0122: 'System.Web.Configuration.IConfigMapPath' is inaccessible due to its protection level
Requesting Gravatar... Kevin G Nov 09, 2007 5:21 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
ah. Found the answer here:

http://haacked.com/archive/2007/06/20/what-a-difference-a-revision-makes---iconfigmappath-is-inaccessible.aspx

I upgraded to .net 3.5, which replaced System.Web with a newer version.
Requesting Gravatar... Alexey Moudrick Dec 25, 2007 11:18 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Could you fix or at least suggest how to fix the test?
[Test]
[Ignore("NotWorking")]
public void LoadControl()
{
string mapPath = AppDomain.CurrentDomain.BaseDirectory;
string controlFullPath = @"/Control.ascx";
File.WriteAllText(mapPath + controlFullPath, @"
<%@ control autoeventwireup=""false"" language=""c#"" %>
<span>test</span>");
using (HttpSimulator simulator = new HttpSimulator(@"/", mapPath))
{
simulator.SimulateRequest();

System.Web.UI.Page page = new System.Web.UI.Page();
Assert.IsNotNull(page);
System.Web.UI.Control control = page.LoadControl(controlFullPath);
Assert.IsNotNull(control);
}
}

Also, did not you think to start a little (or even more than little) open source project on some code hosting? Community could contribute a lot of ideas, feature and testing. I can start the projest with code linked from the article as the first contribution ;)
Requesting Gravatar... Alexey Moudrick Dec 25, 2007 11:25 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
This is the output of the test:

Starting the MbUnit Test Execution
Exploring HttpSimulator, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
MbUnit 1.0.2700.29885 Addin
Found 1 tests
[failure] HttpSimulatorTests.LoadControl
TestCase 'HttpSimulatorTests.LoadControl' failed: Object reference not set to an instance of an object.
System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: System.Web
StackTrace:
at System.Web.Compilation.BuildManager.GetCacheKeyFromVirtualPath(VirtualPath virtualPath, Boolean& keyFromVPP)
at System.Web.Compilation.BuildManager.GetVPathBuildResultFromCacheInternal(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.UI.TemplateControl.LoadControl(VirtualPath virtualPath)
at System.Web.UI.TemplateControl.LoadControl(String virtualPath)
D:\home\rainbow\googlecode\svn\sandboxes\moudrick\trunks\extract_PortalSettingsProvider\Tests\HttpSimulator\HttpSimulatorTests.cs(330,0): at UnitTests.SUbtext.HttpSimulatorTests.LoadControl()

[reports] generating HTML report
TestResults: file:///C:/Documents%20and%20Settings/alexm.BDUA/Application%20Data/MbUnit/Reports/HttpSimulator.Tests.html

0 passed, 1 failed, 0 skipped, took 3.73 seconds.


Requesting Gravatar... Daniel Gonzalez Dec 29, 2007 8:51 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Hi Phil,

I am finding a VERY weird issue while using your code.
I am testing a piece of code that changes the handler once the request is simulated. But when I run my test alongside some other tests I get an Exception:
Test.Dgg.Utilities.Web.ClientScriptHelperTester.TryRegisterClientScriptIncludeInPage_NonPageHandler_ScriptNotRegistered : System.Web.HttpException : Invalid use of SimpleWorkerRequest constructor. Application path cannot be overridden in this context. Please use SimpleWorkerRequest constructor that does not override the application path.

But this exception does not show when I run my test in isolation (no other test running). It shows the same strange behavior both in NUnit runner (2.4.5) and TestDriven.Net (latest version).

Of course, when I change your code so that SimulateHttpRequest calls another base constructor, my tests run fine, but yours not.

Any clues?

Thanks a lot
Any clues?
Requesting Gravatar... Noam Elyashiv Jan 06, 2008 3:30 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
How can make it haapend with the user object also
Requesting Gravatar... 分享 Jan 22, 2008 4:33 AM
# 可以测试Session相关的代码了
需要测试的代码分为如下几个部分:纯粹的相对简单的计算页面逻辑HTTP相关的代码数据库相关1很容易测试,2还没有尝试过,估计有麻烦;3今天找到模拟的办法了;4基本上是可以测试的,只是数据准备和清理比...
Requesting Gravatar... Slevdi Feb 04, 2008 11:07 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
@joe Re: Cache object

Just in case you didn't solve this:

The result you get is correct. The cache remains intact for the duration of the application so you need to clear it in between tests.

I would put a cache clearing method as a SetUp:

(Note that you don't need to use HttpContext for the cache; HttpRuntime works fine without the simulator.)


internal static Cache cache = HttpRuntime.Cache;

[SetUp]
public void SetUp()
{
foreach (DictionaryEntry cacheItem in cache)
{
cache.Remove(cacheItem.Key.ToString());
}
}


Then I would refactor the tests to use the internal static cache field.

Requesting Gravatar... Slevdi Feb 08, 2008 7:26 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Phil - I am having great success so far with HttpSimulator. Thanks for it.

Question: How do I do resources using it? E.g.:

string key = (string) HttpContext.GetGlobalResourceObject(classKey,resourcekey);

Requesting Gravatar... Jai Feb 12, 2008 8:19 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Hi,

I was successful creating a HttpContext but not HttpContext.Current.Profile since it is read-only. My application code makes use of Profile and the NUnit test fails because
"Property or indexer 'System.Web.HttpContext.Profile' cannot be assigned to -- it is read only". Any help here?

Thanks in advance.
Jai
Requesting Gravatar... Ulu Mar 06, 2008 2:45 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
You might want to take a look at Ivonna. Doesn't need a web server, and you can test your views in an object-oriented way (not just raw html, but control values).
Requesting Gravatar... Josh Blanchard Apr 02, 2008 12:01 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Wow. This was so helpful and so easy to use. Thanks for posting!
Requesting Gravatar... Paul May 01, 2008 1:50 PM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Phil, You're a life-saver. Thanks! The check is in the mail! ;-)
Requesting Gravatar... Ameya Gholap May 13, 2008 12:16 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
This is awesome - worked in a first shot
I knew something could be done about web tests - but thought of googling instead of writing something of my own - landed up here - and it worked like magic.. Thank you!
Cool stuff.. \m/
Requesting Gravatar... Pennidren May 16, 2008 10:21 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
Exactly what I needed and works great.
Thanks!
Requesting Gravatar... Lily Jul 07, 2008 2:05 AM
# re: Unit Test Web Code Without A Web Server Using HttpSimulator
How to simulate post xml data via http request

What do you have to say?

(will show your gravatar)
Please add 8 and 6 and type the answer here: