Browse Source

Add more DefaultUnknownEnumConverter tests

pull/324/head
Ionite 12 months ago
parent
commit
51b81dc2c0
No known key found for this signature in database
  1. 35
      StabilityMatrix.Tests/Core/DefaultUnknownEnumConverterTests.cs

35
StabilityMatrix.Tests/Core/DefaultUnknownEnumConverterTests.cs

@ -1,4 +1,5 @@
using System.Text.Json; using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using StabilityMatrix.Core.Converters.Json; using StabilityMatrix.Core.Converters.Json;
@ -46,6 +47,16 @@ public class DefaultUnknownEnumConverterTests
Assert.AreEqual(expected, result); Assert.AreEqual(expected, result);
} }
[TestMethod]
public void TestDeserialize_UnknownEnum_ShouldUseEnumMemberValue()
{
const string json = "\"Value 2\"";
var result = JsonSerializer.Deserialize<UnknownEnum>(json);
Assert.AreEqual(UnknownEnum.Value2, result);
}
[TestMethod] [TestMethod]
public void TestSerialize_DefaultEnum_ShouldConvert() public void TestSerialize_DefaultEnum_ShouldConvert()
{ {
@ -56,6 +67,26 @@ public class DefaultUnknownEnumConverterTests
Assert.AreEqual(expected, result); Assert.AreEqual(expected, result);
} }
[TestMethod]
public void TestSerialize_UnknownEnum_ShouldUseEnumMemberValue()
{
const string json = "\"Value 2\"";
var result = JsonSerializer.Deserialize<UnknownEnum>(json);
Assert.AreEqual(UnknownEnum.Value2, result);
}
[TestMethod]
public void TestSerialize_ComplexObject_ShouldUseEnumMemberValue()
{
const string expected = "{\"Key\":\"Value 2\"}";
var result = JsonSerializer.Serialize(new { Key = UnknownEnum.Value2 });
Assert.AreEqual(expected, result);
}
private enum NormalEnum private enum NormalEnum
{ {
Unknown, Unknown,
@ -68,6 +99,8 @@ public class DefaultUnknownEnumConverterTests
{ {
Unknown, Unknown,
Value1, Value1,
[EnumMember(Value = "Value 2")]
Value2 Value2
} }

Loading…
Cancel
Save