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 <ArgumentNullException>(delegate { new JsonObject().ContainsKey(null); }); }
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)); }
public void ContainsKeyTest() { string key1 = AnyInstance.AnyString; JsonValue value1 = AnyInstance.AnyJsonValue1; JsonObject target = new JsonObject(); Assert.IsFalse(target.ContainsKey(key1)); target.Add(key1, value1); Assert.IsTrue(target.ContainsKey(key1)); target.Clear(); Assert.IsFalse(target.ContainsKey(key1)); ExceptionTestHelper.ExpectException<ArgumentNullException>(delegate { new JsonObject().ContainsKey(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); } }
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.AreEqual(0, target.Count); Assert.IsFalse(target.ContainsKey(key1)); target.Add(key2, value2); Assert.AreEqual(1, target.Count); Assert.IsFalse(target.ContainsKey(key1)); Assert.IsTrue(target.ContainsKey(key2)); }