我想不通为什么这个异常被抛出...... 我有一个单元测试:序列包含多个元素的NancyBootstrapperBase类
[Test]
public void Should_return_status_ok_when_route_exists()
{
// Given
var bootstrapper = new DefaultNancyBootstrapper();
var browser = new Browser(bootstrapper);
// When
var result = browser.Get("/", with =>
{
with.HttpRequest();
});
// Then
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}
虽然浏览器变量被分配,除了在扔与后续堆栈跟踪南希引导程序的基类
System.InvalidOperationException:序列包含多个元素
at System.Linq.Enumerable.SingleOrDefault(IEnumerable`1 source)
at Nancy.Bootstrapper.NancyBootstrapperBase`1.GetRootPathProvider() in NancyBootstrapperBase.cs: line 558
at Nancy.Bootstrapper.NancyBootstrapperBase`1.get_RootPathProvider() in NancyBootstrapperBase.cs: line 172
at Nancy.Bootstrapper.NancyBootstrapperBase`1.GetAdditionalInstances() in NancyBootstrapperBase.cs: line 514
at Nancy.Bootstrapper.NancyBootstrapperBase`1.Initialise() in NancyBootstrapperBase.cs: line 242
at Nancy.Testing.Browser..ctor(INancyBootstrapper bootstrapper) in Browser.cs: line 39
at Tests.Tests.Should_return_status_ok_when_route_exists() in Tests.cs: line 34
您是否正在运行您应用程序所在的项目中的Nancy.Testing?如果不是,那么你是否参考了也引用Nancy.Testing的项目中的主机程序集(Nancy.Hosting.xxxx)? – TheCodeJunkie 2013-02-28 17:51:46
我没有跑Nancy.Testing。我应该这样做吗?我只是添加了Nancy,Nancy.Authentication.Forms,Nancy.Testing对我的测试项目的引用,并运行我在VS中使用Resharper编写的测试。这是不正确的? – 2013-03-01 09:55:07
如果您只在运行测试时引用了Nancy,Nancy.Authentication.Forms和Nancy.Testing并且遇到了这个问题,那么我们需要了解有关您的项目设置的更多信息,以了解它发生的原因。代码是否可用? – TheCodeJunkie 2013-03-01 10:49:00