NUnit and Session state

  • Thread starter Thread starter Mark
  • Start date Start date
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
 
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
|
|
 
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,
 
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.
 
Back
Top