I have a Nancy based web project and a unit test project using MSTest referencing the web project.

I have added a robots.txt file to the Content folder in the web project. I added a static content path to it using nancyConventions.StaticContentsConventions.AddFile("/robots.txt", "/Content/robots.txt"); in the ConfigureConventions method in Bootstrapper.

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. Make sure it is there.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top