fix: 单元测试完成~快搞完了
1. RemoteSyncServer 的 StateHelper 改为私有 2. 修改删除的文件做一个备份 3. 更加详细的测试,主要是观察文件对比是否成功 4. websocket 正式测试
This commit is contained in:
parent
ffda80aa01
commit
bfdda810d1
5 changed files with 54 additions and 23 deletions
|
@ -7,7 +7,17 @@ public class LocalSyncServer
|
||||||
#pragma warning disable CA2211 // Non-constant fields should not be visible
|
#pragma warning disable CA2211 // Non-constant fields should not be visible
|
||||||
public static string TempRootFile = "C:/TempPack";
|
public static string TempRootFile = "C:/TempPack";
|
||||||
#pragma warning restore CA2211 // Non-constant fields should not be visible
|
#pragma warning restore CA2211 // Non-constant fields should not be visible
|
||||||
public StateHelpBase StateHelper;
|
private StateHelpBase StateHelper;
|
||||||
|
|
||||||
|
public void SetStateHelper(StateHelpBase helper)
|
||||||
|
{
|
||||||
|
StateHelper = helper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StateHelpBase GetStateHelper()
|
||||||
|
{
|
||||||
|
return StateHelper;
|
||||||
|
}
|
||||||
|
|
||||||
public Config? SyncConfig;
|
public Config? SyncConfig;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ public abstract class StateHelpBase(
|
||||||
{
|
{
|
||||||
protected readonly LocalSyncServer Context = context;
|
protected readonly LocalSyncServer Context = context;
|
||||||
|
|
||||||
protected readonly SyncProcessStep Step = step;
|
public readonly SyncProcessStep Step = step;
|
||||||
|
|
||||||
public SyncMsg CreateErrMsg(string Body)
|
public SyncMsg CreateErrMsg(string Body)
|
||||||
{
|
{
|
||||||
|
@ -91,7 +91,7 @@ public class ConnectAuthorityHelper(LocalSyncServer context)
|
||||||
Context.LocalPipe.SendMsg(msg);
|
Context.LocalPipe.SendMsg(msg);
|
||||||
//下一步
|
//下一步
|
||||||
var deployHelper = new DeployHelper(Context);
|
var deployHelper = new DeployHelper(Context);
|
||||||
Context.StateHelper = deployHelper;
|
Context.SetStateHelper(deployHelper);
|
||||||
deployHelper.DeployProcess();
|
deployHelper.DeployProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ public class ConnectAuthorityHelper(LocalSyncServer context)
|
||||||
var rs = Context.RemotePipe.Work(
|
var rs = Context.RemotePipe.Work(
|
||||||
(byte[] b) =>
|
(byte[] b) =>
|
||||||
{
|
{
|
||||||
return Context.StateHelper.ReceiveRemoteMsg(b);
|
var x = Context.GetStateHelper().Step;
|
||||||
|
return Context.GetStateHelper().ReceiveRemoteMsg(b);
|
||||||
},
|
},
|
||||||
Context.NotNullSyncConfig.RemoteUrl + "/websoc?Name=" + Context.Name
|
Context.NotNullSyncConfig.RemoteUrl + "/websoc?Name=" + Context.Name
|
||||||
);
|
);
|
||||||
|
@ -142,7 +143,7 @@ public class DeployHelper(LocalSyncServer context)
|
||||||
{
|
{
|
||||||
Context.LocalPipe.SendMsg(CreateMsg("配置为不发布跳过此步骤")).Wait();
|
Context.LocalPipe.SendMsg(CreateMsg("配置为不发布跳过此步骤")).Wait();
|
||||||
var h = new DiffFileAndPackHelper(Context);
|
var h = new DiffFileAndPackHelper(Context);
|
||||||
Context.StateHelper = h;
|
Context.SetStateHelper(h);
|
||||||
h.DiffProcess();
|
h.DiffProcess();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -152,7 +153,7 @@ public class DeployHelper(LocalSyncServer context)
|
||||||
ProcessStartInfo startInfo =
|
ProcessStartInfo startInfo =
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
FileName = "msdeploy", // The command to execute (can be any command line tool)
|
FileName = "C:\\Program Files\\IIS\\Microsoft Web Deploy V3\\msdeploy.exe", // The command to execute (can be any command line tool)
|
||||||
Arguments =
|
Arguments =
|
||||||
$" -verb:sync -source:contentPath={Context.NotNullSyncConfig.LocalProjectAbsolutePath} -dest:contentPath={Context.NotNullSyncConfig.LocalRootPath} -disablerule:BackupRule",
|
$" -verb:sync -source:contentPath={Context.NotNullSyncConfig.LocalProjectAbsolutePath} -dest:contentPath={Context.NotNullSyncConfig.LocalRootPath} -disablerule:BackupRule",
|
||||||
// The arguments to pass to the command (e.g., list directory contents)
|
// The arguments to pass to the command (e.g., list directory contents)
|
||||||
|
@ -172,9 +173,9 @@ public class DeployHelper(LocalSyncServer context)
|
||||||
|
|
||||||
if (process.ExitCode == 0)
|
if (process.ExitCode == 0)
|
||||||
{
|
{
|
||||||
Context.LocalPipe.SendMsg(CreateMsg("发布成功!")).Wait();
|
Context.LocalPipe.SendMsg(CreateMsg("本地编译成功!")).Wait();
|
||||||
var h = new DiffFileAndPackHelper(Context);
|
var h = new DiffFileAndPackHelper(Context);
|
||||||
Context.StateHelper = h;
|
Context.SetStateHelper(h);
|
||||||
h.DiffProcess();
|
h.DiffProcess();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -248,8 +249,8 @@ public class DiffFileAndPackHelper(LocalSyncServer context)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var n = new DeployMSSqlHelper(Context);
|
var n = new DeployMSSqlHelper(Context);
|
||||||
|
Context.SetStateHelper(n);
|
||||||
n.PackSqlServerProcess();
|
n.PackSqlServerProcess();
|
||||||
Context.StateHelper = n;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +264,7 @@ public class DeployMSSqlHelper(LocalSyncServer context)
|
||||||
Context.NotNullSyncConfig.Id.ToString()
|
Context.NotNullSyncConfig.Id.ToString()
|
||||||
);
|
);
|
||||||
var h = new UploadPackedHelper(Context);
|
var h = new UploadPackedHelper(Context);
|
||||||
Context.StateHelper = h;
|
Context.SetStateHelper(h);
|
||||||
h.UpLoadPackedFile();
|
h.UpLoadPackedFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +298,7 @@ public class DeployMSSqlHelper(LocalSyncServer context)
|
||||||
ProcessStartInfo startInfo =
|
ProcessStartInfo startInfo =
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
FileName = "SqlPackage", // The command to execute (can be any command line tool)
|
FileName = "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe", // The command to execute (can be any command line tool)
|
||||||
Arguments = arguments,
|
Arguments = arguments,
|
||||||
// The arguments to pass to the command (e.g., list directory contents)
|
// The arguments to pass to the command (e.g., list directory contents)
|
||||||
RedirectStandardOutput = true, // Redirect the standard output to a string
|
RedirectStandardOutput = true, // Redirect the standard output to a string
|
||||||
|
@ -359,6 +360,8 @@ public class UploadPackedHelper(LocalSyncServer context)
|
||||||
)
|
)
|
||||||
.Wait();
|
.Wait();
|
||||||
Context.LocalPipe.SendMsg(CreateMsg("上传完成!")).Wait();
|
Context.LocalPipe.SendMsg(CreateMsg("上传完成!")).Wait();
|
||||||
|
|
||||||
|
var x = Context.GetStateHelper().Step;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void HandleLocalMsg(SyncMsg msg)
|
protected override void HandleLocalMsg(SyncMsg msg)
|
||||||
|
@ -370,7 +373,7 @@ public class UploadPackedHelper(LocalSyncServer context)
|
||||||
{
|
{
|
||||||
Context.LocalPipe.SendMsg(msg).Wait();
|
Context.LocalPipe.SendMsg(msg).Wait();
|
||||||
var h = new FinallyPublishHelper(Context);
|
var h = new FinallyPublishHelper(Context);
|
||||||
Context.StateHelper = h;
|
Context.SetStateHelper(h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ public class UnPackAndReleaseHelper(RemoteSyncServer context)
|
||||||
public void UnPack()
|
public void UnPack()
|
||||||
{
|
{
|
||||||
FileDirOpForUnpack.FirstUnComparess(
|
FileDirOpForUnpack.FirstUnComparess(
|
||||||
Path.Combine(RemoteSyncServer.TempRootFile, Context.NotNullSyncConfig.Id.ToString()),
|
Path.Combine(RemoteSyncServer.TempRootFile),
|
||||||
Context.NotNullSyncConfig.Id.ToString()
|
Context.NotNullSyncConfig.Id.ToString()
|
||||||
);
|
);
|
||||||
Context.Pipe.SendMsg(CreateMsg("解压完成!")).Wait();
|
Context.Pipe.SendMsg(CreateMsg("解压完成!")).Wait();
|
||||||
|
@ -149,14 +149,14 @@ public class FinallyPublishHelper(RemoteSyncServer context)
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
var arguments =
|
var arguments =
|
||||||
$" /Action:Publish /SourceFile: {RemoteSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.dacpac"
|
$" /Action:Publish /SourceFile:{RemoteSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.dacpac"
|
||||||
+ $" /TargetServerName:{Context.NotNullSyncConfig.DstDb.ServerName} /TargetDatabaseName:{Context.NotNullSyncConfig.DstDb.DatebaseName}"
|
+ $" /TargetServerName:{Context.NotNullSyncConfig.DstDb.ServerName} /TargetDatabaseName:{Context.NotNullSyncConfig.DstDb.DatebaseName}"
|
||||||
+ $" /TargetUser:{Context.NotNullSyncConfig.DstDb.User} /TargetPassword:{Context.NotNullSyncConfig.DstDb.Password} /TargetTrustServerCertificate:True";
|
+ $" /TargetUser:{Context.NotNullSyncConfig.DstDb.User} /TargetPassword:{Context.NotNullSyncConfig.DstDb.Password} /TargetTrustServerCertificate:True";
|
||||||
|
|
||||||
ProcessStartInfo startInfo =
|
ProcessStartInfo startInfo =
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
FileName = "SqlPackage", // The command to execute (can be any command line tool)
|
FileName = "C:\\Users\\ZHAOLEI\\.dotnet\\tools\\sqlpackage.exe", // The command to execute (can be any command line tool)
|
||||||
Arguments = arguments,
|
Arguments = arguments,
|
||||||
// The arguments to pass to the command (e.g., list directory contents)
|
// The arguments to pass to the command (e.g., list directory contents)
|
||||||
RedirectStandardOutput = true, // Redirect the standard output to a string
|
RedirectStandardOutput = true, // Redirect the standard output to a string
|
||||||
|
@ -193,11 +193,7 @@ public class FinallyPublishHelper(RemoteSyncServer context)
|
||||||
Context.Pipe.SendMsg(CreateMsg("跳过数据库发布!")).Wait();
|
Context.Pipe.SendMsg(CreateMsg("跳过数据库发布!")).Wait();
|
||||||
}
|
}
|
||||||
var DirFileOp = new FileDirOpForUnpack(
|
var DirFileOp = new FileDirOpForUnpack(
|
||||||
Path.Combine(
|
Path.Combine(RemoteSyncServer.TempRootFile, Context.NotNullSyncConfig.Id.ToString()),
|
||||||
RemoteSyncServer.TempRootFile,
|
|
||||||
Context.NotNullSyncConfig.Id.ToString(),
|
|
||||||
Context.NotNullSyncConfig.Id.ToString()
|
|
||||||
),
|
|
||||||
Context.NotNullSyncConfig.RemoteRootPath
|
Context.NotNullSyncConfig.RemoteRootPath
|
||||||
);
|
);
|
||||||
Context.NotNullSyncConfig.DirFileConfigs.ForEach(e =>
|
Context.NotNullSyncConfig.DirFileConfigs.ForEach(e =>
|
||||||
|
|
|
@ -19,6 +19,11 @@ public class PipeTest
|
||||||
var rs = p1.Work(
|
var rs = p1.Work(
|
||||||
(byte[] b) =>
|
(byte[] b) =>
|
||||||
{
|
{
|
||||||
|
var msg = JsonSerializer.Deserialize<SyncMsg>(b);
|
||||||
|
if (msg.Body == "发布完成!")
|
||||||
|
{
|
||||||
|
p1.Close("正常退出!");
|
||||||
|
}
|
||||||
Console.WriteLine(b);
|
Console.WriteLine(b);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +49,7 @@ public class PipeTest
|
||||||
lf.CreateLocalSyncServer(p2, "Test", p3);
|
lf.CreateLocalSyncServer(p2, "Test", p3);
|
||||||
var rf = new RemoteSyncServerFactory();
|
var rf = new RemoteSyncServerFactory();
|
||||||
rf.CreateRemoteSyncServer(p4, "Test");
|
rf.CreateRemoteSyncServer(p4, "Test");
|
||||||
|
TestPipe.syncServerFactory = rf;
|
||||||
var starter = new SyncMsg
|
var starter = new SyncMsg
|
||||||
{
|
{
|
||||||
Body = JsonSerializer.Serialize(new PipeSeed().TestConfig),
|
Body = JsonSerializer.Serialize(new PipeSeed().TestConfig),
|
||||||
|
@ -52,7 +58,7 @@ public class PipeTest
|
||||||
};
|
};
|
||||||
await p1.SendMsg(starter);
|
await p1.SendMsg(starter);
|
||||||
await x;
|
await x;
|
||||||
if (p1.ErrResult != null)
|
if (p1.ErrResult != "正常退出!")
|
||||||
{
|
{
|
||||||
Assert.Fail(p1.ErrResult);
|
Assert.Fail(p1.ErrResult);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Common;
|
using Common;
|
||||||
|
using Microsoft.AspNetCore.Hosting.Server;
|
||||||
using RemoteServer;
|
using RemoteServer;
|
||||||
|
|
||||||
namespace ServerTest
|
namespace ServerTest
|
||||||
|
@ -14,6 +15,7 @@ namespace ServerTest
|
||||||
public TestPipe? Other;
|
public TestPipe? Other;
|
||||||
public string? ErrResult;
|
public string? ErrResult;
|
||||||
public string Id = id;
|
public string Id = id;
|
||||||
|
public static RemoteSyncServerFactory syncServerFactory;
|
||||||
|
|
||||||
public override async IAsyncEnumerable<int> Work(
|
public override async IAsyncEnumerable<int> Work(
|
||||||
Func<byte[], bool> receiveCb,
|
Func<byte[], bool> receiveCb,
|
||||||
|
@ -34,12 +36,19 @@ namespace ServerTest
|
||||||
dst = Path.Combine(RemoteSyncServer.TempRootFile, Path.GetFileName(filePath));
|
dst = Path.Combine(RemoteSyncServer.TempRootFile, Path.GetFileName(filePath));
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
System.IO.File.Copy(filePath, dst, true);
|
||||||
progressCb(100);
|
progressCb(100);
|
||||||
//if (!Directory.Exists(dst))
|
//if (!Directory.Exists(dst))
|
||||||
//{
|
//{
|
||||||
// Directory.CreateDirectory(dst);
|
// Directory.CreateDirectory(dst);
|
||||||
//}
|
//}
|
||||||
System.IO.File.Copy(filePath, dst, true);
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
var it = syncServerFactory.GetServerByName("Test");
|
||||||
|
var h = new UnPackAndReleaseHelper(it);
|
||||||
|
it.StateHelper = h;
|
||||||
|
h.UnPack();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +120,14 @@ namespace ServerTest
|
||||||
//var x = 1;
|
//var x = 1;
|
||||||
var id = Id;
|
var id = Id;
|
||||||
//抛出异常 从 p3 传递到 p2
|
//抛出异常 从 p3 传递到 p2
|
||||||
throw new Exception(ErrResult);
|
if (ErrResult == "正常退出!")
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(ErrResult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue