简体   繁体   English

请求静态内容时,Nancy单元测试不起作用

[英]Nancy unit test doesn't work when requesting static content

I have a Nancy based web project and a unit test project using MSTest referencing the web project. 我有一个基于Nancy的Web项目和一个使用MSTest引用Web项目的单元测试项目。

I have added a robots.txt file to the Content folder in the web project. 我已将robots.txt文件添加到Web项目的Content文件夹中。 I added a static content path to it using nancyConventions.StaticContentsConventions.AddFile("/robots.txt", "/Content/robots.txt"); 我使用nancyConventions.StaticContentsConventions.AddFile("/robots.txt", "/Content/robots.txt");为它添加了静态内容路径nancyConventions.StaticContentsConventions.AddFile("/robots.txt", "/Content/robots.txt"); in the ConfigureConventions method in Bootstrapper . Bootstrapper中的ConfigureConventions方法中。

The unit test looks like this: 单元测试如下所示:

[TestMethod]
public void Get_Robotstxt_Should_Return_Status_OK()
{
    // Given
    var browser = new Browser(new Bootstrapper());

    // When
    var result = browser.Get("/robots.txt");

    // Then
    Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
}

The code actually works fine when deployed, it is just the test that doesn't work. 代码实际上在部署时工作正常,只是测试不起作用。

Most probably the robots.txt file is not copied to the build output of your test assembly. 很可能robots.txt文件不会复制到测试程序集的构建输出中。 Make sure it is there. 确保它在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM