title: Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
body: <p>I have been attempting to run a Unit Test in visual studio for an MVC Application and continuously getting the following error:</p>
  
  <blockquote>
    <p>The URL specified ('http://localhost:21496/') does not correspond to a
    valid directory. Tests configured to run in ASP.NET in IIS require a
    valid directory to exist for the URL. The URL may be invalid or may
    not point to a valid Web application.</p>
  </blockquote>
  
  <p>The only advice around is to make sure you have a localhost address in the UrlToTest attribute like so:</p>
  
  <blockquote>
  <pre><code>    [TestMethod()]
      [HostType("ASP.NET")]
      [UrlToTest("http://localhost:21496/")]
  </code></pre>
  </blockquote>
  
  <p>This however still doesn't run against IIS Express or IIS 7 on Windows 7 and when I delved into the event logs, found the following problem.</p>
  
  <pre><code>(QTAgent32.exe, PID 6976, Thread 15) WebSites.GetWebServer: failed to create AspNetHelper: Microsoft.VisualStudio.Enterprise.Common.AspNetHelperException: The website metabase contains unexpected information or you do not have permission to access the metabase.  You must be a member of the Administrators group on the local computer to access the IIS metabase. Therefore, you cannot create or open a local IIS Web site.  If you have Read, Write, and Modify Permissions for the folder where the files are located, you can create a file system web site that points to the folder in order to proceed. ---&gt; System.Runtime.InteropServices.COMException: Unknown error (0x80005000)
     at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
     at System.DirectoryServices.DirectoryEntry.Bind()
     at System.DirectoryServices.DirectoryEntry.get_IsContainer()
     at System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(DirectoryEntry container)
     at Microsoft.VisualStudio.Enterprise.Common.IISHelper.GetWebServerOrdinal(Uri site)
     --- End of inner exception stack trace ---
     at Microsoft.VisualStudio.Enterprise.Common.IISHelper.GetWebServerOrdinal(Uri site)
     at Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_WebServerOrdinal()
     at Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_RootPath()
     at Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_PhysicalPath()
     at Microsoft.VisualStudio.Enterprise.Common.AspNetHelperMan..ctor(Uri uri, BasicAuthCredential credential, Int32 frameworkMajorVersion)
     at Microsoft.VisualStudio.TestTools.HostAdapters.WebSites.GetWebServer(String webServerName, WebServerType webServerType, String urlToTest, String pathToWeb, String webAppRoot, BasicAuthCredential credential, Context context, WebSiteConfigurationType webSiteConfigType, Origin origin)
  </code></pre>
  
  <p>The next step I took was to make sure the QTAgent32 always runs with administrative privileges, along with visual studio.</p>
  
  <p>I am now at a loss and cannot think of anything else to try, so do hope someone can at least point me in some direction.</p>
  
  <p>Thanks</p>