Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Global.asax.cs and unittests

Reply
Thread Tools

Global.asax.cs and unittests

 
 
Peter Larsen [CPH]
Guest
Posts: n/a
 
      09-05-2008
Hi,

I have a problem where the code in Global.asax.cs runs before the unittests
(on test of course).

In the global file, i load some data from a Oracle table and save it in
HttpApplicationState. This is happening in the Application_start function.

The following unittest show the beginning of the method, where the database
mock is created. If this mock isn't created, the unittest will try to access
the database - which is not allowed/possible from the build server.

[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\...Web", "/")]
[UrlToTest("http://localhost:2044/")]
[DeploymentItem("...Web.dll")]
public void PageTest()
{
DatabaseAccess.CreateDataAccessMock();
//the test code

}

The problem is that i want the mock to be created before the Global.asax.cs
file is called.
Is that possible ??

Thank you in advance.

BR
Peter


 
Reply With Quote
 
 
 
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      09-08-2008
Hi Peter,

Regarding on this issue, you 're using unit testing framework to perform
test on your ASP.NET web page, however, you found some code in Global.asax
always get executed first before some of your unit test intilize code, you
want to make the unit test code executed first, correct?

Based on my understanding, ASP.NET application is a particulur one as
ASP.NET appdomain is hosted by an existing process. And at the startup
time, the code in global.asax is always run first. I'm afraid so far there
hasn't provided inteface for customize the execution time or sequence of
the global.asax(it is executed before each page request get executed, I
think the unit test code is executing together with each page request).

My current thought is whether it is convenient to move those initialize
code(for unit test) into global.asax? thus, all the unit test functions
only contains code that is ok to execute after the global.asax

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
http://www.velocityreviews.com/forums/(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Peter Larsen [CPH]" <(E-Mail Removed)>
>Subject: Global.asax.cs and unittests
>Date: Fri, 5 Sep 2008 20:57:30 +0200


>Hi,
>
>I have a problem where the code in Global.asax.cs runs before the

unittests
>(on test of course).
>
>In the global file, i load some data from a Oracle table and save it in
>HttpApplicationState. This is happening in the Application_start function.
>
>The following unittest show the beginning of the method, where the

database
>mock is created. If this mock isn't created, the unittest will try to

access
>the database - which is not allowed/possible from the build server.
>
> [TestMethod()]
> [HostType("ASP.NET")]
> [AspNetDevelopmentServerHost("C:\...Web", "/")]
> [UrlToTest("http://localhost:2044/")]
> [DeploymentItem("...Web.dll")]
> public void PageTest()
> {
> DatabaseAccess.CreateDataAccessMock();
> //the test code
>
> }
>
>The problem is that i want the mock to be created before the

Global.asax.cs
>file is called.
>Is that possible ??
>
>Thank you in advance.
>
>BR
>Peter
>
>
>


 
Reply With Quote
 
 
 
 
Peter Larsen [CPH]
Guest
Posts: n/a
 
      09-09-2008
Hi Steven,

Thanks for your reply.

I use unittests to test my business logic - and yes, i have found that
Global.asax always get fired first.
This is also what you say. And you also say that there is no way around
this.

The code in Global.asax has no importans for the unittest.
If it was possible, i would disable Global.asax when running unittests.

The only solution i can think of, is to move the code from global.asax and
to the default page - or to all pages and then ensure the code is only run
once. Only that way, the unittests run before any business logic.

BR
Peter


 
Reply With Quote
 
Steven Cheng [MSFT]
Guest
Posts: n/a
 
      09-10-2008
Thanks for your reply Peter,

I think your workaround it also reasonable. You can remove the global.asax
and put the code logic to a default page which is guranteed to be run at
the earlier time of your web application.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(E-Mail Removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.




--------------------
>From: "Peter Larsen [CPH]" <(E-Mail Removed)>
>References: <#(E-Mail Removed)>

<(E-Mail Removed)>
>Subject: Re: Global.asax.cs and unittests
>Date: Tue, 9 Sep 2008 10:15:54 +0200


>
>Hi Steven,
>
>Thanks for your reply.
>
>I use unittests to test my business logic - and yes, i have found that
>Global.asax always get fired first.
>This is also what you say. And you also say that there is no way around
>this.
>
>The code in Global.asax has no importans for the unittest.
>If it was possible, i would disable Global.asax when running unittests.
>
>The only solution i can think of, is to move the code from global.asax and
>to the default page - or to all pages and then ensure the code is only run
>once. Only that way, the unittests run before any business logic.
>
>BR
>Peter
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unittests with different parameters Ulrich Eckhardt Python 9 11-24-2010 02:10 PM
question about an exciting gotcha for unittests (and elsewhere) ... Cameron Simpson Python 3 04-23-2010 07:05 PM
Error on using require 'unittests/setup' Puneet Pattar Ruby 1 12-14-2009 09:46 AM
Python and database unittests Daniel Python 9 08-27-2008 10:33 AM
Bugtracking & UnitTests == good? martinankerl at eml dot cc Ruby 13 07-11-2004 11:53 PM



Advertisments