升级到.Net Core 2.2后获得405 MethodNotAllowed

时间:2019-11-27 07:16:27

标签: .net-core .net-core-2.2

  • ASP.Net Core 2.2
  • Visual Studio 2019专业版

将.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);

0 个答案:

没有答案