mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 02:24:30 +08:00
test(localization): 添加本地化集成测试的临时文件管理和测试数据创建
- 添加 System.IO 命名空间引用以支持文件操作 - 实现 CreateTestLocalizationFiles 方法创建测试用的多语言文件 - 使用 GUID 生成唯一的临时目录路径避免冲突 - 添加 TearDown 方法清理测试过程中创建的临时文件 - 在 Setup 方法中调用文件创建方法初始化测试环境 - 将目标框架配置改为可配置的条件变量方式
This commit is contained in:
parent
d7e7d3cc7f
commit
0c5c9dceae
@ -1,7 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
|
||||
<TestTargetFrameworks Condition="'$(TestTargetFrameworks)' == ''">net10.0</TestTargetFrameworks>
|
||||
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using System.IO;
|
||||
using GFramework.Core.Abstractions.Localization;
|
||||
using GFramework.Core.Localization;
|
||||
|
||||
@ -9,7 +10,9 @@ public class LocalizationIntegrationTests
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_testDataPath = "/tmp/localization_example";
|
||||
_testDataPath = Path.Combine(Path.GetTempPath(), $"gframework_localization_{Guid.NewGuid():N}");
|
||||
CreateTestLocalizationFiles(_testDataPath);
|
||||
|
||||
var config = new LocalizationConfig
|
||||
{
|
||||
DefaultLanguage = "eng",
|
||||
@ -23,9 +26,42 @@ public class LocalizationIntegrationTests
|
||||
_manager.Initialize();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
if (Directory.Exists(_testDataPath))
|
||||
{
|
||||
Directory.Delete(_testDataPath, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
private LocalizationManager? _manager;
|
||||
private string _testDataPath = null!;
|
||||
|
||||
private static void CreateTestLocalizationFiles(string rootPath)
|
||||
{
|
||||
var engPath = Path.Combine(rootPath, "eng");
|
||||
var zhsPath = Path.Combine(rootPath, "zhs");
|
||||
Directory.CreateDirectory(engPath);
|
||||
Directory.CreateDirectory(zhsPath);
|
||||
|
||||
File.WriteAllText(Path.Combine(engPath, "common.json"), """
|
||||
{
|
||||
"game.title": "My Game",
|
||||
"ui.message.welcome": "Welcome, {playerName}!",
|
||||
"status.health": "Health: {current}/{max}"
|
||||
}
|
||||
""");
|
||||
|
||||
File.WriteAllText(Path.Combine(zhsPath, "common.json"), """
|
||||
{
|
||||
"game.title": "我的游戏",
|
||||
"ui.message.welcome": "欢迎, {playerName}!",
|
||||
"status.health": "生命值: {current}/{max}"
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetText_ShouldReturnEnglishText()
|
||||
{
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
|
||||
<TestTargetFrameworks Condition="'$(TestTargetFrameworks)' == ''">net10.0</TestTargetFrameworks>
|
||||
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
|
||||
<TestTargetFrameworks Condition="'$(TestTargetFrameworks)' == ''">net10.0</TestTargetFrameworks>
|
||||
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
|
||||
<TestTargetFrameworks Condition="'$(TestTargetFrameworks)' == ''">net10.0</TestTargetFrameworks>
|
||||
<TargetFrameworks>$(TestTargetFrameworks)</TargetFrameworks>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user