我正在编写XUnit测试用例。我收到以下错误消息
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?)
该错误说明了什么以及如何解决。请任何一个尝试帮助我。
谢谢..
答案 0 :(得分:1)
对于Should
,没有内置Should
来实现类似功能Assert.Equal(HttpStatusCode.OK, defaultPage.StatusCode);
。
您可以尝试shouldly来简化Assert.Equal
。
using Shouldly;
推荐使用情况
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();
}