public void CopyToTest()
        {
            string    key1   = AnyInstance.AnyString;
            string    key2   = AnyInstance.AnyString2;
            JsonValue value1 = AnyInstance.AnyJsonValue1;
            JsonValue value2 = AnyInstance.AnyJsonValue2;

            JsonObject target = new JsonObject {
                { key1, value1 }, { key2, value2 }
            };

            KeyValuePair <string, JsonValue>[] array = new KeyValuePair <string, JsonValue> [target.Count + 1];

            target.CopyTo(array, 1);
            int index1 = key1 == array[1].Key ? 1 : 2;
            int index2 = index1 == 1 ? 2 : 1;

            Assert.Equal(key1, array[index1].Key);
            Assert.Equal(value1, array[index1].Value);
            Assert.Equal(key2, array[index2].Key);
            Assert.Equal(value2, array[index2].Value);

            ExceptionHelper.Throws <ArgumentNullException>(() => target.CopyTo(null, 0));
            ExceptionHelper.Throws <ArgumentOutOfRangeException>(() => target.CopyTo(array, -1));
            ExceptionHelper.Throws <ArgumentException>(() => target.CopyTo(array, array.Length - target.Count + 1));
        }
        public void JsonObjectCopytoFunctionalTest()
        {
            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);
                KeyValuePair <string, JsonValue>[] destJson = new KeyValuePair <string, JsonValue> [arrayLength];
                if (sourceJson != null && destJson != null)
                {
                    sourceJson.CopyTo(destJson, 0);
                }
                else
                {
                    Log.Info("[JsonObjectCopytoFunctionalTest] sourceJson.ToString() = " + sourceJson.ToString());
                    Log.Info("[JsonObjectCopytoFunctionalTest] destJson.ToString() = " + destJson.ToString());
                    Assert.False(true, "[JsonObjectCopytoFunctionalTest] failed to create the source JsonObject object.");
                    return;
                }

                if (destJson.Length == arrayLength)
                {
                    for (int k = 0; k < destJson.Length; k++)
                    {
                        JsonValue temp;
                        sourceJson.TryGetValue(k.ToString(), out temp);
                        if (!(temp != null && destJson[k].Value == temp))
                        {
                            retValue = false;
                        }
                    }
                }
                else
                {
                    retValue = false;
                }

                Assert.True(retValue, "[JsonObjectCopytoFunctionalTest] JsonObject.CopyTo() failed to function properly. destJson.GetLength(0) = " + destJson.GetLength(0));
            }
        }
示例#3
0
        public void CopyToTest()
        {
            string key1 = AnyInstance.AnyString;
            string key2 = AnyInstance.AnyString2;
            JsonValue value1 = AnyInstance.AnyJsonValue1;
            JsonValue value2 = AnyInstance.AnyJsonValue2;

            JsonObject target = new JsonObject { { key1, value1 }, { key2, value2 } };

            KeyValuePair<string, JsonValue>[] array = new KeyValuePair<string, JsonValue>[target.Count + 1];

            target.CopyTo(array, 1);
            int index1 = key1 == array[1].Key ? 1 : 2;
            int index2 = index1 == 1 ? 2 : 1;

            Assert.AreEqual(key1, array[index1].Key);
            Assert.AreEqual(value1, array[index1].Value);
            Assert.AreEqual(key2, array[index2].Key);
            Assert.AreEqual(value2, array[index2].Value);

            ExceptionTestHelper.ExpectException<ArgumentNullException>(() => target.CopyTo(null, 0));
            ExceptionTestHelper.ExpectException<ArgumentOutOfRangeException>(() => target.CopyTo(array, -1));
            ExceptionTestHelper.ExpectException<ArgumentException>(() => target.CopyTo(array, array.Length - target.Count + 1));
        }