Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
135 views
in Technique[技术] by (71.8m points)

500 Error Running Visual Studio ASP.NET Unit Test

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:ESIHR_Connect2BenefitChangeSystemApplication_DEVWebSysCoord.

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%solutionfolderwebfolder", "/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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...