473,325 Members | 2,774 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,325 software developers and data experts.

Global.asax.cs and unittests

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
Sep 5 '08 #1
3 5195
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:
ms****@microsoft.com.

==================================================
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]" <Pe*********@community.nospam>
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
Sep 8 '08 #2
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
Sep 9 '08 #3
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:
ms****@microsoft.com.

==================================================
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]" <Pe*********@community.nospam>
References: <#u**************@TK2MSFTNGP06.phx.gbl>
<N2**************@TK2MSFTNGHUB02.phx.gbl>
>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
Sep 10 '08 #4

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

Similar topics

22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
12
by: John M | last post by:
Hello, On Microsoft Visual Studio .NET 2003, I want to use some global elements, that can be used in each one of my pages. i.e I put a oleDBConnection on global.asax.vb How can I use it...
8
by: Vishwanathan Raman | last post by:
Hi I have a declared a static DataSet object SOBJ in Global.asax.I also have a localy defined DataSet LSOBJ in Global.asax which I am storing in Application State.Is there any technical...
5
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
4
by: Al Santino | last post by:
Hello, I've created a simple C# web services project using Visual Studio 2005. My service compiles and runs correctly when called by remote clients. I'm able to step through the service in the...
16
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@...
8
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project...
15
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax code file. In 1.1 I could have a code behind file for the global.asax file. This allow for shared variables of the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.