You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 19, 2024. It is now read-only.
Since MVC/WebAPI 5.2 there is an option to add single global route attribute to controller so all the actions in it will match:
[RoutePrefix("files"), Route("{container}/{id}")]
public class FilesController : ApiController
{
[HttpGet]
public async Task<IHttpActionResult> GetDescription(string container, string id)
{
return Ok();
}
[HttpDelete]
public async Task<IHttpActionResult> Delete(string container, string id)
{
return Ok();
}
}
This notation actually works flawlessly and all requests land as expected. But test fails:
[TestMethod]
public void GetDescription()
{
var expectations = new
{
controller = "Files",
action = "GetDescription",
container = "someContainer",
id = "someFile"
};
RouteAssert.HasApiRoute(_host.Config, "/files/someContainer/someFile", HttpMethod.Get, expectations);
}
with error: Expected 'someFile', got missing value for 'id' at url '/files/someContainer/someFile'.
Simply copying the route attribute from controller to method declaration makes it pass:
[HttpGet, Route("{container}/{id}")]
public async Task<IHttpActionResult> GetDescription(string container, string id)
Since MVC/WebAPI 5.2 there is an option to add single global route attribute to controller so all the actions in it will match:
This notation actually works flawlessly and all requests land as expected. But test fails:
with error:
Expected 'someFile', got missing value for 'id' at url '/files/someContainer/someFile'.Simply copying the route attribute from controller to method declaration makes it pass: