Skip to content

Commit eec9725

Browse files
committed
test: 增加单元测试
1 parent dfea8cc commit eec9725

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

test/UnitTest/Locales/en-US.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@
2525
"PlaceHolder": "Click to select ...",
2626
"Primary": "Primary",
2727
"Middle": "Middle"
28+
},
29+
"UnitTest.Utils.UtilityTest": {
30+
"Test-Null": null,
31+
"Test-Key:": ""
2832
}
2933
}

test/UnitTest/Utils/UtilityTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,23 @@ public void GetJsonStringByTypeName_Ok()
379379
Utility.GetJsonStringByTypeName(option, dynamicType!.Assembly, "Test");
380380
}
381381

382+
[Fact]
383+
public void GetJsonStringByTypeName_Exception()
384+
{
385+
// improve code coverage
386+
var option = Context.Services.GetRequiredService<IOptions<JsonLocalizationOptions>>().Value;
387+
option.UseKeyWhenValueIsNull = true;
388+
var items = Utility.GetJsonStringByTypeName(option, this.GetType().Assembly, "UnitTest.Utils.UtilityTest", "en-US", true);
389+
390+
var test1 = items.FirstOrDefault(i => i.Name == "Test-Null");
391+
Assert.NotNull(test1);
392+
Assert.Equal("", test1.Value);
393+
394+
var test2 = items.FirstOrDefault(i => i.Name == "Test-Key");
395+
Assert.NotNull(test2);
396+
Assert.Equal("Test-Key", test2.Value);
397+
}
398+
382399
private class MockDynamicObject : IDynamicObject
383400
{
384401
public Guid DynamicObjectPrimaryKey { get; set; }

0 commit comments

Comments
 (0)