473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Unit Testing classes that derive from IHttpHandler

Hello,

Is there a way to unit test a that derives from IHttpHandler that uses
the HttpResponse in the HttpContext passed to it?

When I try to call the context.Response.End() method, I get the
following error:
Unable to connect to the remote server

I am looking at
http://hyperthink.net/blog/CommentVi...e25348b8c.aspx
which has a way to create a HttpRuntime, so IIS is not needed to unit
test an asp.net page.

Unfortunately, I can't figure out how to get the IHttpHandler attached.

Does anybody know how to do this?

Thank you,
Brian Takita

Nov 19 '05 #1
5 2670
Fyi,

I'm trying to unit test a this class (with a few revisions):
http://www.codeproject.com/aspnet/HTTPReverseProxy.asp

Nov 19 '05 #2
Fyi,

I'm trying to unit test this class (with a few revisions):
http://www.codeproject.com/aspnet/HTTPReverseProxy.asp

Nov 19 '05 #3
Problem solved. The context can be called directly if an
ApplicationInstance is assigned to the context.

Here is a snippet of my test code:

Thread.GetDomain().SetData(".appPath",
"c:\\inetpub\\wwwroot\\webapp\\");
Thread.GetDomain().SetData(".appVPath", "/webapp");
Thread.GetDomain().SetData(".hostingVirtualPath", "/webapp");
Thread.GetDomain().SetData(".hostingInstallDir",
HttpRuntime.AspInstallDirectory);

StringWriter sw = new StringWriter();
SimpleWorkerRequest wr = new SimpleWorkerRequest("default.aspx", "",
sw);
HttpContext context = new HttpContext(wr);

context.ApplicationInstance = new HttpApplication();

CustomHttpProxy p = new CustomHttpProxy ();
p.ProcessRequest(context);

Nov 19 '05 #4
One problem I'm running into now is reading the Response.OutputStream.

Does anybody know how to read this stream into a string variable?

Thank you,
Brian

Nov 19 '05 #5
A good post about this subject can be found at:
http://groups-beta.google.com/group/...1cfe2d43fb4d92

Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hugh Cowan | last post by:
Hello, I don't program full-time (anymore), but I do try and stay on-top of the latest technologies and like most are always trying to upgrade my skills and remain current (as much as is...
2
by: Edvard Majakari | last post by:
Hi all ya unit-testing experts there :) Code I'm working on has to parse large and complex files and detect equally complex and large amount of errors before the contents of the file is fed to...
5
by: Pete | last post by:
Hi folks, I've been looking at unit testing frameworks (csUnit, NUnit, etc) and have gathered some info on them (see the older thread on c# 2004). My question is this: how do they work with...
2
by: Naveen Mukkelli | last post by:
Hi, I'm writing a client/server application using C#. The server accepts connecitons asynchronously, using BeginAccept/EndAccept. Is there any way we can write some unit tests(NUnit) to test...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
2
by: PeterKellner | last post by:
I'm trying to understand how asp.net 2.0 ties together the codebehind. I've made a simple page, turned debug on so the *0.cs,*1.cs,*2.cs files don't get erased. My first point of confusion is...
10
by: Sean Chambers | last post by:
Hello, I am attempting to utilize the MVP pattern in a new app I am building. I am using TDD, along with mock views attached to the View interface to attempt to unit test the UI. The problem I...
20
by: earthwormgaz | last post by:
Hello, I'm after doing some C++ unit testing, I'm using CppUnit. I like the look of RudeMocks, but it doesn't work for Solaris/Sparc, so its no good to me sadly. So, I have class A, and it...
10
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.