将.Net Core从2.1升级到2.2后,对控制器运行集成测试
当运行控制器上不存在的URL测试用例时,我得到405 MethodNotAllowed。
我希望获得状态代码404(与升级到2.2之前一样),但得到405 MethodNotAllowed。
控制器:
[Authorize]
[Authorize(Policy = Constants.APIPolicies.OrgId)]
[ResponseCache(Location = ResponseCacheLocation.None, NoStore = true, Duration = 0)]
[Route("api/patient")]
[Produces("application/json")]
public class PatientController : Controller {
...
...
[Audit(Constants.AuditParameters.PatientUidRoot)]
[HttpPost("v1/{" + Constants.RouteParams.orgId + "}/ResolvePatientId")]
public async Task<IActionResult> GetPatientIdByUID([FromRoute] Guid orgId, [FromBody] UidModel patientUid)
{
...
}
...
...
}
测试:
patientUid = new UID(validRoot, validExtension);
response = await _mApiHostFixture.Client.PostAsync(string.Format("/api/patient/v1/{0}/ResolvePatientIdxx", orgId), new JsonContent(patientUid));
response.StatusCode.Should().Be(HttpStatusCode.NotFound);