提问人:Kozel Czech 提问时间:11/8/2023 最后编辑:Kozel Czech 更新时间:11/8/2023 访问量:23
BadRequest 的 RestSharp 测试 - 在断言之前失败
RestSharp testing for a BadRequest - fail before Assertion
问:
我正在尝试学习 ReshSharp、NUnit 测试等等。当前尝试在 API 调用期间测试 BadRequest,当我向它发送无效数据时:
[Test, Order(1)]
[TestCase("registerTestFirstName", "registerTestLastName", "invalid-email", "registerTestPassword")]
[TestCase("registerTestFirstName", "registerTestLastName", "[email protected]", "short")]
[TestCase(null, "registerTestLastName", "[email protected]", "registerTestPassword")]
public void RegisterUserTest_ReturnsBadRequest(string firstName, string lastName, string email, string Password)
{
UserEntity userEntity = new UserEntity
{
FirstName = firstName,
LastName = lastName,
Email = email,
Password = Password
};
var request = new RestRequest($"{_url}register", Method.Post);
request.AddJsonBody(userEntity);
var response = _client.Post(request).StatusCode;
response.Should().Be(System.Net.HttpStatusCode.BadRequest);
}
我试图断言响应等于所需的状态代码,但在 BadRequest 上失败而不是允许它转发......var response = _client.Post(request).StatusCode
我尝试在网上搜索,但我没有任何运气。
注意:我故意为我的实体类发送无效数据以接收错误请求,但就像我说的那样,HttpClient.Post 不允许它通过,因为它是 BadRequest - 400,它失败了,而不是让它继续
答: 暂无答案
评论