views:

3610

answers:

9

I have the following method in my unit test project:

    [TestMethod]
    [HostType("ASP.NET")]
    [UrlToTest("http://localhost:3418/Web/SysCoord/ChooseEPA.aspx")]
    [AspNetDevelopmentServerHost("%PathToWebRoot%")]
    public void TestMethod1()
    {
        Page page = TestContext.RequestedPage;
        Assert.IsTrue(false, "Test ran, at least.");
    }

I'm getting this exception:

The test adapter 'WebHostAdapter' threw an exception while running test 'TestMethod1'. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'http://localhost:3418/SysCoord/VSEnterpriseHelper.axd' returned an error: The remote server returned an error: (404) Not Found. The remote server returned an error: (404) Not Found.

The page works as it should in a browser at the url: http://localhost:3418/Web/SysCoord/ChooseEPA.aspx.

This physical path is: C:\ESI\HR_Connect2\BenefitChangeSystem\Application_DEV\Web\SysCoord.

Any ideas would be appreciated.

Update 1

Added the following to my web.config file per this article. Also made the web.config writable and killed/restarted the development web server. No change in behavior.

<location path="VSEnterpriseHelper.axd">
 <system.web>
  <authorization>
   <allow users="*"/>
  </authorization>
 </system.web>
</location>

Update 2

Changing the AspNetDevelopmentServerHost attribute to the equivalent of [AspNetDevelopmentServerHost("%PathToWebRoot%\solutionfolder\webfolder", "/webfolder")] resolved the 404 problem.

Unfortunately the test began to return a 500 error instead. Progress, but not much. Trial and error with a clean project led to the conclusion that references to custom classes in the of the web.config were causing the problem.

For example:

 <profile enabled="true" defaultProvider="MyProfileProvider">
  <providers>
   <add name="MyProfileProvider" connectionStringName="ProfileConnectionString" applicationName="/MyApp" type="System.Web.Profile.SqlProfileProvider"/>
  </providers>
  <properties>
   <add name="Theme" type="String" defaultValue="Default"/>
   <add name="LastLogon" type="DateTime"/>
   <add name="LastLogonIp" type="String"/>
   <!--
   <add name="EmployeeSearchCriteria" type="MyApplicationFramework.Profile.EmployeeSearchCriteria"/>
   <add name="DocumentSearchCriteria" type="MyApplicationFramework.Profile.DocumentSearchCriteria"/>
   -->
  </properties>
 </profile>

With the criteria types above commented out the test ran fine. With them uncommented, the 500 error was returned.

Anyone had a similar problem in the past?

+1  A: 

Based on your evidence I would guess that a reference to whichever assembly contains MyApplicationFramework.Profile.EmployeeSearchCriteria is missing from either the unit test project or the web project - though I would really think that you would only require the reference in the web project but I'm not knowledgeable about how the VS web server behaves when used as part of a unit test.

cfeduke
A: 

Hello friends,

I have faced same problem with unit testing. And found the problem reason and also solve it. The problem is only with access rights for the directory.

In my case I have installed VSTS on the different drive(d) then default. So only to give the full access rights to the user PCNAME\ASPNET for whole directory \Program Files\Microsoft Visual Studio 9.0.

I m using the windows XP but if u are using window server then give access rights to the user NetworkServices.

By this solution i have solved my problem. Hope u find something useful from this Answer.

Thanks, Priyesh Patel

+1  A: 

I was getting the same problem as you, however my experience was a little different.

I am on vista x64, my developers are in xp x64...they haven't been having any issues at all. I just upgraded and could not run any unit test for a asp.net MVC project. I was receiving the same 500 error you were receiving.

I turned off code coverage, everything magically started working.

ben
+1  A: 

Comment out the whole bit of web.config like this

<!-- <location path="VSEnterpriseHelper.axd">
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
    </system.web>   </location>   -->

It worked for me

A: 

Hi,

I am also facing the same error("The test adapter 'WebHostAdapter' threw an exception while running test 'AxSPSite'. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'http://dev05:4444/VSEnterpriseHelper.axd' returned an error: The remote server returned an error: (500) Internal Server Error. The remote server returned an error: (500) Internal Server Error.") while using like this

    [TestMethod]
    [HostType("ASP.Net")]
    [UrlToTest("http://localhost:4444/smallarray/Pages/default.aspx")] 
    public void SPSite()            
    {            
        SPWeb theWeb; 
        theWeb = SPContext.Current.Web;

    }

So can anyone give a solution for this.......

Thanks in advance

Karthick
A: 

Make sure your web application is targeted to Framework 4.0. If you are trying to test a 2.0, 3.0 or 3.5 project, you will get the (500) Internal Server Error.

Scott
A: 

I found that using vs2010 I am not restricted to just 4.0 applications. I DID however find that if testing a web application and you are using the old System.Web.Extensions version redirect you may get an error. Removing this fixed my issue.

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v2.0.50727"><dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
        <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
    </dependentAssembly>
</assemblyBinding>

Good luck.

Hal Diggs
A: 

I ran into a similar issue testing a webservice where the project is .NET 3.51. I was getting a IIS 500 error. I removed the old assembly bindinds as commented by Hal Diggs and it worked.

Bigdog
A: 

I've had this problem before and at that point gave up after reading all I could google about it (including this thread).

The solution turned out to be simple in my case. All I had to do was not use ASP.NET test attributes and simply test the MVC project as a DLL.

Step 1

Remove the extra attributes from the test.

[TestMethod]
public void TestMethod1()
{
    Page page = TestContext.RequestedPage;
    Assert.IsTrue(false, "Test ran, at least.");
}

Step 2

In Code Coverage, uncheck the MVC Project and add the MVC Project's DLL manually.

alt text

Voila, it get instrumented as a normal assembly, no errors, doesn't spin up the Development Server, also doesn't fail the Team Build.

Igor Zevaka