public void AddTest() { JsonArray target = new JsonArray(); JsonValue item = AnyInstance.AnyJsonValue1; Assert.False(target.Contains(item)); target.Add(item); Assert.Equal(1, target.Count); Assert.Equal(item, target[0]); Assert.True(target.Contains(item)); ExceptionHelper.Throws <ArgumentException>(() => target.Add(AnyInstance.DefaultJsonValue)); }
public void JsonArrayItemsFunctionalTest() { 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.Contains(JsonValue) // JsonArray.IndexOf(JsonValue) JsonArray sourceJson = SpecialJsonValueHelper.CreatePrePopulatedJsonArray(seed, arrayLength); for (int j = 0; j < sourceJson.Count; j++) { if (!sourceJson.Contains(sourceJson[j])) { Log.Info("[JsonArrayItemsFunctionalTest] JsonArray.Contains(JsonValue) failed to function properly."); retValue = false; } else { Log.Info("[JsonArrayItemsFunctionalTest] JsonArray.Contains(JsonValue) passed test."); } if (sourceJson.IndexOf(sourceJson[j]) != j) { Log.Info("[JsonArrayItemsFunctionalTest] JsonArray.IndexOf(JsonValue) failed to function properly."); retValue = false; } else { Log.Info("[JsonArrayItemsFunctionalTest] JsonArray.IndexOf(JsonValue) passed test."); } } // JsonArray.Insert(int, JsonValue) JsonValue newItem = SpecialJsonValueHelper.GetRandomJsonPrimitives(seed); sourceJson.Insert(3, newItem); if (sourceJson[3] != newItem || sourceJson.Count != arrayLength + 1) { Log.Info("[JsonArrayItemsFunctionalTest] JsonArray.Insert(int, JsonValue) failed to function properly."); retValue = false; } else { Log.Info("[JsonArrayItemsFunctionalTest] JsonArray.Insert(int, JsonValue) passed test."); } Assert.True(retValue); } }
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)); }