diff --git a/Netch.sln b/Netch.sln
index da67cd3c..2dab10d5 100644
--- a/Netch.sln
+++ b/Netch.sln
@@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Netch", "Netch\Netch.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SearchComboBox", "SearchComboBox\SearchComboBox.csproj", "{A8715AF4-ACC6-43F9-9381-4294C5360623}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", "{53397641-35CA-4336-8E22-2CE12EF476AC}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTest", "UnitTest\UnitTest.csproj", "{53397641-35CA-4336-8E22-2CE12EF476AC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/Netch/Global.cs b/Netch/Global.cs
index 91265315..03bdde50 100644
--- a/Netch/Global.cs
+++ b/Netch/Global.cs
@@ -34,6 +34,12 @@ namespace Netch
public static readonly Mutex Mutex = new(false, "Global\\Netch");
+#if DEBUG
+ public static bool Testing = false;
+#else
+ public const bool Testing = false;
+#endif
+
///
/// 用于读取和写入的配置
///
diff --git a/Netch/Utils/Logging.cs b/Netch/Utils/Logging.cs
index fa17a1fa..11c95335 100644
--- a/Netch/Utils/Logging.cs
+++ b/Netch/Utils/Logging.cs
@@ -39,8 +39,15 @@ namespace Netch.Utils
private static void Write(string text, LogLevel logLevel)
{
+ var contents = $@"[{DateTime.Now}][{logLevel.ToString()}] {text}{Global.EOF}";
+ if (Global.Testing)
+ {
+ Console.WriteLine(contents);
+ return;
+ }
+
lock (FileLock)
- File.AppendAllText(LogFile, $@"[{DateTime.Now}][{logLevel.ToString()}] {text}{Global.EOF}");
+ File.AppendAllText(LogFile, contents);
}
}
}
\ No newline at end of file
diff --git a/Test/Test.csproj b/Test/Test.csproj
deleted file mode 100644
index ed276b79..00000000
--- a/Test/Test.csproj
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
- net48
- x64
- true
- latest
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Test/Tests.cs b/Test/Tests.cs
deleted file mode 100644
index b4f2fb29..00000000
--- a/Test/Tests.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-using System.Linq;
-using System.Windows.Forms;
-using Netch.Servers.ShadowsocksR;
-using Netch.Servers.VLESS;
-using Netch.Servers.VMess;
-using Netch.Servers.VMess.Form;
-using Netch.Utils;
-using NUnit.Framework;
-
-namespace Test
-{
- [TestFixture]
- public class Tests
- {
- [Test]
- public void TestServerForm()
- {
- i18N.Load("zh-CN");
-
- var server = ParseVMessUri();
-
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new VMessForm(server));
- }
-
- private static ShadowsocksR ParseSSRUri()
- {
- return (ShadowsocksR) new SSRUtil().ParseUri(@"ssr://MTI3LjAuMC4xOjEyMzQ6YXV0aF9hZXMxMjhfbWQ1OmFlcy0xMjgtY2ZiOnRsczEuMl90aWNrZXRfYXV0aDpZV0ZoWW1KaS8_b2Jmc3BhcmFtPVluSmxZV3QzWVRFeExtMXZaUSZyZW1hcmtzPTVyV0w2Sy1WNUxpdDVwYUg").First();
- }
-
- private static VMess ParseVMessUri()
- {
- /*
-{
-"v": "2",
-"ps": "备注别名",
-"add": "111.111.111.111",
-"port": "32000",
-"id": "1386f85e-657b-4d6e-9d56-78badb75e1fd",
-"aid": "100",
-"net": "tcp",
-"type": "none",
-"host": "www.bbb.com",
-"path": "/",
-"tls": "tls"
-}
- */
- return (VMess) new VMessUtil().ParseUri(@"vmess://eyAidiI6ICIyIiwgInBzIjogIuWkh+azqOWIq+WQjSIsICJhZGQiOiAiMTExLjExMS4xMTEuMTExIiwgInBvcnQiOiAiMzIwMDAiLCAiaWQiOiAiMTM4NmY4NWUtNjU3Yi00ZDZlLTlkNTYtNzhiYWRiNzVlMWZkIiwgImFpZCI6ICIxMDAiLCAibmV0IjogInRjcCIsICJ0eXBlIjogIm5vbmUiLCAiaG9zdCI6ICJ3d3cuYmJiLmNvbSIsICJwYXRoIjogIi8iLCAidGxzIjogInRscyIgfQ==").First();
- }
-
- [Test]
- public void ParseVLESSUri()
- {
- var server = new VLESSUtil().ParseUri(@"vless://399ce595-894d-4d40-add1-7d87f1a3bd10@qv2ray.net:41971?type=kcp&headerType=wireguard&seed=69f04be3-d64e-45a3-8550-af3172c63055#VLESSmKCPSeedWG").First();
- }
- }
-}
\ No newline at end of file
diff --git a/Test/.gitignore b/UnitTest/.gitignore
similarity index 100%
rename from Test/.gitignore
rename to UnitTest/.gitignore
diff --git a/UnitTest/FunctionTest.cs b/UnitTest/FunctionTest.cs
new file mode 100644
index 00000000..6af4d717
--- /dev/null
+++ b/UnitTest/FunctionTest.cs
@@ -0,0 +1,32 @@
+using System;
+using System.IO;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Netch.Utils;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class FunctionTest : TestBase
+ {
+ [TestMethod]
+ public void TestLoadI18N()
+ {
+ void TestLoad(string t)
+ {
+ Console.WriteLine($"Load: {t}");
+ i18N.Load(t);
+ Console.WriteLine($"Result: {i18N.LangCode}\n");
+ }
+
+ Directory.CreateDirectory("logging");
+ TestLoad("System");
+ TestLoad("en-US");
+ TestLoad("zh-CN");
+ TestLoad("zh-HK");
+ TestLoad("zh");
+ TestLoad("HND123&*$_-^$@SAUI");
+ TestLoad("");
+ TestLoad("-");
+ }
+ }
+}
\ No newline at end of file
diff --git a/UnitTest/ParseShareLinkTest.cs b/UnitTest/ParseShareLinkTest.cs
new file mode 100644
index 00000000..49f06b39
--- /dev/null
+++ b/UnitTest/ParseShareLinkTest.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Linq;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Netch.Servers.ShadowsocksR;
+using Netch.Servers.VLESS;
+using Netch.Servers.VMess;
+
+namespace UnitTest
+{
+ [TestClass]
+ public class TestParseShareLink : TestBase
+ {
+ [TestMethod]
+ public void ParseSSR()
+ {
+ var server = (ShadowsocksR) new SSRUtil()
+ .ParseUri(
+ @"ssr://MTI3LjAuMC4xOjEyMzQ6YXV0aF9hZXMxMjhfbWQ1OmFlcy0xMjgtY2ZiOnRsczEuMl90aWNrZXRfYXV0aDpZV0ZoWW1KaS8_b2Jmc3BhcmFtPVluSmxZV3QzWVRFeExtMXZaUSZyZW1hcmtzPTVyV0w2Sy1WNUxpdDVwYUg")
+ .First();
+
+ if (server == null)
+ Assert.Fail();
+
+ Console.WriteLine(JsonSerializerFormatted(server));
+ }
+
+ [TestMethod]
+ public void ParseV2RayNFormatUri()
+ {
+ /*
+{
+"v": "2",
+"ps": "备注别名",
+"add": "111.111.111.111",
+"port": "32000",
+"id": "1386f85e-657b-4d6e-9d56-78badb75e1fd",
+"aid": "100",
+"net": "tcp",
+"type": "none",
+"host": "www.bbb.com",
+"path": "/",
+"tls": "tls"
+}
+ */
+ var server = (VMess) new VMessUtil().ParseUri(
+ @"vmess://eyAidiI6ICIyIiwgInBzIjogIuWkh+azqOWIq+WQjSIsICJhZGQiOiAiMTExLjExMS4xMTEuMTExIiwgInBvcnQiOiAiMzIwMDAiLCAiaWQiOiAiMTM4NmY4NWUtNjU3Yi00ZDZlLTlkNTYtNzhiYWRiNzVlMWZkIiwgImFpZCI6ICIxMDAiLCAibmV0IjogInRjcCIsICJ0eXBlIjogIm5vbmUiLCAiaG9zdCI6ICJ3d3cuYmJiLmNvbSIsICJwYXRoIjogIi8iLCAidGxzIjogInRscyIgfQ==")
+ .First();
+
+ if (server == null)
+ Assert.Fail();
+
+ Console.WriteLine(JsonSerializerFormatted(server));
+ }
+
+ [TestMethod]
+ public void ParseVLESSUri()
+ {
+ var server = new VLESSUtil()
+ .ParseUri(
+ @"vless://399ce595-894d-4d40-add1-7d87f1a3bd10@qv2ray.net:41971?type=kcp&headerType=wireguard&seed=69f04be3-d64e-45a3-8550-af3172c63055#VLESSmKCPSeedWG")
+ .First();
+
+ if (server == null)
+ Assert.Fail();
+
+ Console.WriteLine(JsonSerializerFormatted(server));
+ }
+ }
+}
\ No newline at end of file
diff --git a/UnitTest/TestBase.cs b/UnitTest/TestBase.cs
new file mode 100644
index 00000000..d0a34405
--- /dev/null
+++ b/UnitTest/TestBase.cs
@@ -0,0 +1,26 @@
+using Netch;
+using Newtonsoft.Json;
+
+namespace UnitTest
+{
+ public class TestBase
+ {
+ private readonly JsonSerializerSettings _serializerSettings = new()
+ {
+ Formatting = Formatting.Indented,
+ NullValueHandling = NullValueHandling.Ignore
+ };
+
+ protected TestBase()
+ {
+#if DEBUG
+ Global.Testing = true;
+#endif
+ }
+
+ protected string JsonSerializerFormatted(object o)
+ {
+ return JsonConvert.SerializeObject(o, _serializerSettings);
+ }
+ }
+}
\ No newline at end of file
diff --git a/UnitTest/Tests.cs b/UnitTest/Tests.cs
new file mode 100644
index 00000000..f9319540
--- /dev/null
+++ b/UnitTest/Tests.cs
@@ -0,0 +1,18 @@
+using System.Windows.Forms;
+using Netch.Servers.VMess.Form;
+using Netch.Utils;
+
+namespace UnitTest
+{
+ public class Tests : TestBase
+ {
+ public static void TestServerForm()
+ {
+ i18N.Load("zh-CN");
+
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Application.Run(new VMessForm());
+ }
+ }
+}
\ No newline at end of file
diff --git a/UnitTest/UnitTest.csproj b/UnitTest/UnitTest.csproj
new file mode 100644
index 00000000..de79d4e1
--- /dev/null
+++ b/UnitTest/UnitTest.csproj
@@ -0,0 +1,30 @@
+
+
+
+ net48
+ x64
+ true
+ latest
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+