public void Test_ReadNonNullableJson(string json, string durationString) { // Validate parameters. if (string.IsNullOrWhiteSpace(json)) { throw new ArgumentNullException(nameof(json)); } if (string.IsNullOrWhiteSpace(durationString)) { throw new ArgumentNullException(nameof(durationString)); } // Get the expected value. TimeSpan expected = TimeSpan.Parse(durationString); // Map to an object. NonNullableTest actual = JsonSerializer.Deserialize <NonNullableTest>(json); // Equal. Assert.Equal(expected, actual.Value); }
public void Test_ReadNonNullableJson(string json, string durationString) { // Validate parameters. if (string.IsNullOrWhiteSpace(json)) { throw new ArgumentNullException(nameof(json)); } if (string.IsNullOrWhiteSpace(durationString)) { throw new ArgumentNullException(nameof(durationString)); } // Get the expected value. TimeSpan expected = TimeSpan.Parse(durationString); // Parse/etc. JObject obj = JObject.Parse(json); // Map to an object. NonNullableTest test = obj.ToObject <NonNullableTest>(); // Equal. Assert.Equal(expected, test.Value); }