// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Runtime.Serialization.Json; using Xunit; namespace System.Json { public class JsonObjectTest { [Fact] public void JsonObjectConstructorEnumTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; List> items = new List>() { new KeyValuePair(key1, value1), new KeyValuePair(key2, value2), }; JsonObject target = new JsonObject(null); Assert.Equal(0, target.Count); target = new JsonObject(items); Assert.Equal(2, target.Count); ValidateJsonObjectItems(target, key1, value1, key2, value2); // Invalid tests items.Add(new KeyValuePair(key1, AnyInstance.DefaultJsonValue)); ExceptionHelper.Throws(delegate { new JsonObject(items); }); } [Fact] public void JsonObjectConstructorParmsTest() { JsonObject target = new JsonObject(); Assert.Equal(0, target.Count); string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; List> items = new List>() { new KeyValuePair(key1, value1), new KeyValuePair(key2, value2), }; target = new JsonObject(items[0], items[1]); Assert.Equal(2, target.Count); ValidateJsonObjectItems(target, key1, value1, key2, value2); target = new JsonObject(items.ToArray()); Assert.Equal(2, target.Count); ValidateJsonObjectItems(target, key1, value1, key2, value2); // Invalid tests items.Add(new KeyValuePair(key1, AnyInstance.DefaultJsonValue)); ExceptionHelper.Throws(delegate { new JsonObject(items[0], items[1], items[2]); }); ExceptionHelper.Throws(delegate { new JsonObject(items.ToArray()); }); } [Fact] public void AddTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target; target = new JsonObject(); target.Add(new KeyValuePair(key1, value1)); Assert.Equal(1, target.Count); Assert.True(target.ContainsKey(key1)); Assert.Equal(value1, target[key1]); target.Add(key2, value2); Assert.Equal(2, target.Count); Assert.True(target.ContainsKey(key2)); Assert.Equal(value2, target[key2]); ExceptionHelper.Throws(delegate { new JsonObject().Add(null, value1); }); ExceptionHelper.Throws(delegate { new JsonObject().Add(new KeyValuePair(null, value1)); }); ExceptionHelper.Throws(delegate { new JsonObject().Add(key1, AnyInstance.DefaultJsonValue); }); ExceptionHelper.Throws(delegate { new JsonArray().Add(AnyInstance.DefaultJsonValue); }); } [Fact] public void AddRangeParamsTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; List> items = new List>() { new KeyValuePair(key1, value1), new KeyValuePair(key2, value2), }; JsonObject target; target = new JsonObject(); target.AddRange(items[0], items[1]); Assert.Equal(2, target.Count); ValidateJsonObjectItems(target, key1, value1, key2, value2); target = new JsonObject(); target.AddRange(items.ToArray()); Assert.Equal(2, target.Count); ValidateJsonObjectItems(target, key1, value1, key2, value2); ExceptionHelper.Throws(delegate { new JsonObject().AddRange((KeyValuePair[])null); }); ExceptionHelper.Throws(delegate { new JsonObject().AddRange((IEnumerable>)null); }); items[1] = new KeyValuePair(key2, AnyInstance.DefaultJsonValue); ExceptionHelper.Throws(delegate { new JsonObject().AddRange(items.ToArray()); }); ExceptionHelper.Throws(delegate { new JsonObject().AddRange(items[0], items[1]); }); } [Fact] public void AddRangeEnumTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; List> items = new List>() { new KeyValuePair(key1, value1), new KeyValuePair(key2, value2), }; JsonObject target; target = new JsonObject(); target.AddRange(items); Assert.Equal(2, target.Count); ValidateJsonObjectItems(target, key1, value1, key2, value2); ExceptionHelper.Throws(delegate { new JsonObject().AddRange(null); }); items[1] = new KeyValuePair(key2, AnyInstance.DefaultJsonValue); ExceptionHelper.Throws(delegate { new JsonObject().AddRange(items); }); } [Fact] public void ClearTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target = new JsonObject(); target.Add(key1, value1); target.Clear(); Assert.Equal(0, target.Count); Assert.False(target.ContainsKey(key1)); target.Add(key2, value2); Assert.Equal(1, target.Count); Assert.False(target.ContainsKey(key1)); Assert.True(target.ContainsKey(key2)); } [Fact] public void ContainsKeyTest() { string key1 = AnyInstance.AnyString; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonObject target = new JsonObject(); Assert.False(target.ContainsKey(key1)); target.Add(key1, value1); Assert.True(target.ContainsKey(key1)); target.Clear(); Assert.False(target.ContainsKey(key1)); ExceptionHelper.Throws(delegate { new JsonObject().ContainsKey(null); }); } [Fact] public void CopyToTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target = new JsonObject { { key1, value1 }, { key2, value2 } }; KeyValuePair[] array = new KeyValuePair[target.Count + 1]; target.CopyTo(array, 1); int index1 = key1 == array[1].Key ? 1 : 2; int index2 = index1 == 1 ? 2 : 1; Assert.Equal(key1, array[index1].Key); Assert.Equal(value1, array[index1].Value); Assert.Equal(key2, array[index2].Key); Assert.Equal(value2, array[index2].Value); ExceptionHelper.Throws(() => target.CopyTo(null, 0)); ExceptionHelper.Throws(() => target.CopyTo(array, -1)); ExceptionHelper.Throws(() => target.CopyTo(array, array.Length - target.Count + 1)); } [Fact] public void CreateFromComplexTypeTest() { Assert.Null(JsonValueExtensions.CreateFrom(null)); Person anyObject = AnyInstance.AnyPerson; JsonObject jv = JsonValueExtensions.CreateFrom(anyObject) as JsonObject; Assert.NotNull(jv); Assert.Equal(4, jv.Count); foreach (string key in "Name Age Address".Split()) { Assert.True(jv.ContainsKey(key)); } Assert.Equal(AnyInstance.AnyString, (string)jv["Name"]); Assert.Equal(AnyInstance.AnyInt, (int)jv["Age"]); JsonObject nestedObject = jv["Address"] as JsonObject; Assert.NotNull(nestedObject); Assert.Equal(3, nestedObject.Count); foreach (string key in "Street City State".Split()) { Assert.True(nestedObject.ContainsKey(key)); } Assert.Equal(Address.AnyStreet, (string)nestedObject["Street"]); Assert.Equal(Address.AnyCity, (string)nestedObject["City"]); Assert.Equal(Address.AnyState, (string)nestedObject["State"]); } [Fact] public void ReadAsComplexTypeTest() { JsonObject target = new JsonObject { { "Name", AnyInstance.AnyString }, { "Age", AnyInstance.AnyInt }, { "Address", new JsonObject { { "Street", Address.AnyStreet }, { "City", Address.AnyCity }, { "State", Address.AnyState } } }, }; Person person = target.ReadAsType(); Assert.Equal(AnyInstance.AnyString, person.Name); Assert.Equal(AnyInstance.AnyInt, person.Age); Assert.NotNull(person.Address); Assert.Equal(Address.AnyStreet, person.Address.Street); Assert.Equal(Address.AnyCity, person.Address.City); Assert.Equal(Address.AnyState, person.Address.State); } [Fact] public void GetEnumeratorTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target = new JsonObject { { key1, value1 }, { key2, value2 } }; IEnumerator> enumerator = target.GetEnumerator(); Assert.True(enumerator.MoveNext()); bool key1IsFirst = key1 == enumerator.Current.Key; if (key1IsFirst) { Assert.Equal(key1, enumerator.Current.Key); Assert.Equal(value1, enumerator.Current.Value); } else { Assert.Equal(key2, enumerator.Current.Key); Assert.Equal(value2, enumerator.Current.Value); } Assert.True(enumerator.MoveNext()); if (key1IsFirst) { Assert.Equal(key2, enumerator.Current.Key); Assert.Equal(value2, enumerator.Current.Value); } else { Assert.Equal(key1, enumerator.Current.Key); Assert.Equal(value1, enumerator.Current.Value); } Assert.False(enumerator.MoveNext()); } [Fact] public void RemoveTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target = new JsonObject { { key1, value1 }, { key2, value2 } }; Assert.True(target.ContainsKey(key1)); Assert.True(target.ContainsKey(key2)); Assert.Equal(2, target.Count); Assert.True(target.Remove(key2)); Assert.True(target.ContainsKey(key1)); Assert.False(target.ContainsKey(key2)); Assert.Equal(1, target.Count); Assert.False(target.Remove(key2)); Assert.True(target.ContainsKey(key1)); Assert.False(target.ContainsKey(key2)); Assert.Equal(1, target.Count); } [Fact] public void ToStringTest() { JsonObject target = new JsonObject(); JsonValue item1 = AnyInstance.AnyJsonValue1 ?? "not null"; JsonValue item2 = null; JsonValue item3 = AnyInstance.AnyJsonValue2 ?? "not null"; JsonValue item4 = AnyInstance.AnyJsonValue3 ?? "not null"; target.Add("item1", item1); target.Add("item2", item2); target.Add("item3", item3); target.Add("", item4); string expected = String.Format(CultureInfo.InvariantCulture, "{{\"item1\":{0},\"item2\":null,\"item3\":{1},\"\":{2}}}", item1.ToString(), item3.ToString(), item4.ToString()); Assert.Equal(expected, target.ToString()); string json = "{\r\n \"item1\": \"hello\",\r\n \"item2\": null,\r\n \"item3\": [\r\n 1,\r\n 2,\r\n 3\r\n ],\r\n \"\": \"notnull\"\r\n}"; target = JsonValue.Parse(json) as JsonObject; Assert.Equal(json.Replace("\r\n", "").Replace(" ", ""), target.ToString()); } [Fact] public void ContainsKVPTest() { JsonObject target = new JsonObject(); KeyValuePair item = new KeyValuePair(AnyInstance.AnyString, AnyInstance.AnyJsonValue1); KeyValuePair item2 = new KeyValuePair(AnyInstance.AnyString2, AnyInstance.AnyJsonValue2); target.Add(item); Assert.True(((ICollection>)target).Contains(item)); Assert.False(((ICollection>)target).Contains(item2)); } [Fact] public void RemoveKVPTest() { JsonObject target = new JsonObject(); KeyValuePair item1 = new KeyValuePair(AnyInstance.AnyString, AnyInstance.AnyJsonValue1); KeyValuePair item2 = new KeyValuePair(AnyInstance.AnyString2, AnyInstance.AnyJsonValue2); target.AddRange(item1, item2); Assert.Equal(2, target.Count); Assert.True(((ICollection>)target).Contains(item1)); Assert.True(((ICollection>)target).Contains(item2)); Assert.True(((ICollection>)target).Remove(item1)); Assert.Equal(1, target.Count); Assert.False(((ICollection>)target).Contains(item1)); Assert.True(((ICollection>)target).Contains(item2)); Assert.False(((ICollection>)target).Remove(item1)); Assert.Equal(1, target.Count); Assert.False(((ICollection>)target).Contains(item1)); Assert.True(((ICollection>)target).Contains(item2)); } [Fact] public void GetEnumeratorTest1() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target = new JsonObject { { key1, value1 }, { key2, value2 } }; IEnumerator enumerator = ((IEnumerable)target).GetEnumerator(); Assert.True(enumerator.MoveNext()); Assert.IsType>(enumerator.Current); KeyValuePair current = (KeyValuePair)enumerator.Current; bool key1IsFirst = key1 == current.Key; if (key1IsFirst) { Assert.Equal(key1, current.Key); Assert.Equal(value1, current.Value); } else { Assert.Equal(key2, current.Key); Assert.Equal(value2, current.Value); } Assert.True(enumerator.MoveNext()); Assert.IsType>(enumerator.Current); current = (KeyValuePair)enumerator.Current; if (key1IsFirst) { Assert.Equal(key2, current.Key); Assert.Equal(value2, current.Value); } else { Assert.Equal(key1, current.Key); Assert.Equal(value1, current.Value); } Assert.False(enumerator.MoveNext()); } [Fact] public void TryGetValueTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target = new JsonObject { { key1, value1 }, { key2, value2 } }; JsonValue value; Assert.True(target.TryGetValue(key2, out value)); Assert.Equal(value2, value); Assert.False(target.TryGetValue("not a key", out value)); Assert.Null(value); } [Fact] public void GetValueOrDefaultTest() { bool boolValue; JsonValue target; JsonValue jsonValue; Person person = AnyInstance.AnyPerson; JsonObject jo = JsonValueExtensions.CreateFrom(person) as JsonObject; Assert.Equal(person.Age, jo.ValueOrDefault("Age").ReadAs()); // JsonPrimitive Assert.Equal(person.Address.ToString(), jo.ValueOrDefault("Address").ReadAsType
().ToString()); // JsonObject Assert.Equal(person.Friends.Count, jo.ValueOrDefault("Friends").Count); // JsonArray target = jo.ValueOrDefault("Address").ValueOrDefault("City"); // JsonPrimitive Assert.NotNull(target); Assert.Equal(person.Address.City, target.ReadAs()); target = jo.ValueOrDefault("Address", "City"); // JsonPrimitive Assert.NotNull(target); Assert.Equal(person.Address.City, target.ReadAs()); target = jo.ValueOrDefault("Address").ValueOrDefault("NonExistentProp").ValueOrDefault("NonExistentProp2"); // JsonObject Assert.Equal(JsonType.Default, target.JsonType); Assert.NotNull(target); Assert.False(target.TryReadAs(out boolValue)); Assert.True(target.TryReadAs(out jsonValue)); target = jo.ValueOrDefault("Address", "NonExistentProp", "NonExistentProp2"); // JsonObject Assert.Equal(JsonType.Default, target.JsonType); Assert.NotNull(target); Assert.False(target.TryReadAs(out boolValue)); Assert.True(target.TryReadAs(out jsonValue)); Assert.Same(target, jsonValue); } [Fact] public void CountTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target = new JsonObject(); Assert.Equal(0, target.Count); target.Add(key1, value1); Assert.Equal(1, target.Count); target.Add(key2, value2); Assert.Equal(2, target.Count); target.Remove(key2); Assert.Equal(1, target.Count); } [Fact] public void ItemTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonValue value3 = AnyInstance.AnyJsonValue3; JsonObject target; target = new JsonObject { { key1, value1 }, { key2, value2 } }; Assert.Equal(value1, target[key1]); Assert.Equal(value2, target[key2]); target[key1] = value3; Assert.Equal(value3, target[key1]); Assert.Equal(value2, target[key2]); ExceptionHelper.Throws(delegate { var o = target["not a key"]; }); ExceptionHelper.Throws(delegate { var o = target[null]; }); ExceptionHelper.Throws(delegate { target[null] = 123; }); ExceptionHelper.Throws(delegate { target[key1] = AnyInstance.DefaultJsonValue; }); } [Fact] public void ChangingEventsTest() { const string key1 = "first"; const string key2 = "second"; const string key3 = "third"; const string key4 = "fourth"; const string key5 = "fifth"; JsonObject jo = new JsonObject { { key1, AnyInstance.AnyString }, { key2, AnyInstance.AnyBool }, { key3, null }, }; TestEvents( jo, obj => obj.Add(key4, 1), new List> { new Tuple(true, jo, new JsonValueChangeEventArgs(1, JsonValueChange.Add, key4)), new Tuple(false, jo, new JsonValueChangeEventArgs(1, JsonValueChange.Add, key4)), }); TestEvents( jo, obj => obj[key2] = 2, new List> { new Tuple(true, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Replace, key2)), new Tuple(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyBool, JsonValueChange.Replace, key2)), }); TestEvents( jo, obj => obj[key5] = 3, new List> { new Tuple(true, jo, new JsonValueChangeEventArgs(3, JsonValueChange.Add, key5)), new Tuple(false, jo, new JsonValueChangeEventArgs(3, JsonValueChange.Add, key5)), }); jo.Remove(key4); jo.Remove(key5); TestEvents( jo, obj => obj.AddRange(new JsonObject { { key4, AnyInstance.AnyString }, { key5, AnyInstance.AnyDouble } }), new List> { new Tuple(true, jo, new JsonValueChangeEventArgs(AnyInstance.AnyString, JsonValueChange.Add, key4)), new Tuple(true, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Add, key5)), new Tuple(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyString, JsonValueChange.Add, key4)), new Tuple(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Add, key5)), }); TestEvents( jo, obj => obj.Remove(key5), new List> { new Tuple(true, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Remove, key5)), new Tuple(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Remove, key5)), }); TestEvents( jo, obj => obj.Remove("not there"), new List>()); jo = new JsonObject { { key1, 1 }, { key2, 2 }, { key3, 3 } }; TestEvents( jo, obj => obj.Clear(), new List> { new Tuple(true, jo, new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null)), new Tuple(false, jo, new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null)), }); jo = new JsonObject { { key1, 1 }, { key2, 2 }, { key3, 3 } }; TestEvents( jo, obj => ((IDictionary)obj).Remove(new KeyValuePair(key2, jo[key2])), new List> { new Tuple(true, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Remove, key2)), new Tuple(false, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Remove, key2)), }); TestEvents( jo, obj => ((IDictionary)obj).Remove(new KeyValuePair("key not in object", jo[key1])), new List> { }); TestEvents( jo, obj => ((IDictionary)obj).Remove(new KeyValuePair(key1, "different object")), new List> { }); ExceptionHelper.Throws(() => new JsonValueChangeEventArgs(1, JsonValueChange.Add, null)); } [Fact] public void NestedChangingEventTest() { const string key1 = "first"; JsonObject target = new JsonObject { { key1, new JsonArray { 1, 2 } } }; JsonArray child = target[key1] as JsonArray; TestEvents( target, obj => ((JsonArray)obj[key1]).Add(5), new List>()); target = new JsonObject(); child = new JsonArray(1, 2); TestEvents( target, obj => { obj.Add(key1, child); ((JsonArray)obj[key1]).Add(5); }, new List> { new Tuple(true, target, new JsonValueChangeEventArgs(child, JsonValueChange.Add, key1)), new Tuple(false, target, new JsonValueChangeEventArgs(child, JsonValueChange.Add, key1)), }); } [Fact] public void MultipleListenersTest() { const string key1 = "first"; const string key2 = "second"; const string key3 = "third"; for (int changingListeners = 0; changingListeners <= 2; changingListeners++) { for (int changedListeners = 0; changedListeners <= 2; changedListeners++) { JsonArrayTest.MultipleListenersTestHelper( () => new JsonObject { { key1, 1 }, { key2, 2 } }, delegate(JsonObject obj) { obj[key2] = "hello"; obj.Remove(key1); obj.Add(key3, "world"); obj.Clear(); }, new List { new JsonValueChangeEventArgs("hello", JsonValueChange.Replace, key2), new JsonValueChangeEventArgs(1, JsonValueChange.Remove, key1), new JsonValueChangeEventArgs("world", JsonValueChange.Add, key3), new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null), }, new List { new JsonValueChangeEventArgs(2, JsonValueChange.Replace, key2), new JsonValueChangeEventArgs(1, JsonValueChange.Remove, key1), new JsonValueChangeEventArgs("world", JsonValueChange.Add, key3), new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null), }, changingListeners, changedListeners); } } } [Fact] public void JsonTypeTest() { JsonObject target = AnyInstance.AnyJsonObject; Assert.Equal(JsonType.Object, target.JsonType); } [Fact] public void KeysTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target = new JsonObject { { key1, value1 }, { key2, value2 } }; List expected = new List { key1, key2 }; List actual = new List(target.Keys); Assert.Equal(expected.Count, actual.Count); expected.Sort(); actual.Sort(); for (int i = 0; i < expected.Count; i++) { Assert.Equal(expected[i], actual[i]); } } [Fact] public void IsReadOnlyTest() { JsonObject target = AnyInstance.AnyJsonObject; Assert.False(((ICollection>)target).IsReadOnly); } [Fact] public void ValuesTest() { string key1 = AnyInstance.AnyString; string key2 = AnyInstance.AnyString2; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonValue value2 = AnyInstance.AnyJsonValue2; JsonObject target = new JsonObject { { key1, value1 }, { key2, value2 } }; List values = new List(target.Values); Assert.Equal(2, values.Count); bool value1IsFirst = value1 == values[0]; Assert.True(value1IsFirst || value1 == values[1]); Assert.Equal(value2, values[value1IsFirst ? 1 : 0]); } private static void ValidateJsonObjectItems(JsonObject jsonObject, params object[] keyValuePairs) { Dictionary expected = new Dictionary(); Assert.True((keyValuePairs.Length % 2) == 0, "Test error"); for (int i = 0; i < keyValuePairs.Length; i += 2) { Assert.IsType(keyValuePairs[i]); Assert.IsAssignableFrom(keyValuePairs[i + 1]); expected.Add((string)keyValuePairs[i], (JsonValue)keyValuePairs[i + 1]); } } private static void ValidateJsonObjectItems(JsonObject jsonObject, Dictionary expected) { Assert.Equal(expected.Count, jsonObject.Count); foreach (string key in expected.Keys) { Assert.True(jsonObject.ContainsKey(key)); Assert.Equal(expected[key], jsonObject[key]); } } private static void TestEvents(JsonObject obj, Action actionToTriggerEvent, List> expectedEvents) { JsonArrayTest.TestEvents(obj, actionToTriggerEvent, expectedEvents); } } }