Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Last active May 31, 2020 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankitvijay/e7461410d1f50771beaf2184da7dc374 to your computer and use it in GitHub Desktop.
Save ankitvijay/e7461410d1f50771beaf2184da7dc374 to your computer and use it in GitHub Desktop.
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