public void JsonElementToDynamicValueWhenObjectShouldReturnObject() { // ARRANGE var doc = JsonDocument.Parse("{\"str\": \"string\"}"); // ACT var obj = JsonElementExtensions.ToDynamicValue(doc.RootElement) as IDictionary <string, object?>; // ASSERT Assert.Equal("string", obj?["str"]); }
public void JsonElementToDynamicValueWhenDoubleShouldReturnDouble() { // ARRANGE var doc = JsonDocument.Parse("{\"int\": 10.5}"); var prop = doc.RootElement.GetProperty("int"); double expectedValue = 10.5; // ACT var obj = JsonElementExtensions.ToDynamicValue(prop); // ASSERT Assert.IsType <double>(obj); Assert.Equal(expectedValue, obj); }
public void JsonElementToDynamicValueWhenFalseShouldReturnBoolFalse() { // ARRANGE var doc = JsonDocument.Parse("{\"bool\": false}"); var prop = doc.RootElement.GetProperty("bool"); // ACT var obj = JsonElementExtensions.ToDynamicValue(prop); // ASSERT Assert.IsType <bool>(obj); Assert.Equal(false, obj); }
public void JsonElementToDynamicValueWhenStringShouldReturnString() { // ARRANGE var doc = JsonDocument.Parse("{\"str\": \"string\"}"); var prop = doc.RootElement.GetProperty("str"); // ACT var obj = JsonElementExtensions.ToDynamicValue(prop); // ASSERT Assert.IsType <string>(obj); Assert.Equal("string", obj); }
public void JsonElementToDynamicValueWhenArrayShouldReturnArray() { // ARRANGE var doc = JsonDocument.Parse("{\"array\": [\"a\", \"b\", \"c\"]}"); var prop = doc.RootElement.GetProperty("array"); // ACT var obj = JsonElementExtensions.ToDynamicValue(prop); var arr = obj as IEnumerable <object?>; // ASSERT Assert.NotNull(arr); Assert.Equal(3, arr?.Count()); }