public void RemoveTest() { JsonValue item1 = AnyInstance.AnyJsonValue1; JsonValue item2 = AnyInstance.AnyJsonValue2; JsonValue item3 = AnyInstance.AnyJsonValue3; JsonArray target = new JsonArray(item1, item2, item3); Assert.True(target.Remove(item2)); Assert.Equal(2, target.Count); Assert.Equal(item1, target[0]); Assert.Equal(item3, target[1]); Assert.False(target.Remove(item2)); Assert.Equal(2, target.Count); }
public void CountTest() { JsonValue item1 = AnyInstance.AnyJsonValue1; JsonValue item2 = AnyInstance.AnyJsonValue2; JsonArray target = new JsonArray(); Assert.Equal(0, target.Count); target.Add(item1); Assert.Equal(1, target.Count); target.Add(item2); Assert.Equal(2, target.Count); target.Remove(item1); Assert.Equal(1, target.Count); }
public void ContainsTest() { JsonValue item1 = AnyInstance.AnyJsonValue1; JsonValue item2 = AnyInstance.AnyJsonValue2; JsonArray target = new JsonArray(item1); Assert.True(target.Contains(item1)); Assert.False(target.Contains(item2)); target.Add(item2); Assert.True(target.Contains(item1)); Assert.True(target.Contains(item2)); target.Remove(item1); Assert.False(target.Contains(item1)); Assert.True(target.Contains(item2)); }
public void JsonArrayAddRemoveFunctionalTest() { 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; JsonArray sourceJson = SpecialJsonValueHelper.CreatePrePopulatedJsonArray(seed, arrayLength); JsonValue[] cloneJson = SpecialJsonValueHelper.CreatePrePopulatedJsonValueArray(seed, 3); // JsonArray.AddRange(JsonValue[]) sourceJson.AddRange(cloneJson); if (sourceJson.Count != arrayLength + cloneJson.Length) { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.AddRange(JsonValue[]) failed to function properly."); retValue = false; } else { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.AddRange(JsonValue[]) passed test."); } // JsonArray.RemoveAt(int) int count = sourceJson.Count; for (int j = 0; j < count; j++) { sourceJson.RemoveAt(0); } if (sourceJson.Count > 0) { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.RemoveAt(int) failed to function properly."); retValue = false; } else { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.RemoveAt(int) passed test."); } // JsonArray.JsonType if (sourceJson.JsonType != JsonType.Array) { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.JsonType failed to function properly."); retValue = false; } // JsonArray.Clear() sourceJson = SpecialJsonValueHelper.CreatePrePopulatedJsonArray(seed, arrayLength); sourceJson.Clear(); if (sourceJson.Count > 0) { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.Clear() failed to function properly."); retValue = false; } else { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.Clear() passed test."); } // JsonArray.AddRange(JsonValue) sourceJson = SpecialJsonValueHelper.CreatePrePopulatedJsonArray(seed, arrayLength); // adding one additional value to the array sourceJson.AddRange(SpecialJsonValueHelper.GetRandomJsonPrimitives(seed)); if (sourceJson.Count != arrayLength + 1) { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.AddRange(JsonValue) failed to function properly."); retValue = false; } else { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.AddRange(JsonValue) passed test."); } // JsonArray.AddRange(IEnumerable<JsonValue> items) sourceJson = SpecialJsonValueHelper.CreatePrePopulatedJsonArray(seed, arrayLength); MyJsonValueCollection <JsonValue> myCols = new MyJsonValueCollection <JsonValue>(); myCols.Add(new JsonPrimitive(PrimitiveCreator.CreateInstanceOfUInt32(rndGen))); string str; do { str = PrimitiveCreator.CreateInstanceOfString(rndGen); } while (str == null); myCols.Add(new JsonPrimitive(str)); myCols.Add(new JsonPrimitive(PrimitiveCreator.CreateInstanceOfDateTime(rndGen))); // adding 3 additional value to the array sourceJson.AddRange(myCols); if (sourceJson.Count != arrayLength + 3) { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.AddRange(IEnumerable<JsonValue> items) failed to function properly."); retValue = false; } else { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.AddRange(IEnumerable<JsonValue> items) passed test."); } // JsonArray[index].set_Item sourceJson = SpecialJsonValueHelper.CreatePrePopulatedJsonArray(seed, arrayLength); string temp; do { temp = PrimitiveCreator.CreateInstanceOfString(rndGen); } while (temp == null); sourceJson[1] = temp; if ((string)sourceJson[1] != temp) { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray[index].set_Item failed to function properly."); retValue = false; } else { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray[index].set_Item passed test."); } // JsonArray.Remove(JsonValue) count = sourceJson.Count; for (int j = 0; j < count; j++) { sourceJson.Remove(sourceJson[0]); } if (sourceJson.Count > 0) { Log.Info("[JsonArrayAddRemoveFunctionalTest] JsonArray.Remove(JsonValue) failed to function properly."); retValue = false; } Assert.True(retValue); } }