Esempio n. 1
0
        public void IndexOfTest()
        {
            JsonValue item1  = AnyInstance.AnyJsonValue1;
            JsonValue item2  = AnyInstance.AnyJsonValue2;
            JsonValue item3  = AnyInstance.AnyJsonValue3;
            JsonArray target = new JsonArray(item1, item2);

            Assert.Equal(0, target.IndexOf(item1));
            Assert.Equal(1, target.IndexOf(item2));
            Assert.Equal(-1, target.IndexOf(item3));
        }
        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);
            }
        }