Part 2 - EnumerationJsonConverterTests
// Import System.Text.Json; | |
public class EnumerationJsonConverterTests | |
{ | |
private readonly ITestOutputHelper _testOutputHelper; | |
public EnumerationJsonConverterTests(ITestOutputHelper testOutputHelper) | |
{ | |
_testOutputHelper = testOutputHelper; | |
} | |
[Fact] | |
public void EnumerationIsSerializesAndDeserializesCorrectly() | |
{ | |
var expected = new Transaction | |
{ | |
Amount = 100, | |
PaymentType = PaymentType.CreditCard | |
}; | |
var json = JsonSerializer.Serialize(expected, | |
new JsonSerializerOptions | |
{ | |
Converters = | |
{ | |
new EnumerationJsonConverter() | |
} | |
}); | |
_testOutputHelper.WriteLine(json); | |
var actual= JsonSerializer.Deserialize<Transaction>(json, new JsonSerializerOptions() | |
{ | |
Converters = { new EnumerationJsonConverter() } | |
}); | |
Assert.Equal(expected.Amount, actual.Amount); | |
Assert.Equal(expected.PaymentType, actual.PaymentType); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment