views:

467

answers:

1

I just wrote some new utility methods within a non-page class for an existing .NET webforms application and decided to try to unit test using the VS unit test framework rather than testing by hand. I've used the unit test tools before, but only on EXE and MVC projects, and am encountering an error connecting to the WebHostAdapter no matter what I've tried so far.

The current test:

 [TestMethod()]
 [HostType("ASP.NET")]
 [AspNetDevelopmentServerHost("C:\\inetpub\\wwwroot\\sitepath", "/")]
 [UrlToTest("localhost/Login.aspx")]
 public void UrlFriendlyTitleTest()
 {
  string dirtyPath = "São\\Hell & High water";
  string expected = "sao/hell-high-water";
  string actual;
  actual = GeneralUtility_Accessor.UrlFriendlyTitle(dirtyPath);
  Assert.AreEqual(expected, actual);
  Assert.Inconclusive("Verify the correctness of this test method.");
 }

The error I'm encountering:

The test adapter 'WebHostAdapter' threw an exception while running test 'UrlFriendlyTitleTest'. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting 'localhost:53874/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.

What I've tried so far:

Set UrlToTest to current running debug path for a page in the project.
Promoted application to the local default site (reflected in current value of UrlToTest).
Set UrlToTest to point to an unauthenticated page (it shouldn't matter which page is called--I'm testing a method that's not even referenced yet).
Suggestions from MSDN boards (unable to post more than 1 link).
And I've tried the suggestions and web.config changes listed by the author of this SO question.

Is there a canonical answer for this issue that I've missed?

+1  A: 

Typically, I'll have all of my non-page classes defined in a separate assembly (class library) that gets referenced from the web site. It's much easier to unit test class libraries than it is to test web sites. My advice would be to move your GeneralUtility class into a class library and test it from there.

tvanfosson
Unfortunately, I can't change the structure of the solution on this app. This would probably be the best fix if I were able to, though.
Daniel Halsey