找不到测试不起作用的原因。有人知道为什么会这样吗?这两个测试之间的区别仅在于视图。第一个是“.html”页面,第二个是“.liquid”。在我的项目中,我使用“.liquid”,因此“.html”仅用于测试正确的工作测试。我有一个南希模块
public sealed class Module : NancyModule
{
public Module(IBackend storage)
{
Get["/"] = _ => View["Create.liquid"];
Get["/Test"] = _ => View["TestHtml.html"];
}
}
和测试
[Test]
public void test_html()
{
// Given
var bootstrapper = new ConfigurableBootstrapper(with =>
{
var module = new Module(new Endpoint());
with.Module(module);
});
browser = new Browser(bootstrapper);
// When
var result = browser.Get("/Test", with =>
{
with.HttpRequest();
});
// Then
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}
[Test]
public void test_liquid()
{
// Given
var bootstrapper = new ConfigurableBootstrapper(with =>
{
var module = new Module(new Endpoint());
with.Module(module);
});
browser = new Browser(bootstrapper);
// When
var result = browser.Get("/", with =>
{
with.HttpRequest();
});
// Then
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}
第二次测试有异常
System.Exception : ConfigurableBootstrapper Exception
----> Nancy.RequestExecutionException : Oh noes!
----> Nancy.ViewEngines.ViewNotFoundException : Unable to locate view 'Create.liquid'
Currently available view engine extensions: sshtml,html,htm
Locations inspected: ,,,,,,,,views/Module/Create.liquid-en- US,views/Module/Create.liquid,Module/Create.liquid-en-US,Module/Create.liquid,views/Create.liquid-en-US,views/Create.liquid,Create.liquid-en-US,Create.liquid
Root path: D:\Projects\epm-vsp-pasta\Tests\bin\Debug
使用堆栈跟踪
at Nancy.Testing.PassThroughStatusCodeHandler.Handle(HttpStatusCode statusCode, NancyContext context) in d:\Nancy-master\src\Nancy.Testing\PassThroughStatusHandler.cs: line 22
at Nancy.NancyEngine.CheckStatusCodeHandler(NancyContext context) in d:\Nancy-master\src\Nancy\NancyEngine.cs: line 219
at Nancy.NancyEngine.HandleRequest(Request request, Func`2 preRequest) in d:\Nancy-master\src\Nancy\NancyEngine.cs: line 112
at Nancy.NancyEngine.HandleRequest(Request request) in d:\Nancy-master\src\Nancy\NancyEngine.cs: line 77
at Nancy.Testing.Browser.HandleRequest(String method, String path, Action`1 browserContext) in d:\Nancy-master\src\Nancy.Testing\Browser.cs: line 125
at Nancy.Testing.Browser.Get(String path, Action`1 browserContext) in d:\Nancy-master\src\Nancy.Testing\Browser.cs: line 62
at Tests.TestModule.test_liquid() in TestModule.cs: line 111 --RequestExecutionException
at Nancy.NancyEngine.InvokeOnErrorHook(NancyContext context, ErrorPipeline pipeline, Exception ex) in d:\Nancy-master\src\Nancy\NancyEngine.cs: line 272
--ViewNotFoundException