You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpStringToBoolean_Tests.cs

55 lines
1.4 KiB

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 AbpStringToBooleanConverter()
}
};
var testClassJson = JsonSerializer.Serialize(new TestClass()
{
Enabled = true
});
testClassJson.ShouldBe("{\"Enabled\":true}");
}
class TestClass
{
public bool Enabled { get; set; }
}
}
}