예제 #1
0
        public void DynamicEventsTest()
        {
            int       seed   = 1;
            int       maxObj = 10;
            JsonArray ja     = new JsonArray();
            dynamic   d      = ja.AsDynamic();

            TestEventsDynamic(
                d,
                (Action <dynamic>)(arr => arr.Add(1)),
                new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> >
            {
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, ja, new JsonValueChangeEventArgs(1, JsonValueChange.Add, 0)),
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, ja, new JsonValueChangeEventArgs(1, JsonValueChange.Add, 0)),
            });

            const string key1 = "first";
            const string key2 = "second";
            JsonObject   jo   = new JsonObject
            {
                { key1, SpecialJsonValueHelper.GetRandomJsonPrimitives(seed) },
            };

            JsonObject objectToAdd = SpecialJsonValueHelper.CreateRandomPopulatedJsonObject(seed, maxObj);
            dynamic    d2          = jo.AsDynamic();

            TestEventsDynamic(
                d2,
                (Action <dynamic>)(obj => obj[key2] = objectToAdd),
                new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> >
            {
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(objectToAdd, JsonValueChange.Add, key2)),
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(objectToAdd, JsonValueChange.Add, key2)),
            });

            TestEventsDynamic(
                d2,
                (Action <dynamic>)(obj => obj[key2] = objectToAdd),
                new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> >
            {
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(objectToAdd, JsonValueChange.Replace, key2)),
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(objectToAdd, JsonValueChange.Replace, key2)),
            });
        }