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); }
public void ValidJsonObjectRoundTrip() { bool oldValue = CreatorSettings.CreateDateTimeWithSubMilliseconds; CreatorSettings.CreateDateTimeWithSubMilliseconds = false; try { int seed = 1; Log.Info("Seed: {0}", seed); Random rndGen = new Random(seed); JsonObject sourceJson = new JsonObject(new Dictionary <string, JsonValue>() { { "Name", PrimitiveCreator.CreateInstanceOfString(rndGen) }, { "Age", PrimitiveCreator.CreateInstanceOfInt32(rndGen) }, { "DateTimeOffset", PrimitiveCreator.CreateInstanceOfDateTimeOffset(rndGen) }, { "Birthday", PrimitiveCreator.CreateInstanceOfDateTime(rndGen) } }); sourceJson.Add("NewItem1", PrimitiveCreator.CreateInstanceOfString(rndGen)); sourceJson.Add(new KeyValuePair <string, JsonValue>("NewItem2", PrimitiveCreator.CreateInstanceOfString(rndGen))); JsonObject newJson = (JsonObject)JsonValue.Parse(sourceJson.ToString()); newJson.Remove("NewItem1"); sourceJson.Remove("NewItem1"); Assert.False(newJson.ContainsKey("NewItem1")); Assert.False(!JsonValueVerifier.Compare(sourceJson, newJson)); } finally { CreatorSettings.CreateDateTimeWithSubMilliseconds = oldValue; } }
public void ValidJsonObjectRoundTrip() { bool oldValue = CreatorSettings.CreateDateTimeWithSubMilliseconds; CreatorSettings.CreateDateTimeWithSubMilliseconds = false; try { int seed = 1; Log.Info("Seed: {0}", seed); Random rndGen = new Random(seed); JsonObject sourceJson = new JsonObject(new Dictionary<string, JsonValue>() { { "Name", PrimitiveCreator.CreateInstanceOfString(rndGen) }, { "Age", PrimitiveCreator.CreateInstanceOfInt32(rndGen) }, { "DateTimeOffset", PrimitiveCreator.CreateInstanceOfDateTimeOffset(rndGen) }, { "Birthday", PrimitiveCreator.CreateInstanceOfDateTime(rndGen) } }); sourceJson.Add("NewItem1", PrimitiveCreator.CreateInstanceOfString(rndGen)); sourceJson.Add(new KeyValuePair<string, JsonValue>("NewItem2", PrimitiveCreator.CreateInstanceOfString(rndGen))); JsonObject newJson = (JsonObject)JsonValue.Parse(sourceJson.ToString()); newJson.Remove("NewItem1"); sourceJson.Remove("NewItem1"); Assert.False(newJson.ContainsKey("NewItem1")); Assert.False(!JsonValueVerifier.Compare(sourceJson, newJson)); } finally { CreatorSettings.CreateDateTimeWithSubMilliseconds = oldValue; } }
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); }
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 <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(1, JsonValueChange.Add, key4)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(1, JsonValueChange.Add, key4)), }); TestEvents( jo, obj => obj[key2] = 2, new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Replace, key2)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyBool, JsonValueChange.Replace, key2)), }); TestEvents( jo, obj => obj[key5] = 3, new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(3, JsonValueChange.Add, key5)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(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 <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(AnyInstance.AnyString, JsonValueChange.Add, key4)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Add, key5)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyString, JsonValueChange.Add, key4)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Add, key5)), }); TestEvents( jo, obj => obj.Remove(key5), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Remove, key5)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Remove, key5)), }); TestEvents( jo, obj => obj.Remove("not there"), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> >()); jo = new JsonObject { { key1, 1 }, { key2, 2 }, { key3, 3 } }; TestEvents( jo, obj => obj.Clear(), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null)), }); jo = new JsonObject { { key1, 1 }, { key2, 2 }, { key3, 3 } }; TestEvents( jo, obj => ((IDictionary <string, JsonValue>)obj).Remove(new KeyValuePair <string, JsonValue>(key2, jo[key2])), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Remove, key2)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Remove, key2)), }); TestEvents( jo, obj => ((IDictionary <string, JsonValue>)obj).Remove(new KeyValuePair <string, JsonValue>("key not in object", jo[key1])), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { }); TestEvents( jo, obj => ((IDictionary <string, JsonValue>)obj).Remove(new KeyValuePair <string, JsonValue>(key1, "different object")), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { }); ExceptionHelper.Throws <ArgumentNullException>(() => new JsonValueChangeEventArgs(1, JsonValueChange.Add, null)); }
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<Tuple<bool, JsonValue, JsonValueChangeEventArgs>> { new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(1, JsonValueChange.Add, key4)), new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(1, JsonValueChange.Add, key4)), }); TestEvents( jo, obj => obj[key2] = 2, new List<Tuple<bool, JsonValue, JsonValueChangeEventArgs>> { new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Replace, key2)), new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyBool, JsonValueChange.Replace, key2)), }); TestEvents( jo, obj => obj[key5] = 3, new List<Tuple<bool, JsonValue, JsonValueChangeEventArgs>> { new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(3, JsonValueChange.Add, key5)), new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(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<Tuple<bool, JsonValue, JsonValueChangeEventArgs>> { new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(AnyInstance.AnyString, JsonValueChange.Add, key4)), new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Add, key5)), new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyString, JsonValueChange.Add, key4)), new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Add, key5)), }); TestEvents( jo, obj => obj.Remove(key5), new List<Tuple<bool, JsonValue, JsonValueChangeEventArgs>> { new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Remove, key5)), new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(AnyInstance.AnyDouble, JsonValueChange.Remove, key5)), }); TestEvents( jo, obj => obj.Remove("not there"), new List<Tuple<bool, JsonValue, JsonValueChangeEventArgs>>()); jo = new JsonObject { { key1, 1 }, { key2, 2 }, { key3, 3 } }; TestEvents( jo, obj => obj.Clear(), new List<Tuple<bool, JsonValue, JsonValueChangeEventArgs>> { new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null)), new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null)), }); jo = new JsonObject { { key1, 1 }, { key2, 2 }, { key3, 3 } }; TestEvents( jo, obj => ((IDictionary<string, JsonValue>)obj).Remove(new KeyValuePair<string, JsonValue>(key2, jo[key2])), new List<Tuple<bool, JsonValue, JsonValueChangeEventArgs>> { new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Remove, key2)), new Tuple<bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Remove, key2)), }); TestEvents( jo, obj => ((IDictionary<string, JsonValue>)obj).Remove(new KeyValuePair<string, JsonValue>("key not in object", jo[key1])), new List<Tuple<bool, JsonValue, JsonValueChangeEventArgs>> { }); TestEvents( jo, obj => ((IDictionary<string, JsonValue>)obj).Remove(new KeyValuePair<string, JsonValue>(key1, "different object")), new List<Tuple<bool, JsonValue, JsonValueChangeEventArgs>> { }); ExceptionHelper.Throws<ArgumentNullException>(() => new JsonValueChangeEventArgs(1, JsonValueChange.Add, null)); }
public void JsonObjectAddRemoveFunctionalTest() { int seed = 1; for (int i = 0; i < iterationCount / 10; i++) { seed++; Log.Info("Seed: {0}", seed); Random rndGen = new Random(seed); bool retValue = true; JsonObject sourceJson = SpecialJsonValueHelper.CreateIndexPopulatedJsonObject(seed, arrayLength); // JsonObject.JsonType if (sourceJson.JsonType != JsonType.Object) { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonArray.JsonType failed to function properly."); retValue = false; } // JsonObject.Add(KeyValuePair<string, JsonValue> item) // JsonObject.Add(string key, JsonValue value) // + various numers below so .AddRange() won't try to add an already existing value sourceJson.Add(SpecialJsonValueHelper.GetUniqueNonNullInstanceOfString(seed + 3, sourceJson), SpecialJsonValueHelper.GetUniqueValue(seed, sourceJson)); KeyValuePair <string, JsonValue> kvp; int startingSeed = seed + 1; do { kvp = SpecialJsonValueHelper.CreatePrePopulatedKeyValuePair(startingSeed); startingSeed++; }while (sourceJson.ContainsKey(kvp.Key)); sourceJson.Add(kvp); do { kvp = SpecialJsonValueHelper.CreatePrePopulatedKeyValuePair(startingSeed); startingSeed++; }while (sourceJson.ContainsKey(kvp.Key)); sourceJson.Add(kvp); if (sourceJson.Count != arrayLength + 3) { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.Add() failed to function properly."); retValue = false; } else { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.Add() passed test."); } // JsonObject.Clear() sourceJson.Clear(); if (sourceJson.Count > 0) { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.Clear() failed to function properly."); retValue = false; } else { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.Clear() passed test."); } // JsonObject.AddRange(IEnumerable<KeyValuePair<string, JsonValue>> items) sourceJson = SpecialJsonValueHelper.CreateIndexPopulatedJsonObject(seed, arrayLength); // + various numers below so .AddRange() won't try to add an already existing value sourceJson.AddRange(SpecialJsonValueHelper.CreatePrePopulatedListofKeyValuePair(seed + 13 + (arrayLength * 2), 5)); if (sourceJson.Count != arrayLength + 5) { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.AddRange(IEnumerable<KeyValuePair<string, JsonValue>> items) failed to function properly."); retValue = false; } else { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.AddRange(IEnumerable<KeyValuePair<string, JsonValue>> items) passed test."); } // JsonObject.AddRange(params KeyValuePair<string, JsonValue>[] items) sourceJson = SpecialJsonValueHelper.CreateIndexPopulatedJsonObject(seed, arrayLength); // + various numers below so .AddRange() won't try to add an already existing value KeyValuePair <string, JsonValue> item1 = SpecialJsonValueHelper.CreatePrePopulatedKeyValuePair(seed + arrayLength + 41); KeyValuePair <string, JsonValue> item2 = SpecialJsonValueHelper.CreatePrePopulatedKeyValuePair(seed + arrayLength + 47); KeyValuePair <string, JsonValue> item3 = SpecialJsonValueHelper.CreatePrePopulatedKeyValuePair(seed + arrayLength + 53); sourceJson.AddRange(new KeyValuePair <string, JsonValue>[] { item1, item2, item3 }); if (sourceJson.Count != arrayLength + 3) { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.AddRange(params KeyValuePair<string, JsonValue>[] items) failed to function properly."); retValue = false; } else { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.AddRange(params KeyValuePair<string, JsonValue>[] items) passed test."); } sourceJson.Clear(); // JsonObject.Remove(Key) sourceJson = SpecialJsonValueHelper.CreateIndexPopulatedJsonObject(seed, arrayLength); int count = sourceJson.Count; List <string> keys = new List <string>(sourceJson.Keys); foreach (string key in keys) { sourceJson.Remove(key); } if (sourceJson.Count > 0) { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.Remove(Key) failed to function properly."); retValue = false; } else { Log.Info("[JsonObjectAddRemoveFunctionalTest] JsonObject.Remove(Key) passed test."); } Assert.True(retValue); } }
/// <summary> /// 由Json串给对象赋值,将递归进行调用,碰到JsonArray自动把JsonArray转换成ObjectList。 /// 碰到JsonObject,自动转换成GeneralOject。 /// </summary> /// <param name="item">从这个json对象给对象属性赋值</param> public void FromJson(JsonObject item) { //通过获取类型,给_ctype赋值 this.NewGetType(); //如果有实体类型,则设置实体类型 if (item.ContainsKey("EntityType")) { EntityType = item["EntityType"]; item.Remove("EntityType"); } foreach (string key in item.Keys) { object value = item[key]; Log.Debug("from json name=" + this.Name); if (key.Equals("id")) { Log.Debug("from json id=" + value); } //如果是数组,对数组中的每一个对象调用转换过程 if (value is JsonArray) { //数组转换成对象列表 ObjectList ol = new ObjectList(); ol.FromJson(value as JsonArray); SetCollectionProperty(key, ol); } else if (value is JsonObject) { //JsonObject转换成一般对象 GeneralObject go = new GeneralObject(); go.FromJson(value as JsonObject); SetPropertyValue(key, go, true); } else if (value is JsonPrimitive) { this.NewGetType().GetProperty(key).SetValue(this, value as JsonPrimitive, null); } else if (value == null) { SetPropertyValue(key, null, true); } else { throw new Exception("类型错误"); } } //新加载的对象为未修改 IsModified = false; }
public void JsonObjectEventsTest() { int seed = 1; const int maxObj = 10; 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, SpecialJsonValueHelper.GetRandomJsonPrimitives(seed) }, { key2, SpecialJsonValueHelper.GetRandomJsonPrimitives(seed) }, { key3, null }, }; JsonObject objToAdd = SpecialJsonValueHelper.CreateRandomPopulatedJsonObject(seed, maxObj); TestEvents( jo, obj => obj.Add(key4, objToAdd), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(objToAdd, JsonValueChange.Add, key4)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(objToAdd, JsonValueChange.Add, key4)), }, obj => obj.Add("key44", objToAdd)); JsonArray jaToAdd = SpecialJsonValueHelper.CreatePrePopulatedJsonArray(seed, maxObj); JsonValue replaced = jo[key2]; TestEvents( jo, obj => obj[key2] = jaToAdd, new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(jaToAdd, JsonValueChange.Replace, key2)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(replaced, JsonValueChange.Replace, key2)), }); JsonValue jpToAdd = SpecialJsonValueHelper.GetRandomJsonPrimitives(seed); TestEvents( jo, obj => obj[key5] = jpToAdd, new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(jpToAdd, JsonValueChange.Add, key5)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(jpToAdd, JsonValueChange.Add, key5)), }); jo.Remove(key4); jo.Remove(key5); JsonValue jp1 = SpecialJsonValueHelper.GetRandomJsonPrimitives(seed); JsonValue jp2 = SpecialJsonValueHelper.GetRandomJsonPrimitives(seed); TestEvents( jo, obj => obj.AddRange(new JsonObject { { key4, jp1 }, { key5, jp1 } }), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(jp1, JsonValueChange.Add, key4)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(jp2, JsonValueChange.Add, key5)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(jp1, JsonValueChange.Add, key4)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(jp2, JsonValueChange.Add, key5)), }, obj => obj.AddRange(new JsonObject { { "new key", jp1 }, { "newnewKey", jp2 } })); TestEvents( jo, obj => obj.Remove(key5), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(jp2, JsonValueChange.Remove, key5)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(jp2, JsonValueChange.Remove, key5)), }); TestEvents( jo, obj => obj.Remove("not there"), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> >()); jo = new JsonObject { { key1, 1 }, { key2, 2 }, { key3, 3 } }; TestEvents( jo, obj => obj.Clear(), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(null, JsonValueChange.Clear, null)), }); jo = new JsonObject { { key1, 1 }, { key2, 2 }, { key3, 3 } }; TestEvents( jo, obj => ((IDictionary <string, JsonValue>)obj).Remove(new KeyValuePair <string, JsonValue>(key2, jo[key2])), new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> > { new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Remove, key2)), new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(2, JsonValueChange.Remove, key2)), }, obj => ((IDictionary <string, JsonValue>)obj).Remove(new KeyValuePair <string, JsonValue>(key1, jo[key1]))); }