XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension

【DLL】XFE各类拓展是一个C#的DLL库,旨在优化C#代码中常用语句的使用,并提供更简洁的访问方式,同时提供Xunit测试框架,快速搭建服务器/客户端,免费ChatGPTAPI接口,免费通讯服务器,XFE下载器,新增格式等

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEExtension

为XFEConsole提供对XUnit测试框架的支持

6ba13a0
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

5 个文件 +99 -15
Modified XFEExtension.NetCore.Test/Program.cs +22 -6
@@ -1,9 +1,25 @@
1 1 using XFEExtension.NetCore.Test;
2 using XFEExtension.NetCore.XFEConsole;
3 using XFEExtension.NetCore.XUnit;
2 4
3 var testClass = new TestClass("测试类", "测试描述:我上早八", 56)
5 internal class Program
4 6 {
5 Tags = [["标签11", "标签12"], ["标签21", "标签22"]]
6 };
7 Console.WriteLine(testClass);
8 Console.WriteLine("Program End");
9 Console.ReadLine();
7
8 private static async Task Main(string[] args)
9 {
10 await XFECode.RunTest();
11 }
12
13 [SMTest]
14 [UseXFEConsole]
15 public static async Task TestMethod()
16 {
17 var testClass = new TestClass("测试类", "测试描述:我上早八", 56)
18 {
19 Tags = [["标签11", "标签12"], ["标签21", "标签22"]]
20 };
21 Console.WriteLine(testClass);
22 Console.WriteLine("Program End");
23 Console.ReadLine();
24 }
25 }
Modified XFEExtension.NetCore.Test/TestClass.cs +1 -3
@@ -1,6 +1,4 @@
1 using System;
2
3 namespace XFEExtension.NetCore.Test;
1 namespace XFEExtension.NetCore.Test;
4 2
5 3 internal class TestClass(string name, string description, int age)
6 4 {
Modified XFEExtension.NetCore.Test/XFEExtension.NetCore.Test.csproj +4 -0
@@ -7,6 +7,10 @@
7 7 <Nullable>enable</Nullable>
8 8 </PropertyGroup>
9 9
10 <ItemGroup>
11 <PackageReference Include="XFEExtension.NetCore.XFEConsole" Version="1.0.3" />
12 </ItemGroup>
13
10 14 <ItemGroup>
11 15 <ProjectReference Include="..\XFEExtension.NetCore\XFEExtension.NetCore.csproj" />
12 16 </ItemGroup>
Modified XFEExtension.NetCore/XFEExtension.NetCore.csproj +3 -3
@@ -5,6 +5,7 @@
5 5 <ImplicitUsings>enable</ImplicitUsings>
6 6 <Nullable>enable</Nullable>
7 7 <GenerateDocumentationFile>True</GenerateDocumentationFile>
8 <Version>3.0.3</Version>
8 9 <Title>XFEExtension</Title>
9 10 <RepositoryUrl>https://github.com/XFEstudio/XFEExtension</RepositoryUrl>
10 11 <AnalysisLevel>latest</AnalysisLevel>
@@ -19,8 +20,7 @@
19 20 <PackageTags>XFE;拓展;GPT;Server;服务器;测试;XFEExtension</PackageTags>
20 21 <PackageReleaseNotes>## 调整
21 22
22 修复分析中的部分bug
23 为CyberComm添加终止服务器功能
23 为XFEConsole提供对XUnit测试框架的支持
24 24
25 25 ## 新增
26 26
@@ -33,7 +33,7 @@
33 33 <PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
34 34 <PackageLicenseFile>LICENSE</PackageLicenseFile>
35 35 <AssemblyOriginatorKeyFile>..\XFEstudio.pfx</AssemblyOriginatorKeyFile>
36 <Version>3.0.2</Version>
36 <Version>$(Version)</Version>
37 37 <Authors>XFEstudio</Authors>
38 38 </PropertyGroup>
39 39
Modified XFEExtension.NetCore/XFEExtension/XFECode.cs +69 -3
@@ -190,7 +190,21 @@ public abstract class XFECode
190 190 var isFirstStaticMethod = true;
191 191 foreach (var method in singleRunMethods)
192 192 {
193 var attributes = method.GetCustomAttributes(typeof(SMTestAttribute));
193 var attributes = method.GetCustomAttributes<SMTestAttribute>();
194 bool useXFEConsole = false;
195 int consolePort = 3280;
196 foreach (var customAttribute in method.CustomAttributes)
197 {
198 if (customAttribute is not null && customAttribute.AttributeType.Name == "UseXFEConsoleAttribute")
199 {
200 useXFEConsole = true;
201 foreach (var arg in customAttribute.ConstructorArguments)
202 {
203 if (arg.ArgumentType == typeof(int))
204 consolePort = (int)arg.Value!;
205 }
206 }
207 }
194 208 foreach (var likeAttribute in attributes)
195 209 {
196 210 if (likeAttribute is SMTestAttribute attribute)
@@ -274,6 +288,18 @@ public abstract class XFECode
274 288 object? result = null;
275 289 try
276 290 {
291 if (useXFEConsole)
292 {
293 if (Type.GetType("XFEExtension.NetCore.XFEConsole.XFEConsole, XFEExtension.NetCore.XFEConsole") is Type type)
294 {
295 if (type.GetMethod("UseXFEConsole", BindingFlags.Static | BindingFlags.Public, [typeof(int), typeof(string)]) is MethodInfo useXFEConsoleMethodInfo)
296 {
297 var connectSuccessful = await (Task<bool>)useXFEConsoleMethodInfo.Invoke(null, [consolePort, ""])!;
298 if (!connectSuccessful)
299 Console.WriteLine("XFE控制台连接失败!");
300 }
301 }
302 }
277 303 currentMethodIsAsserted = false;
278 304 if (method.ReturnType == typeof(Task))
279 305 {
@@ -383,11 +409,18 @@ public abstract class XFECode
383 409 Console.ResetColor();
384 410 Console.WriteLine("\n");
385 411 Console.WriteLine("\n");
412 if (useXFEConsole)
413 {
414 if (Type.GetType("XFEExtension.NetCore.XFEConsole.XFEConsole") is Type type && type.GetMethod("StopXFEConsole", BindingFlags.Static | BindingFlags.Public) is MethodInfo stopXFEConsoleMethodInfo)
415 {
416 await (Task)stopXFEConsoleMethodInfo.Invoke(null, null)!;
417 }
418 }
386 419 }
387 420 }
388 421 }
389 422 #endregion
390 var classAttributes = subClass.GetCustomAttributes(typeof(CTestAttribute));
423 var classAttributes = subClass.GetCustomAttributes<CTestAttribute>();
391 424 var classRunMethods = subClass.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).Where(m => m.IsDefined(typeof(MTestAttribute)));
392 425 foreach (var classAttribute in classAttributes.Cast<CTestAttribute>())
393 426 {
@@ -472,7 +505,21 @@ public abstract class XFECode
472 505 classTimeCounter.Start();
473 506 foreach (var method in classRunMethods)
474 507 {
475 var attributes = method.GetCustomAttributes(typeof(MTestAttribute));
508 var attributes = method.GetCustomAttributes<MTestAttribute>();
509 bool useXFEConsole = false;
510 int consolePort = 3280;
511 foreach (var customAttribute in method.CustomAttributes)
512 {
513 if (customAttribute is not null && customAttribute.AttributeType.Name == "UseXFEConsoleAttribute")
514 {
515 useXFEConsole = true;
516 foreach (var arg in customAttribute.ConstructorArguments)
517 {
518 if (arg.ArgumentType == typeof(int))
519 consolePort = (int)arg.Value!;
520 }
521 }
522 }
476 523 foreach (MTestAttribute attribute in attributes.Cast<MTestAttribute>())
477 524 {
478 525 if (attribute is MTestAttribute methodAttribute)
@@ -557,6 +604,18 @@ public abstract class XFECode
557 604 try
558 605 {
559 606 currentMethodIsAsserted = false;
607 if (useXFEConsole)
608 {
609 if (Type.GetType("XFEExtension.NetCore.XFEConsole.XFEConsole, XFEExtension.NetCore.XFEConsole") is Type type)
610 {
611 if (type.GetMethod("UseXFEConsole", BindingFlags.Static | BindingFlags.Public, [typeof(int), typeof(string)]) is MethodInfo useXFEConsoleMethodInfo)
612 {
613 var connectSuccessful = await (Task<bool>)useXFEConsoleMethodInfo.Invoke(null, [consolePort, ""])!;
614 if (!connectSuccessful)
615 Console.WriteLine("XFE控制台连接失败!");
616 }
617 }
618 }
560 619 if (method.ReturnType == typeof(Task))
561 620 {
562 621 timeCounter.Start();
@@ -664,6 +723,13 @@ public abstract class XFECode
664 723 Console.Write("=");
665 724 }
666 725 Console.ResetColor();
726 if (useXFEConsole)
727 {
728 if (Type.GetType("XFEExtension.NetCore.XFEConsole.XFEConsole") is Type type && type.GetMethod("StopXFEConsole", BindingFlags.Static | BindingFlags.Public) is MethodInfo stopXFEConsoleMethodInfo)
729 {
730 await (Task)stopXFEConsoleMethodInfo.Invoke(null, null)!;
731 }
732 }
667 733 }
668 734 }
669 735 }