Last active
May 31, 2020 06:18
-
-
Save ankitvijay/e7461410d1f50771beaf2184da7dc374 to your computer and use it in GitHub Desktop.
Part 2 - EnumerationJsonConverterTests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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