Я пытаюсь вызвать метод в webapiController (ядро .net) из моего теста
Если у моего объекта запроса есть Id в виде строки, он не работает, как int это делает
Что я делаю не так в моем тестовом образце?
[Fact]
public async Task WhyDoesNotWorkWithIdAsString()
{
string thisQueryDoesNotWork = "http://localhost:1111/api/v1/shop/customers?id=1";
string thisQueryWorksProvidedTheIdIsAnInt = "http://localhost:1111/api/v1/shop/customers/1";
var response = await client.GetAsync(thisQueryDoesNotWork);
var response2 = await client.GetAsync(thisQueryWorksProvidedTheIdIsAnInt);
//omitted asserts
}
[Route("api/[controller]")]
public class ShopController: Controller
{
[HttpGet]
[Route("{id}",Name ="GetCustomerAsync")]
[ProducesResponseType(typeof(GetCustomerResponse), (int)HttpStatusCode.OK)]
//more ProducesResponseType omitted
public async Task<IActionResult> GetCustomerAsync([FromQuery]GetCustomerRequest request)
{
//code omitted
}
}
public class GetCustomerRequest
{
Required]
public string Id { get; set; }
// public int Id { get; set; } //works with int but not with a string
}
}
Также ниже правильно
[FromQuery] = использовать Получить только
[FromBody] = использовать Put-Post
есть ли ссылка с объяснением, когда использовать этот параметр привязки?
большое спасибо