mirror of https://github.com/abpframework/abp.git
2 changed files with 109 additions and 0 deletions
@ -0,0 +1,54 @@ |
|||
using System.Text.Json; |
|||
using Shouldly; |
|||
using Volo.Abp.Json.SystemTextJson.JsonConverters; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Json |
|||
{ |
|||
public class AbpStringToBoolean_Tests |
|||
{ |
|||
[Fact] |
|||
public void Test_Read() |
|||
{ |
|||
var options = new JsonSerializerOptions() |
|||
{ |
|||
Converters = |
|||
{ |
|||
new AbpStringToBooleanConverter() |
|||
} |
|||
}; |
|||
|
|||
var testClass = JsonSerializer.Deserialize<TestClass>("{\"Enabled\": \"TrUe\"}", options); |
|||
testClass.ShouldNotBeNull(); |
|||
testClass.Enabled.ShouldBe(true); |
|||
|
|||
testClass = JsonSerializer.Deserialize<TestClass>("{\"Enabled\": true}", options); |
|||
testClass.ShouldNotBeNull(); |
|||
testClass.Enabled.ShouldBe(true); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Test_Write() |
|||
{ |
|||
var options = new JsonSerializerOptions() |
|||
{ |
|||
Converters = |
|||
{ |
|||
new AbpStringToEnumFactory() |
|||
} |
|||
}; |
|||
|
|||
var testClassJson = JsonSerializer.Serialize(new TestClass() |
|||
{ |
|||
Enabled = true |
|||
}); |
|||
|
|||
testClassJson.ShouldBe("{\"Enabled\":true}"); |
|||
} |
|||
|
|||
class TestClass |
|||
{ |
|||
public bool Enabled { get; set; } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
using System; |
|||
using System.Text.Json; |
|||
using Shouldly; |
|||
using Volo.Abp.Json.SystemTextJson.JsonConverters; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.Json |
|||
{ |
|||
public class AbpStringToEnum_Tests |
|||
{ |
|||
[Fact] |
|||
public void Test_Read() |
|||
{ |
|||
var options = new JsonSerializerOptions() |
|||
{ |
|||
Converters = |
|||
{ |
|||
new AbpStringToEnumFactory() |
|||
} |
|||
}; |
|||
|
|||
var testClass = JsonSerializer.Deserialize<TestClass>("{\"Day\": \"Monday\"}", options); |
|||
testClass.ShouldNotBeNull(); |
|||
testClass.Day.ShouldBe(DayOfWeek.Monday); |
|||
|
|||
testClass = JsonSerializer.Deserialize<TestClass>("{\"Day\": 1}", options); |
|||
testClass.ShouldNotBeNull(); |
|||
testClass.Day.ShouldBe(DayOfWeek.Monday); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Test_Write() |
|||
{ |
|||
var options = new JsonSerializerOptions() |
|||
{ |
|||
Converters = |
|||
{ |
|||
new AbpStringToEnumFactory() |
|||
} |
|||
}; |
|||
|
|||
var testClassJson = JsonSerializer.Serialize(new TestClass() |
|||
{ |
|||
Day = DayOfWeek.Monday |
|||
}); |
|||
|
|||
testClassJson.ShouldBe("{\"Day\":1}"); |
|||
} |
|||
|
|||
class TestClass |
|||
{ |
|||
public DayOfWeek Day { get; set; } |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue