Exemplo n.º 1
0
 public void Add()
 {
     JsonArray array = new JsonArray();
     JsonValue value = new JsonPrimitive(true);
     array.Add(value);
     Assert.Equal(1, array.Count);
     Assert.Same(value, array[0]);
 }
Exemplo n.º 2
0
 public void Add_NullItem_ThrowsArgumentNullException()
 {
     JsonArray array = new JsonArray();
     Assert.Throws<ArgumentNullException>("item", () => array.Add(null));
 }
        public void DataContractSerializerTest()
        {
            ValidateSerialization(new JsonPrimitive(DateTime.Now));
            ValidateSerialization(new JsonObject { { "a", 1 }, { "b", 2 }, { "c", 3 } });
            ValidateSerialization(new JsonArray { "a", "b", "c", 1, 2, 3 });

            JsonObject beforeObject = new JsonObject { { "a", 1 }, { "b", 2 }, { "c", 3 } };
            JsonObject afterObject1 = (JsonObject)ValidateSerialization(beforeObject);
            beforeObject.Add("d", 4);
            afterObject1.Add("d", 4);
            Assert.Equal(beforeObject.ToString(), afterObject1.ToString());

            JsonObject afterObject2 = (JsonObject)ValidateSerialization(beforeObject);
            beforeObject.Add("e", 5);
            afterObject2.Add("e", 5);
            Assert.Equal(beforeObject.ToString(), afterObject2.ToString());

            JsonArray beforeArray = new JsonArray { "a", "b", "c" };
            JsonArray afterArray1 = (JsonArray)ValidateSerialization(beforeArray);
            beforeArray.Add("d");
            afterArray1.Add("d");
            Assert.Equal(beforeArray.ToString(), afterArray1.ToString());

            JsonArray afterArray2 = (JsonArray)ValidateSerialization(beforeArray);
            beforeArray.Add("e");
            afterArray2.Add("e");
            Assert.Equal(beforeArray.ToString(), afterArray2.ToString());
        }