Nancy unit test does not work when requesting static content

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

I added the 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 method ConfigureConventionsin Bootstrapper.

unit test is as follows:

[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);
}

In reality, when deployed, this code works just fine, it's just a test that doesn't work.

+4
source share
1 answer

Most likely, the robots.txt file is not copied to the output of the assembly of your test assembly. Make sure he is.

+2
source

All Articles