Skip to content

Commit bb00a73

Browse files
committed
Translate files for unit test - Threads / Trace
1 parent 7b9ab3c commit bb00a73

File tree

3 files changed

+42
-46
lines changed

3 files changed

+42
-46
lines changed

src/Senparc.CO2NET.Tests/Threads/SenparcMessageQueueThreadUtilityTests.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading.Tasks;
33
using Microsoft.VisualStudio.TestTools.UnitTesting;
44
using Senparc.CO2NET.MessageQueue;
@@ -16,26 +16,25 @@ public void SenparcMessageQueueThreadUtilityTest()
1616
var key = "SenparcMessageQueueThreadUtilityTest";
1717
smq.Add(key, () =>
1818
{
19-
Console.WriteLine("执行SenparcMessageQueue");
19+
Console.WriteLine("Execute SenparcMessageQueue");
2020
});
2121

22-
Console.WriteLine($"SenparcMessageQueue.Count{smq.GetCount()}");
22+
Console.WriteLine($"SenparcMessageQueue.Count: {smq.GetCount()}");
2323

2424
var senparcMessageQueue = new SenparcMessageQueueThreadUtility();
2525

2626
Task.Factory.StartNew(() =>
2727
{
2828
senparcMessageQueue.Run();
29-
});//异步执行
29+
});// Asynchronous execution
3030

3131
//
3232
while (smq.GetCount() > 0)
3333
{
34-
//执行队列
34+
// Execution details
3535
}
3636

37-
Console.WriteLine($"SenparcMessageQueue队列处理完毕,当前项目:{smq.GetCount()}");
38-
37+
Console.WriteLine($"SenparcMessageQueue processing completed, current count: {smq.GetCount()}");
3938
}
4039
}
4140
}
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using Microsoft.VisualStudio.TestTools.UnitTesting;
33
using Senparc.CO2NET.MessageQueue;
44
using Senparc.CO2NET.Threads;
@@ -12,7 +12,7 @@ public class ThreadUtilityTests
1212
public void ThreadUtilityTest()
1313
{
1414
ThreadUtility.Register();
15-
ThreadUtility.Register();//多次注仍然只记录一次(最早的一次)
15+
ThreadUtility.Register();// This comment is only recorded once, not multiple times
1616
ThreadUtility.Register();
1717

1818
Assert.AreEqual(1, ThreadUtility.AsynThreadCollection.Count);
@@ -21,17 +21,14 @@ public void ThreadUtilityTest()
2121
var key = "ThreadUtilityTests";
2222
smq.Add(key, () =>
2323
{
24-
Console.WriteLine("队列执行SenparcMessageQueue");
24+
Console.WriteLine("Executing SenparcMessageQueue");
2525
});
26-
27-
//不再需要操作 SenparcMessageQueueThreadUtility.Run(),队列已经会自动处理
28-
26+
// No need to operate SenparcMessageQueueThreadUtility.Run(), the queue will handle automatically
2927
while (smq.GetCount() > 0)
3028
{
31-
//执行队列
29+
// Execute the queue
3230
}
33-
34-
Console.WriteLine($"SenparcMessageQueue队列处理完毕,当前项目:{smq.GetCount()}");
31+
Console.WriteLine($"SenparcMessageQueue processing completed, current count: {smq.GetCount()}");
3532
}
3633
}
3734
}

src/Senparc.CO2NET.Tests/Trace/SenparcTraceTests.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Threading;
44
using Microsoft.AspNetCore.Hosting;
@@ -21,73 +21,73 @@ public class SenparcTraceTests
2121

2222
public SenparcTraceTests()
2323
{
24-
//注册
24+
//Comment
2525
var mockEnv = new Mock<Microsoft.Extensions.Hosting.IHostEnvironment/*IHostingEnvironment*/>();
2626
mockEnv.Setup(z => z.ContentRootPath).Returns(() => UnitTestHelper.RootPath);
2727
var register = Senparc.CO2NET.AspNet.RegisterServices.RegisterService.Start(mockEnv.Object, new SenparcSetting() { IsDebug = true });
2828

2929
IServiceCollection services = new ServiceCollection();
30-
services.AddMemoryCache();//使用内存缓存
30+
services.AddMemoryCache();//Used for caching
3131

32-
SenparcDI.GlobalServiceCollection = services;//本地缓存需要用到
32+
SenparcDI.GlobalServiceCollection = services;//Required for registration
3333

3434
//var mockRegisterService = new Mock<RegisterService>();
3535
//mockRegisterService.Setup(z => z.ServiceCollection).Returns(() => services);
3636

37-
//删除日志文件
37+
//Delete log file
3838
//File.Delete(_logFilePath);
3939
}
4040

4141

4242
[TestMethod]
4343
public void LogTest()
4444
{
45-
//直接调用此方法不会记录到log文件中,而是输出到系统日志中
46-
var keyword = Guid.NewGuid().ToString();//随机字符串
47-
SenparcTrace.Log($"添加Log:{keyword}");
45+
//Directly call this method to record in the log file, instead of the system log
46+
var keyword = Guid.NewGuid().ToString();//Test string
47+
SenparcTrace.Log($"Add Log: {keyword}");
4848

4949
var dt1 = SystemTime.Now;
5050
while (SystemTime.DiffTotalMS(dt1) < 600)
5151
{
52-
//等待队列执行
52+
//Wait for execution
5353
}
5454

5555
SenparcMessageQueue.OperateQueue();
5656

5757
Console.WriteLine(SenparcMessageQueue.MessageQueueDictionary.Count);
5858

5959
Console.WriteLine(ThreadUtility.AsynThreadCollection.Count);
60-
//Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(_logFilePath,keyword));
60+
//Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(_logFilePath, keyword));
6161
}
6262

6363

6464
[TestMethod]
6565
public void SendCustomLogTest()
6666
{
67-
var keyword = Guid.NewGuid().ToString();//随机字符串
68-
SenparcTrace.SendCustomLog("标题", $"添加Log:{keyword}");
67+
var keyword = Guid.NewGuid().ToString();//Test string
68+
SenparcTrace.SendCustomLog("Title", $"Add Log: {keyword}");
6969

7070
var dt1 = SystemTime.Now;
7171
while (SystemTime.DiffTotalMS(dt1) < 800)
7272
{
73-
//等待队列执行
73+
//Wait for execution
7474
}
7575

76-
Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(LogFilePath, "标题", keyword));
76+
Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(LogFilePath, "Title", keyword));
7777
}
7878

7979

8080
[TestMethod]
8181
public void SendApiLogTest()
8282
{
8383
var url = "http://www.senparc.com";
84-
var result = Guid.NewGuid().ToString();//随机字符串
84+
var result = Guid.NewGuid().ToString();//Test string
8585
SenparcTrace.SendApiLog(url, result);
8686

8787
var dt1 = SystemTime.Now;
8888
while (SystemTime.DiffTotalMS(dt1) < 800)
8989
{
90-
//等待队列执行
90+
//Wait for execution
9191
}
9292

9393
Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(LogFilePath, url, result));
@@ -98,13 +98,13 @@ public void SendApiLogTest()
9898
public void SendApiPostDataLogTest()
9999
{
100100
var url = "http://www.senparc.com";
101-
var data = Guid.NewGuid().ToString();//随机字符串
101+
var data = Guid.NewGuid().ToString();//Test string
102102
SenparcTrace.SendApiLog(url, data);
103103

104104
var dt1 = SystemTime.Now;
105105
while (SystemTime.DiffTotalMS(dt1) < 800)
106106
{
107-
//等待队列执行
107+
//Wait for execution
108108
}
109109

110110
Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(LogFilePath, url, data));
@@ -115,18 +115,18 @@ public void SendApiPostDataLogTest()
115115
[TestMethod]
116116
public void BaseExceptionLogTest()
117117
{
118-
var keyword = Guid.NewGuid().ToString();//随机字符串
119-
var ex = new BaseException("测试异常:" + keyword);
120-
//Log会记录两次,第一次是在BaseException初始化的时候会调用此方法
118+
var keyword = Guid.NewGuid().ToString();//Test string
119+
var ex = new BaseException("Test Excepption" + keyword);
120+
//Log recording method, call this method when initializing a BaseException
121121
SenparcTrace.BaseExceptionLog(ex);
122122

123123
var dt1 = SystemTime.Now;
124124
while (SystemTime.DiffTotalMS(dt1) < 800)
125125
{
126-
//等待队列执行
126+
//Wait for execution
127127
}
128128

129-
Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(LogFilePath, "测试异常", keyword));
129+
Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(LogFilePath, "�����쳣", keyword));
130130
}
131131

132132
[TestMethod]
@@ -135,13 +135,13 @@ public void OnLogFuncTest()
135135
var onlogCount = 0;
136136
SenparcTrace.OnLogFunc = () => onlogCount++;
137137

138-
var keyword = Guid.NewGuid().ToString();//随机字符串
139-
SenparcTrace.SendCustomLog("测试OnLogFuncTest", keyword);
138+
var keyword = Guid.NewGuid().ToString();//Test string
139+
SenparcTrace.SendCustomLog("Test OnLogFuncTest", keyword);
140140

141141
var dt1 = SystemTime.Now;
142142
while (SystemTime.DiffTotalMS(dt1) < 800)
143143
{
144-
//等待队列执行
144+
//Wait for execution
145145
}
146146

147147
Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(LogFilePath, keyword));
@@ -155,15 +155,15 @@ public void OnBaseExceptionFuncTest()
155155
var onlogCount = 0;
156156
SenparcTrace.OnLogFunc = () => onlogCount++;
157157

158-
var keyword = Guid.NewGuid().ToString();//随机字符串
159-
var ex = new BaseException("测试异常:" + keyword);
160-
//Log会记录两次,第一次是在BaseException初始化的时候会调用此方法
158+
var keyword = Guid.NewGuid().ToString();//Test string
159+
var ex = new BaseException("Test Exception" + keyword);
160+
//Log recording method, call this method when initializing a BaseException
161161
SenparcTrace.BaseExceptionLog(ex);
162162

163163
var dt1 = SystemTime.Now;
164164
while (SystemTime.DiffTotalMS(dt1) < 1000)
165165
{
166-
//等待队列执行
166+
//Wait for execution
167167
}
168168

169169
Assert.IsTrue(UnitTestHelper.CheckKeywordsExist(LogFilePath, keyword));

0 commit comments

Comments
 (0)