473,387 Members | 1,779 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,387 software developers and data experts.

NUnit and Session state

I'm building some NUnit tests for the business classes in my ASP.NET
application. Some of the business classes use Session to store information.
NUnit does not generate a Session, so the code below bombs when a

HttpContext.Current.Session["some_key"];

Any suggestions on the best alternative for working around this, without
making a hack job out of the code? I can check the HttpContext.Current and
check to see if it is null, but where/how should I store the alternative
session information? Not sure if it is relevant, but I'm not using
NUnitAsp.

Thanks in advance.
Mark
Nov 19 '05 #1
4 3477
HI Mark:

There are a couple tips on this page:
http://home.iprimus.com.au/lachlanb/nunitasp/nunit.html

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 2 Mar 2005 16:10:28 -0600, "Mark" <Ma**@nowhere.com> wrote:
I'm building some NUnit tests for the business classes in my ASP.NET
application. Some of the business classes use Session to store information.
NUnit does not generate a Session, so the code below bombs when a

HttpContext.Current.Session["some_key"];

Any suggestions on the best alternative for working around this, without
making a hack job out of the code? I can check the HttpContext.Current and
check to see if it is null, but where/how should I store the alternative
session information? Not sure if it is relevant, but I'm not using
NUnitAsp.

Thanks in advance.
Mark


Nov 19 '05 #2
you should switch to the factory model for session management, them you can
supply a mock session handler for the unit tests.
-- bruce (sqlwork.com)


"Mark" <Ma**@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
| I'm building some NUnit tests for the business classes in my ASP.NET
| application. Some of the business classes use Session to store
information.
| NUnit does not generate a Session, so the code below bombs when a
|
| HttpContext.Current.Session["some_key"];
|
| Any suggestions on the best alternative for working around this, without
| making a hack job out of the code? I can check the HttpContext.Current
and
| check to see if it is null, but where/how should I store the alternative
| session information? Not sure if it is relevant, but I'm not using
| NUnitAsp.
|
| Thanks in advance.
| Mark
|
|
Nov 19 '05 #3
Mark wrote:
I'm building some NUnit tests for the business classes in my ASP.NET
application. Some of the business classes use Session to store
information. NUnit does not generate a Session, so the code below
bombs when a

HttpContext.Current.Session["some_key"];

Any suggestions on the best alternative for working around this,
without making a hack job out of the code?


You've tightly coupled your business logic with your web UI -- and
found out that it's a bad idea. Just don't do that. Pass your business
objects the data they need and keep them free of all ASP.NET/HTTP/web
stuff. All of a sudden, your code becomes clean & testable :-)

Cheers,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 19 '05 #4
Have you seen
SWExplorerAutomation(http:\\home.comcast.net/~furmana/SWIEAutomation.htm)?
You can write tests by automating IE. It means that all functionality
of Web Application can be tested, including client scripts.

Mark wrote:
I'm building some NUnit tests for the business classes in my ASP.NET
application. Some of the business classes use Session to store information. NUnit does not generate a Session, so the code below bombs when a

HttpContext.Current.Session["some_key"];

Any suggestions on the best alternative for working around this, without making a hack job out of the code? I can check the HttpContext.Current and check to see if it is null, but where/how should I store the alternative session information? Not sure if it is relevant, but I'm not using
NUnitAsp.

Thanks in advance.
Mark


Nov 19 '05 #5

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

Similar topics

2
by: Sky Kim | last post by:
Hi, all. I've know NUnit for a while, now I try to use it. Most of application I develope is data base driven. I want to test data layer most with may input and checking the result, then compare...
1
by: Johan Nedin | last post by:
Hello! I have a problem with SQLSession state on my ASP.NET pages. SQLSession state behaves very different from InProcess session state, which I think is very bad. I can understand some of...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
5
by: Mike Hofer | last post by:
I need some advice, folks, and I'm hoping you can provide it. First off, a few disclaimers: 1.) I am an ardant advocate of code quality. Especially, my own. 2.) I am maintaining a massive...
11
by: Glenn | last post by:
Hi I've been experimenting with managing state using the Session object. I've created a simple WS with a couple of methods, one which sets a string value, another that retrieves it. Each...
0
by: manjitsarma | last post by:
In doing NUNIT Testing(In the RUN event of NUNIT),I am losing the value of the OBJECT whose methods and variables I need to check.The OBJECT is 'MAP' here.What I should do to solve the problem ?...
2
by: Sonali24 | last post by:
Hi All, I am not sure whether write place to post this in this forum. I am new to Nunit.. I am facing problems to test or instantiate the session variables. I used...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.