在Visual Studio和问题与QTAgent单元测试MVC Web应用程序 [英] Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
问题描述
我一直在试图运行在Visual Studio中的单元测试的MVC应用程序,不断得到以下错误:
中指定的URL(HTTP://本地主机:21496 /')不对应于一个
有效的目录。在配置ASP.NET在IIS中运行测试要求
有效的目录存在的URL。该网址可能无效或可
不是指向一个有效的Web应用程序。
块引用>的唯一建议解决办法是确保你在UrlToTest本地主机地址属性,像这样:
[TestMethod的()]
[HOSTTYPE(ASP.NET)]
[UrlToTest(HTTP://本地主机:21496 /)]
块引用>然而,这仍然没有针对IIS防爆preSS或IIS 7在Windows 7上运行,当我钻研事件日志,发现以下问题。
(QTAgent32.exe,PID 6976,线程15)WebSites.GetWebServer:无法创建AspNetHelper:Microsoft.VisualStudio.Enterprise.Common.AspNetHelperException:该网站的元数据库中包含意外的信息,或者您没有权限访问元数据库。您必须是本地计算机上的Administrators组来访问IIS元数据库中的一员。因此,您不能创建或打开本地IIS网站。如果你读,写和修改权限所在的文件所在的文件夹,可以创建文件系统网站,指向的文件夹才能继续进行。 ---> System.Runtime.InteropServices.COMException:未知的错误(0x80005000)
在System.DirectoryServices.DirectoryEntry.Bind(布尔throwIfFail)
在System.DirectoryServices.DirectoryEntry.Bind()
在System.DirectoryServices.DirectoryEntry.get_IsContainer()
在System.DirectoryServices.DirectoryEntries.ChildEnumerator..ctor(的DirectoryEntry容器)
在Microsoft.VisualStudio.Enterprise.Common.IISHelper.GetWebServerOrdinal(URI网站)
---内部异常堆栈跟踪的结尾---
在Microsoft.VisualStudio.Enterprise.Common.IISHelper.GetWebServerOrdinal(URI网站)
在Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_WebServerOrdinal()
在Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_RootPath()
在Microsoft.VisualStudio.Enterprise.Common.IISHelper.get_PhysicalPath()
在Microsoft.VisualStudio.Enterprise.Common.AspNetHelperMan..ctor(URI URI,BasicAuthCredential凭证的Int32 frameworkMajorVersion)
在Microsoft.VisualStudio.TestTools.HostAdapters.WebSites.GetWebServer(字符串webServerName,WebServerType webServerType,字符串urlToTest,字符串pathToWeb,字符串webAppRoot,BasicAuthCredential凭证,上下文的背景下,WebSiteConfigurationType webSiteConfigType,产地来源)接下来,我真是以确保QTAgent32始终具有管理权限运行,与Visual Studio一起。
我现在很茫然,不能想别的去尝试,所以不要希望有人能至少指向我的一些方向。
感谢
解决方案测试是在默认的ASP.NET环境中创建。为了测试控制器,但无需运行Web应用程序,您必须在测试方法之前删除下列属性。
[HOSTTYPE(ASP.NET)]
[UrlToTest(HTTP://本地主机:21496 /)]I have been attempting to run a Unit Test in visual studio for an MVC Application and continuously getting the following error:
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.
The only advice around is to make sure you have a localhost address in the UrlToTest attribute like so:
[TestMethod()] [HostType("ASP.NET")] [UrlToTest("http://localhost:21496/")]
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.
(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. ---> 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)
The next step I took was to make sure the QTAgent32 always runs with administrative privileges, along with visual studio.
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.
Thanks
解决方案The tests were created in a default ASP.NET environment. In order to test the controllers but without the need to run the web application, you must delete the following attributes before the test methods.
[HostType("ASP.NET")] [UrlToTest("http://localhost:21496/")]
这篇关于在Visual Studio和问题与QTAgent单元测试MVC Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!