2
votes

I am writing XUnit test case. I am getting following error

Error CS1061 'HttpStatusCode' does not contain a definition for 'Should' and no accessible extension method 'Should' accepting a first argument of type 'HttpStatusCode' could be found (are you missing a using directive or an assembly reference?)

What does the error say and how to solve it. Please any one try to help me.

Thank you..

1
Share us the code what you used. - Edward

1 Answers

5
votes

For Should, there is no built-in Should to achieve the similiar function Assert.Equal(HttpStatusCode.OK, defaultPage.StatusCode);.

You could try shouldly to simplify the Assert.Equal.

  • Install-Package Shouldly
  • Referer by using Shouldly;
  • Useage

        public async Task Test()
    {
        var server = new TestServer(WebHost.CreateDefaultBuilder()
            .UseStartup<TestStartup>()
            );
        var response = await server.CreateClient().GetAsync(@"/test");
        response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
    
        var result = await response.Content.ReadAsStringAsync();
    
    }