forked from ddrilling/AsbCloudServer
Add MockController to mock http-400
This commit is contained in:
parent
0e3a0d90cc
commit
4e58841619
@ -33,8 +33,11 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[HttpGet("Current")]
|
[HttpGet("Current")]
|
||||||
public IActionResult GetCurrent()
|
public IActionResult GetCurrent()
|
||||||
{
|
{
|
||||||
var result = (BackgroundWorkDto?)backgroundWorker.CurrentWork;
|
var work = backgroundWorker.CurrentWork;
|
||||||
return Ok(result);
|
if (work == null)
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
|
return Ok(work);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("Failed")]
|
[HttpGet("Failed")]
|
||||||
|
42
AsbCloudWebApi/Controllers/Mock.cs
Normal file
42
AsbCloudWebApi/Controllers/Mock.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class MockController : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// получить статистику
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("400")]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
|
public IActionResult Get([FromQuery, Required]IDictionary<string, string> args)
|
||||||
|
{
|
||||||
|
var errors = new Dictionary<string, string[]>();
|
||||||
|
|
||||||
|
foreach (var arg in args)
|
||||||
|
{
|
||||||
|
var countOfErrors = ((arg.Key + arg.Value).Length % 3) + 1;
|
||||||
|
var errorsText = Enumerable.Range(0, countOfErrors)
|
||||||
|
.Select(i => $"{arg.Value} не соответствует критериям проверки № {i}");
|
||||||
|
|
||||||
|
errors.Add(arg.Key, errorsText.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors.Any())
|
||||||
|
{
|
||||||
|
var problem = new ValidationProblemDetails(errors);
|
||||||
|
return BadRequest(problem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var problem = new ValidationProblemDetails { Detail = "at least one argument must be provided" };
|
||||||
|
return BadRequest(problem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user