@@ -13,24 +13,24 @@ public class DatabaseExportServiceTests
1313 [ TestMethod ]
1414 public async Task TestDatabaseExportServiceWithMockData ( )
1515 {
16- // 创建临时输出目录
16+ // Create temporary output directory
1717 var outputDir = Path . Combine ( Path . GetTempPath ( ) , "MsSql2Any_Test_Output_" + Guid . NewGuid ( ) . ToString ( ) ) ;
1818 Directory . CreateDirectory ( outputDir ) ;
1919
2020 try
2121 {
22- // 创建模拟配置
22+ // Create mock configuration
2323 var mockConfig = new AppConfig
2424 {
2525 SourceConnectionString = "mock_connection_string" ,
26- OutputDirectory = outputDir , // 使用临时目录
26+ OutputDirectory = outputDir , // Using temporary directory
2727 BatchSize = 1000
2828 } ;
2929
30- // 创建模拟数据库提供者
30+ // Create mock database provider
3131 var mockDbProvider = new Mock < ISourceDbProvider > ( ) ;
3232
33- // 设置模拟方法的返回值
33+ // Setup mock method return values
3434 var tableNames = new List < string > { "Users" , "Products" } ;
3535 mockDbProvider . Setup ( x => x . GetTableNamesAsync ( ) ) . ReturnsAsync ( tableNames ) ;
3636
@@ -79,7 +79,7 @@ public async Task TestDatabaseExportServiceWithMockData()
7979 mockDbProvider . Setup ( x => x . GetColumnsAsync ( "Users" ) ) . ReturnsAsync ( userColumns ) ;
8080 mockDbProvider . Setup ( x => x . GetColumnsAsync ( "Products" ) ) . ReturnsAsync ( productColumns ) ;
8181
82- // 模拟数据
82+ // Mock data
8383 var userData = new List < object [ ] > { new object [ ] { 1 , "John Doe" } , new object [ ] { 2 , "Jane Smith" } } ;
8484 var productData = new List < object [ ] > { new object [ ] { 1 , "Product A" } , new object [ ] { 2 , "Product B" } } ;
8585
@@ -89,7 +89,7 @@ public async Task TestDatabaseExportServiceWithMockData()
8989 mockDbProvider . Setup ( x => x . GetDataAsync ( "Products" , 1000 ) )
9090 . Returns ( productData . ToAsyncEnumerable ( ) ) ;
9191
92- // 创建模拟脚本生成器
92+ // Create mock script generators
9393 var mockGenerators = new List < IScriptGenerator >
9494 {
9595 new MysqlScriptGenerator ( ) ,
@@ -98,35 +98,35 @@ public async Task TestDatabaseExportServiceWithMockData()
9898 new DamengScriptGenerator ( )
9999 } . AsEnumerable ( ) ;
100100
101- // 创建服务实例
101+ // Create service instance
102102 var exportService = new DatabaseExportService ( mockDbProvider . Object , mockGenerators , mockConfig ) ;
103103
104- // 执行导出操作
104+ // Execute export operation
105105 await exportService . ExportAsync ( ) ;
106106
107- // 验证模拟对象的方法被调用
107+ // Verify mock object methods were called
108108 mockDbProvider . Verify ( x => x . Initialize ( "mock_connection_string" ) , Times . Once ) ;
109109 mockDbProvider . Verify ( x => x . GetTableNamesAsync ( ) , Times . Once ) ;
110- // 由于DatabaseExportService为每种数据库类型都会获取表结构,所以GetColumnsAsync会被调用多次
111- mockDbProvider . Verify ( x => x . GetColumnsAsync ( "Users" ) , Times . Exactly ( 4 ) ) ; // 4种数据库类型
112- mockDbProvider . Verify ( x => x . GetColumnsAsync ( "Products" ) , Times . Exactly ( 4 ) ) ; // 4种数据库类型
113- mockDbProvider . Verify ( x => x . GetDataAsync ( "Users" , 1000 ) , Times . Exactly ( 4 ) ) ; // 4种数据库类型
114- mockDbProvider . Verify ( x => x . GetDataAsync ( "Products" , 1000 ) , Times . Exactly ( 4 ) ) ; // 4种数据库类型
115-
116- // 验证输出文件已创建
117- var mysqlOutputFile = Path . Combine ( outputDir , "output_mysql .sql" ) ;
118- var sqliteOutputFile = Path . Combine ( outputDir , "output_sqlite .sql" ) ;
119- var postgresqlOutputFile = Path . Combine ( outputDir , "output_postgresql .sql" ) ;
120- var damengOutputFile = Path . Combine ( outputDir , "output_dameng .sql" ) ;
121-
122- Assert . IsTrue ( File . Exists ( mysqlOutputFile ) , "MySQL输出文件应存在 " ) ;
123- Assert . IsTrue ( File . Exists ( sqliteOutputFile ) , "SQLite输出文件应存在 " ) ;
124- Assert . IsTrue ( File . Exists ( postgresqlOutputFile ) , "PostgreSQL输出文件应存在 " ) ;
125- Assert . IsTrue ( File . Exists ( damengOutputFile ) , "达梦输出文件应存在 " ) ;
110+ // Since DatabaseExportService retrieves table structure for each database type, GetColumnsAsync is called multiple times
111+ mockDbProvider . Verify ( x => x . GetColumnsAsync ( "Users" ) , Times . Exactly ( 4 ) ) ; // 4 database types
112+ mockDbProvider . Verify ( x => x . GetColumnsAsync ( "Products" ) , Times . Exactly ( 4 ) ) ; // 4 database types
113+ mockDbProvider . Verify ( x => x . GetDataAsync ( "Users" , 1000 ) , Times . Exactly ( 4 ) ) ; // 4 database types
114+ mockDbProvider . Verify ( x => x . GetDataAsync ( "Products" , 1000 ) , Times . Exactly ( 4 ) ) ; // 4 database types
115+
116+ // Verify output files were created
117+ var mysqlOutputFile = Path . Combine ( outputDir , "MySQL .sql" ) ;
118+ var sqliteOutputFile = Path . Combine ( outputDir , "SQLite .sql" ) ;
119+ var postgresqlOutputFile = Path . Combine ( outputDir , "PostgreSQL .sql" ) ;
120+ var damengOutputFile = Path . Combine ( outputDir , "Dameng .sql" ) ;
121+
122+ Assert . IsTrue ( File . Exists ( mysqlOutputFile ) , "MySQL output file should exist " ) ;
123+ Assert . IsTrue ( File . Exists ( sqliteOutputFile ) , "SQLite output file should exist " ) ;
124+ Assert . IsTrue ( File . Exists ( postgresqlOutputFile ) , "PostgreSQL output file should exist " ) ;
125+ Assert . IsTrue ( File . Exists ( damengOutputFile ) , "Dameng output file should exist " ) ;
126126 }
127127 finally
128128 {
129- // 清理临时目录
129+ // Clean up temporary directory
130130 if ( Directory . Exists ( outputDir ) )
131131 {
132132 Directory . Delete ( outputDir , true ) ;
@@ -224,15 +224,15 @@ public void TestDataTypeMappingForAllGenerators()
224224 }
225225 }
226226
227- // 辅助扩展方法,用于将列表转换为异步可枚举对象
227+ // Helper extension method to convert a list to an asynchronous enumerable
228228 public static class TestExtensions
229229 {
230230 public static async IAsyncEnumerable < T > ToAsyncEnumerable < T > ( this IEnumerable < T > source )
231231 {
232232 foreach ( var item in source )
233233 {
234234 yield return item ;
235- await Task . Yield ( ) ; // 允许异步操作继续
235+ await Task . Yield ( ) ; // Allow async operation to continue
236236 }
237237 }
238238 }
0 commit comments