FileSqlServerSync/Server/ServerTest/PipeTest.cs
zerlei bfdda810d1 fix: 单元测试完成~快搞完了
1. RemoteSyncServer 的 StateHelper 改为私有
2. 修改删除的文件做一个备份
3. 更加详细的测试,主要是观察文件对比是否成功
4. websocket 正式测试
2024-10-12 22:01:48 +08:00

67 lines
1.9 KiB
C#

using System.Text.Json;
using Common;
using LocalServer;
using RemoteServer;
using XUnit.Project.Attributes;
/*using Newtonsoft.Json;*/
namespace ServerTest;
public class PipeTest
{
[Fact]
public async void TestCase()
{
var p1 = new TestPipe(false, "1");
var x = Task.Run(async () =>
{
var rs = p1.Work(
(byte[] b) =>
{
var msg = JsonSerializer.Deserialize<SyncMsg>(b);
if (msg.Body == "发布完成!")
{
p1.Close("正常退出!");
}
Console.WriteLine(b);
return true;
}
);
await foreach (var r in rs)
{
Console.WriteLine(r);
}
});
//await p1.Close("sdf");
//await x;
var p2 = new TestPipe(false, "2");
p1.Other = p2;
p2.Other = p1;
var p3 = new TestPipe(true, "3");
var p4 = new TestPipe(true, "4");
p3.Other = p4;
p4.Other = p3;
LocalSyncServer.TempRootFile = "D:/FileSyncTest/stemp";
RemoteSyncServer.TempRootFile = "D:/FileSyncTest/dtemp";
RemoteSyncServerFactory.NamePwd = [new Tuple<string, string>("Test", "t123")];
var lf = new LocalSyncServerFactory();
lf.CreateLocalSyncServer(p2, "Test", p3);
var rf = new RemoteSyncServerFactory();
rf.CreateRemoteSyncServer(p4, "Test");
TestPipe.syncServerFactory = rf;
var starter = new SyncMsg
{
Body = JsonSerializer.Serialize(new PipeSeed().TestConfig),
Type = SyncMsgType.General,
Step = SyncProcessStep.Connect
};
await p1.SendMsg(starter);
await x;
if (p1.ErrResult != "正常退出!")
{
Assert.Fail(p1.ErrResult);
}
}
}