NUnit and Session state

M

Mark

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
 
B

bruce barker

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)




| 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
|
|
 
J

Joerg Jooss

Mark said:
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,
 
A

alex_f_il

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top