using System.Diagnostics; using Microsoft.AspNetCore.Mvc; using WcsMain.ApiServe.ControllerFilter; namespace WcsMain.ApiServe.Controllers; /// /// 测试接口,用于测试接口是否通断 /// /// /// 构造函数,注入显示类 /// /// [ApiController] [Route("api/Test")] [ServiceFilter] public class TestController(ILogger logger) : ControllerBase { private readonly ILogger _logger = logger; /// /// Get测试 /// /// [HttpGet("GetTest")] public string GetTest() { _logger.LogInformation("正常"); return "正常"; } /// /// Get测试 /// /// [HttpGet("RestartTest")] public string RestartTest() { string? path = Process.GetCurrentProcess().MainModule?.FileName; Process process = new(); process.StartInfo.FileName = path; process.Start(); Process.GetCurrentProcess().Kill(); return "正常"; } /// /// Post测试 /// /// /// [HttpPost("PostTest")] public string PostTest([FromBody] string body) { return $"正常,收到的信息为:{body}"; } /// /// Post异常测试 /// /// /// [HttpPost("PostErrorTest")] public string PostErrorTest([FromBody] string body) { throw new Exception($"异常异常:{body}"); } }