zerlei
78d9e68fea
原因是: 1. 相互独立的单元测试,有助于debug问题, 2. 不需要考虑执行顺序,额外的运行环境等,更加简单。 做的工作是: 1. 去掉了顺序执行,这有助于并发调用,减少测试时间 2. 去掉了测试方法中共享的实例
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System.Text;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace LocalServer.Controllers
|
|
{
|
|
public class LocalServerController(LocalSyncServerFactory factory) : ControllerBase
|
|
{
|
|
private readonly LocalSyncServerFactory Factory = factory;
|
|
|
|
[Route("/")]
|
|
public async Task WebsocketConnection(string Name)
|
|
{
|
|
if (HttpContext.WebSockets.IsWebSocketRequest)
|
|
{
|
|
try
|
|
{
|
|
var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
|
Factory.CreateLocalSyncServer(webSocket, Name);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
HttpContext.Response.Body = new MemoryStream(Encoding.UTF8.GetBytes(e.Message));
|
|
HttpContext.Response.StatusCode = StatusCodes.Status406NotAcceptable;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
|
|
}
|
|
}
|
|
//TODO 是否在本地记载同步日志?
|
|
}
|
|
}
|