Exemplo n.º 1
0
        /// <summary>
        /// Runs a single JsonReaderTestCaseDescriptor test.
        /// </summary>
        /// <param name="testCase">The test case descriptor to run.</param>
        /// <param name="testConfiguration">The test configuration to use.</param>
        /// <param name="jsonValueComparer">The comparer to use to compare JSON OMs.</param>
        /// <param name="assert">The assertion handler.</param>
        public static void ReadAndVerifyJson(
            JsonReaderTestCaseDescriptor testCase,
            JsonReaderTestConfiguration testConfiguration,
            IJsonValueComparer jsonValueComparer,
            AssertionHandler assert,
            IExceptionVerifier exceptionVerifier)
        {
            TextReader testReader = new TestTextReader(new StringReader(testCase.JsonText))
            {
                FailOnPeek = true,
                FailOnSingleCharacterRead = true,
                ReadSizesEnumerator       = testConfiguration.ReadSizes.EndLessLoop()
            };

            JsonValue actualJsonResult = null;

            assert.ExpectedException(() =>
            {
                JsonReader jsonReader = testConfiguration.JsonReaderCreatorFunc(testReader, assert);
                actualJsonResult      = ReadJson(jsonReader, assert);
            },
                                     testCase.ExpectedException,
                                     exceptionVerifier);

            if (testCase.ExpectedException == null)
            {
                if (testCase.FragmentExtractor != null)
                {
                    actualJsonResult = testCase.FragmentExtractor(actualJsonResult);
                }

                jsonValueComparer = new JsonValueComparer();
                jsonValueComparer.Compare(testCase.ExpectedJson, actualJsonResult);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs a single JsonReaderTestCaseDescriptor test.
        /// </summary>
        /// <param name="testCase">The test case descriptor to run.</param>
        /// <param name="testConfiguration">The test configuration to use.</param>
        /// <param name="jsonValueComparer">The comparer to use to compare JSON OMs.</param>
        /// <param name="assert">The assertion handler.</param>
        public static void ReadAndVerifyJson(
            JsonReaderTestCaseDescriptor testCase, 
            JsonReaderTestConfiguration testConfiguration, 
            IJsonValueComparer jsonValueComparer, 
            AssertionHandler assert,
            IExceptionVerifier exceptionVerifier)
        {
            TextReader testReader = new TestTextReader(new StringReader(testCase.JsonText))
            {
                FailOnPeek = true,
                FailOnSingleCharacterRead = true,
                ReadSizesEnumerator = testConfiguration.ReadSizes.EndLessLoop()
            };

            JsonValue actualJsonResult = null;
            assert.ExpectedException(() =>
                {
                    JsonReader jsonReader = testConfiguration.JsonReaderCreatorFunc(testReader, assert);
                    actualJsonResult = ReadJson(jsonReader, assert);
                },
                testCase.ExpectedException,
                exceptionVerifier);

            if (testCase.ExpectedException == null)
            {
                if (testCase.FragmentExtractor != null)
                {
                    actualJsonResult = testCase.FragmentExtractor(actualJsonResult);
                }

                jsonValueComparer = new JsonValueComparer();
                jsonValueComparer.Compare(testCase.ExpectedJson, actualJsonResult);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generates interesting payloads for property cases.
        /// </summary>
        /// <param name="propertyPayloadTestCase">The property test case, where the JsonText represents
        /// a single property and ExpectedJson is a JsonProperty instance.</param>
        /// <returns>Enumeration of all interesting test cases.</returns>
        public static IEnumerable <JsonReaderTestCaseDescriptor> PropertyPayloads(JsonReaderTestCaseDescriptor propertyTestCase)
        {
            Debug.Assert(
                propertyTestCase.ExpectedJson is JsonProperty || propertyTestCase.ExpectedException != null,
                "This method only works on property test cases.");

            // The property alone in an object
            yield return(new JsonReaderTestCaseDescriptor(propertyTestCase)
            {
                JsonText = "^{^" + propertyTestCase.JsonText + "^}^",
                FragmentExtractor = (json) => json.Object().Properties.First()
            });

            // The property surrounded by other properties
            yield return(new JsonReaderTestCaseDescriptor(propertyTestCase)
            {
                JsonText = "^{^\"firstprop\"^:^1^,^" + propertyTestCase.JsonText + "^,^\"lastprop\"^:^2^}^",
                FragmentExtractor = (json) => json.Object().Properties.Skip(1).First()
            });

            // The property as first property followed by another.
            yield return(new JsonReaderTestCaseDescriptor(propertyTestCase)
            {
                JsonText = "^{^" + propertyTestCase.JsonText + "^,^\"lastprop\"^:^2^}^",
                FragmentExtractor = (json) => json.Object().Properties.First()
            });

            // The property as last property preceded by another
            yield return(new JsonReaderTestCaseDescriptor(propertyTestCase)
            {
                JsonText = "^{^\"firstprop\"^:^1^,^" + propertyTestCase.JsonText + "^}^",
                FragmentExtractor = (json) => json.Object().Properties.Skip(1).First()
            });
        }
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="other">The other test case to copy values from.</param>
 public JsonReaderTestCaseDescriptor(JsonReaderTestCaseDescriptor other)
 {
     this.JsonText = other.JsonText;
     this.ExpectedJson = other.ExpectedJson;
     this.FragmentExtractor = other.FragmentExtractor;
     this.ExpectedException = other.ExpectedException;
     this.DisablePayloadCombinations = other.DisablePayloadCombinations;
 }
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="other">The other test case to copy values from.</param>
 public JsonReaderTestCaseDescriptor(JsonReaderTestCaseDescriptor other)
 {
     this.JsonText                   = other.JsonText;
     this.ExpectedJson               = other.ExpectedJson;
     this.FragmentExtractor          = other.FragmentExtractor;
     this.ExpectedException          = other.ExpectedException;
     this.DisablePayloadCombinations = other.DisablePayloadCombinations;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Generates interesting payloads for JSON values.
        /// </summary>
        /// <param name="primitiveValuePayloadTestCase">The value test case, where the JsonText represents
        /// a single value and ExpectedJson is a JsonValue instance.</param>
        /// <returns>Enumeration of all interesting test cases.</returns>
        public static IEnumerable <JsonReaderTestCaseDescriptor> ValuePayloads(JsonReaderTestCaseDescriptor valueTestCase)
        {
            Debug.Assert(
                valueTestCase.ExpectedJson is JsonValue || valueTestCase.ExpectedException != null,
                "This method only works on value test cases.");

            // The value itself at the root - just add whitespace marks around it.
            yield return(new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^" + valueTestCase.JsonText + "^"
            });

            // Value in an array - the only element
            yield return(new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^[^" + valueTestCase.JsonText + "^]^",
                FragmentExtractor = (json) => json.Array().Elements.First()
            });

            // Value in an array - surrounded by other elements
            yield return(new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^[^\"before\"^,^" + valueTestCase.JsonText + "^,42^]^",
                FragmentExtractor = (json) => json.Array().Elements.Skip(1).First()
            });

            // Value in a nested array
            yield return(new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^[^[^" + valueTestCase.JsonText + "^]^]^",
                FragmentExtractor = (json) => json.Array().Elements.First().Array().Elements.First()
            });

            // Value of a property in an object
            yield return(new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^{^\"propertyName\"^:^" + valueTestCase.JsonText + "^}^",
                FragmentExtractor = (json) => json.Object().Properties.First().Value
            });

            // Value of a property in an nested object
            yield return(new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^{^\"child\":^{^\"propertyName\"^:^" + valueTestCase.JsonText + "^}^}^",
                FragmentExtractor = (json) => json.Object().Properties.First().Value.Object().Properties.First().Value
            });

            // Value in an array in an object in an array
            yield return(new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^[^42,^{^\"propertyName\"^:^[^" + valueTestCase.JsonText + "^,^{^}^]^}^,^[^]^]^",
                FragmentExtractor = (json) => json.Array().Elements.Skip(1).First().Object().Properties.First().Value.Array().Elements.First()
            });
        }
Exemplo n.º 7
0
        /// <summary>
        /// Generates interesting payloads for JSON values.
        /// </summary>
        /// <param name="primitiveValuePayloadTestCase">The value test case, where the JsonText represents 
        /// a single value and ExpectedJson is a JsonValue instance.</param>
        /// <returns>Enumeration of all interesting test cases.</returns>
        public static IEnumerable<JsonReaderTestCaseDescriptor> ValuePayloads(JsonReaderTestCaseDescriptor valueTestCase)
        {
            Debug.Assert(
                valueTestCase.ExpectedJson is JsonValue || valueTestCase.ExpectedException != null,
                "This method only works on value test cases.");

            // The value itself at the root - just add whitespace marks around it.
            yield return new JsonReaderTestCaseDescriptor(valueTestCase) { JsonText = "^" + valueTestCase.JsonText + "^" };

            // Value in an array - the only element
            yield return new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^[^" + valueTestCase.JsonText + "^]^",
                FragmentExtractor = (json) => json.Array().Elements.First()
            };

            // Value in an array - surrounded by other elements
            yield return new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^[^\"before\"^,^" + valueTestCase.JsonText + "^,42^]^",
                FragmentExtractor = (json) => json.Array().Elements.Skip(1).First()
            };

            // Value in a nested array
            yield return new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^[^[^" + valueTestCase.JsonText + "^]^]^",
                FragmentExtractor = (json) => json.Array().Elements.First().Array().Elements.First()
            };

            // Value of a property in an object
            yield return new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^{^\"propertyName\"^:^" + valueTestCase.JsonText + "^}^",
                FragmentExtractor = (json) => json.Object().Properties.First().Value
            };

            // Value of a property in an nested object
            yield return new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^{^\"child\":^{^\"propertyName\"^:^" + valueTestCase.JsonText + "^}^}^",
                FragmentExtractor = (json) => json.Object().Properties.First().Value.Object().Properties.First().Value
            };

            // Value in an array in an object in an array
            yield return new JsonReaderTestCaseDescriptor(valueTestCase)
            {
                JsonText = "^[^42,^{^\"propertyName\"^:^[^" + valueTestCase.JsonText + "^,^{^}^]^}^,^[^]^]^",
                FragmentExtractor = (json) => json.Array().Elements.Skip(1).First().Object().Properties.First().Value.Array().Elements.First()
            };
        }
Exemplo n.º 8
0
        /// <summary>
        /// Generates interesting payloads by replacing the whitespace marks (^) with different kinds of whitespaces.
        /// If two consecutive marks are used (^^) it means that this needs to be replaced with non-empty whitespace.
        /// </summary>
        /// <param name="testCase">The test case to process.</param>
        /// <returns>Enumeration of interesting test cases.</returns>
        public static IEnumerable <JsonReaderTestCaseDescriptor> WhitespacePaylods(JsonReaderTestCaseDescriptor testCase)
        {
            var whitespaces = new string[][]
            {
                new string [] { "" },
                new string [] { " " },
                new string [] { " ", "\t", "\n", "\r" },
                new string [] { "  \t", "\r\n", "\t\t", "     \r\n\t" }
            };

            return(whitespaces.Select(ws =>
                                      new JsonReaderTestCaseDescriptor(testCase)
            {
                JsonText = ReplaceWhitespaceMarks(testCase.JsonText, ws.EndLessLoop())
            }));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Generates interesting payloads by replacing the whitespace marks (^) with different kinds of whitespaces.
        /// If two consecutive marks are used (^^) it means that this needs to be replaced with non-empty whitespace.
        /// </summary>
        /// <param name="testCase">The test case to process.</param>
        /// <returns>Enumeration of interesting test cases.</returns>
        public static IEnumerable<JsonReaderTestCaseDescriptor> WhitespacePaylods(JsonReaderTestCaseDescriptor testCase)
        {
            var whitespaces = new string[][]
            {
                new string [] { "" },
                new string [] { " " },
                new string [] { " ", "\t", "\n", "\r" },
                new string [] { "  \t", "\r\n", "\t\t", "     \r\n\t" }
            };

            return whitespaces.Select(ws => 
                new JsonReaderTestCaseDescriptor(testCase) 
                { 
                    JsonText = ReplaceWhitespaceMarks(testCase.JsonText, ws.EndLessLoop()) 
                });
        }
Exemplo n.º 10
0
        public void PropertyTests()
        {
            IEnumerable <JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"foo\"^:^42",
                    ExpectedJson = new JsonProperty("foo", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\'foo\'^:^42",
                    ExpectedJson = new JsonProperty("foo", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "foo^:^42",
                    ExpectedJson = new JsonProperty("foo", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "_$32a$_^:^42",
                    ExpectedJson = new JsonProperty("_$32a$_", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "$a32^:^42",
                    ExpectedJson = new JsonProperty("$a32", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "32^:^42",
                    ExpectedJson = new JsonProperty("32", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "_^:^42",
                    ExpectedJson = new JsonProperty("_", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "$^:^42",
                    ExpectedJson = new JsonProperty("$", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\" \"^:^42",
                    ExpectedJson = new JsonProperty(" ", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\'\t\'^:^42",
                    ExpectedJson = new JsonProperty("\t", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"\r\n\t   \"^:^42",
                    ExpectedJson = new JsonProperty("\r\n\t   ", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\'\\r\\n\\t   \'^:^42",
                    ExpectedJson = new JsonProperty("\r\n\t   ", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = new string('a', 5 * 1024) + "^:^42",
                    ExpectedJson = new JsonProperty(new string('a', 5 * 1024), new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"\"^:^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidPropertyNameOrUnexpectedComma", string.Empty),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\'\'^:^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidPropertyNameOrUnexpectedComma", string.Empty),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "^:^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidPropertyNameOrUnexpectedComma", string.Empty),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"foo\"^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingColon", "foo"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{\"foo\"",
                    DisablePayloadCombinations = true,
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_MissingColon", "foo"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{\"foo\"  ",
                    DisablePayloadCombinations = true,
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_MissingColon", "foo"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"foo\"^,^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingColon", "foo"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"foo\"^:^,^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Property"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{\"foo\":",
                    DisablePayloadCombinations = true,
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_EndOfInputWithOpenScope"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.PropertyPayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
            {
                JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
            });
        }
Exemplo n.º 11
0
        public void ObjectTests()
        {
            IEnumerable <JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "{^}",
                    ExpectedJson = new JsonObject()
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "{^\"foo\"^:^42^}",
                    ExpectedJson = new JsonObject()
                    {
                        new JsonProperty("foo", new JsonPrimitiveValue(42))
                    }
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "{^\"foo\"^:^42^,^\"bar\"^:^\"some\"^}",
                    ExpectedJson = new JsonObject()
                    {
                        new JsonProperty("foo", new JsonPrimitiveValue(42)), new JsonProperty("bar", new JsonPrimitiveValue("some"))
                    }
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{,",
                    DisablePayloadCombinations = true,
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_EndOfInputWithOpenScope"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "{^,^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "{^\"foo\"^:^42^,^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "{^,^\"foo\"^:^42^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "{^,^,^\"foo\"^:^42^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "{^\"foo\"^:^42^^\"bar\"^:^43^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "{^\"foo\"^:^42^\"bar\"^:^43^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "{^\"foo\"^:^{}^\"bar\"^:^43^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Object"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.ValuePayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
            {
                JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
            });
        }
Exemplo n.º 12
0
        public void StringPrimitiveValueTest()
        {
            IEnumerable <JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"some\"",
                    ExpectedJson = new JsonPrimitiveValue("some")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"\"",
                    ExpectedJson = new JsonPrimitiveValue("")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\'some\'",
                    ExpectedJson = new JsonPrimitiveValue("some")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\'\'",
                    ExpectedJson = new JsonPrimitiveValue("")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"so'me\"",
                    ExpectedJson = new JsonPrimitiveValue("so'me")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\'so\\\"me\'",
                    ExpectedJson = new JsonPrimitiveValue("so\"me")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"\\'\\\"\"",
                    ExpectedJson = new JsonPrimitiveValue("\'\"")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\'\\'\\\"\'",
                    ExpectedJson = new JsonPrimitiveValue("\'\"")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"some\\b\\f\\n\\r\\t\\\\\\/\"",
                    ExpectedJson = new JsonPrimitiveValue("some\b\f\n\r\t\\/")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"some\\baa\\faa\\naa\\raa\\taa\\\\aa\\/aa\"",
                    ExpectedJson = new JsonPrimitiveValue("some\baa\faa\naa\raa\taa\\aa/aa")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"aa\\u0020aa\"",
                    ExpectedJson = new JsonPrimitiveValue("aa aa")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"aa\\u006d\\u006Daa\"",
                    ExpectedJson = new JsonPrimitiveValue("aammaa")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "\"" + new string('a', 5 * 1024) + "\"",
                    ExpectedJson = new JsonPrimitiveValue(new string('a', 5 * 1024))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"some",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\'some",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"some\\\"",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\'some\\\'",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\",
                    DisablePayloadCombinations = true,
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"aa\\g\"",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\g"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\u\"",
                    DisablePayloadCombinations = true,
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\uXXXX"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\u123",
                    DisablePayloadCombinations = true,
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\uXXXX"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"aa\\uzzzz\"",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\uzzzz"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"aa\\u-123",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\u-123"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "\"aa\\u0020",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.ValuePayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
            {
                JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
            });
        }
Exemplo n.º 13
0
        public void ArrayTests()
        {
            IEnumerable <JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "[^]",
                    ExpectedJson = new JsonArray()
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "[^42^]",
                    ExpectedJson = new JsonArray()
                    {
                        new JsonPrimitiveValue(42)
                    }
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "[^42^,^43^]",
                    ExpectedJson = new JsonArray()
                    {
                        new JsonPrimitiveValue(42), new JsonPrimitiveValue(43)
                    }
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[,",
                    DisablePayloadCombinations = true,
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_EndOfInputWithOpenScope"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "[^,^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "[^42^,^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "[^,^42^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "[^,^,^42^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "[^42^^43^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "[^42[]^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "[^{}42^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Array"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.ValuePayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
            {
                JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
            });
        }
Exemplo n.º 14
0
        public void NumberPrimitiveTests()
        {
            IEnumerable <JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "42",
                    ExpectedJson = new JsonPrimitiveValue((int)42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "0",
                    ExpectedJson = new JsonPrimitiveValue((int)0)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "-42",
                    ExpectedJson = new JsonPrimitiveValue((int)-42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = Int32.MaxValue.ToString(),
                    ExpectedJson = new JsonPrimitiveValue(Int32.MaxValue)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = Int32.MinValue.ToString(),
                    ExpectedJson = new JsonPrimitiveValue(Int32.MinValue)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "42.42",
                    ExpectedJson = new JsonPrimitiveValue((double)42.42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = ".42",
                    ExpectedJson = new JsonPrimitiveValue((double).42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "-42.42",
                    ExpectedJson = new JsonPrimitiveValue((double)-42.42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "42.3e-2",
                    ExpectedJson = new JsonPrimitiveValue((double)42.3e-2)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "42.3E-2",
                    ExpectedJson = new JsonPrimitiveValue((double)42.3e-2)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "42.3E+2",
                    ExpectedJson = new JsonPrimitiveValue((double)42.3e+2)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText     = "0005.2",
                    ExpectedJson = new JsonPrimitiveValue((double)5.2)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "42-3",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidNumberFormat", "42-3"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "42..3",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidNumberFormat", "42..3"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText          = "4e3e3",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidNumberFormat", "4e3e3"),
                },
                // Number is only up to the first non-number character
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42a",
                    DisablePayloadCombinations = true,  // We need this since the error is different when inside an array or so.
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_MultipleTopLevelValues"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42   4",
                    DisablePayloadCombinations = true,  // We need this since the error is different when inside an array or so.
                    ExpectedException          = ODataExpectedExceptions.ODataException("JsonReader_MultipleTopLevelValues"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.ValuePayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
            {
                JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
            });
        }
Exemplo n.º 15
0
        public void ArrayTests()
        {
            IEnumerable<JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^]",
                    ExpectedJson = new JsonArray()
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^42^]",
                    ExpectedJson = new JsonArray() { new JsonPrimitiveValue(42) }
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^42^,^43^]",
                    ExpectedJson = new JsonArray() { new JsonPrimitiveValue(42), new JsonPrimitiveValue(43) }
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[,",
                    DisablePayloadCombinations = true,
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_EndOfInputWithOpenScope"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^,^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^42^,^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^,^42^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^,^,^42^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^42^^43^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^42[]^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Array"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "[^{}42^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Array"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.ValuePayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
                {
                    JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
                });
        }
Exemplo n.º 16
0
        public void NumberPrimitiveTests()
        {
            IEnumerable<JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42",
                    ExpectedJson = new JsonPrimitiveValue((int)42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "0",
                    ExpectedJson = new JsonPrimitiveValue((int)0)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "-42",
                    ExpectedJson = new JsonPrimitiveValue((int)-42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = Int32.MaxValue.ToString(),
                    ExpectedJson = new JsonPrimitiveValue(Int32.MaxValue)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = Int32.MinValue.ToString(),
                    ExpectedJson = new JsonPrimitiveValue(Int32.MinValue)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42.42",
                    ExpectedJson = new JsonPrimitiveValue((double)42.42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = ".42",
                    ExpectedJson = new JsonPrimitiveValue((double).42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "-42.42",
                    ExpectedJson = new JsonPrimitiveValue((double)-42.42)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42.3e-2",
                    ExpectedJson = new JsonPrimitiveValue((double)42.3e-2)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42.3E-2",
                    ExpectedJson = new JsonPrimitiveValue((double)42.3e-2)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42.3E+2",
                    ExpectedJson = new JsonPrimitiveValue((double)42.3e+2)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "0005.2",
                    ExpectedJson = new JsonPrimitiveValue((double)5.2)
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42-3",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidNumberFormat", "42-3"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42..3",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidNumberFormat", "42..3"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "4e3e3",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidNumberFormat", "4e3e3"),
                },
                // Number is only up to the first non-number character
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42a",
                    DisablePayloadCombinations = true,  // We need this since the error is different when inside an array or so.
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MultipleTopLevelValues"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "42   4",
                    DisablePayloadCombinations = true,  // We need this since the error is different when inside an array or so.
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MultipleTopLevelValues"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.ValuePayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
                {
                    JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
                });
        }
Exemplo n.º 17
0
        public void StringPrimitiveValueTest()
        {
            IEnumerable<JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"some\"",
                    ExpectedJson = new JsonPrimitiveValue("some")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"\"",
                    ExpectedJson = new JsonPrimitiveValue("")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'some\'",
                    ExpectedJson = new JsonPrimitiveValue("some")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'\'",
                    ExpectedJson = new JsonPrimitiveValue("")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"so'me\"",
                    ExpectedJson = new JsonPrimitiveValue("so'me")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'so\\\"me\'",
                    ExpectedJson = new JsonPrimitiveValue("so\"me")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"\\'\\\"\"",
                    ExpectedJson = new JsonPrimitiveValue("\'\"")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'\\'\\\"\'",
                    ExpectedJson = new JsonPrimitiveValue("\'\"")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"some\\b\\f\\n\\r\\t\\\\\\/\"",
                    ExpectedJson = new JsonPrimitiveValue("some\b\f\n\r\t\\/")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"some\\baa\\faa\\naa\\raa\\taa\\\\aa\\/aa\"",
                    ExpectedJson = new JsonPrimitiveValue("some\baa\faa\naa\raa\taa\\aa/aa")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\u0020aa\"",
                    ExpectedJson = new JsonPrimitiveValue("aa aa")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\u006d\\u006Daa\"",
                    ExpectedJson = new JsonPrimitiveValue("aammaa")
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"" + new string('a', 5 * 1024) + "\"",
                    ExpectedJson = new JsonPrimitiveValue(new string('a', 5 * 1024))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"some",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'some",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"some\\\"",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'some\\\'",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\",
                    DisablePayloadCombinations = true,
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\g\"",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\g"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\u\"",
                    DisablePayloadCombinations = true,
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\uXXXX"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\u123",
                    DisablePayloadCombinations = true,
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\uXXXX"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\uzzzz\"",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\uzzzz"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\u-123",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnrecognizedEscapeSequence", "\\u-123"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"aa\\u0020",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedEndOfString"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.ValuePayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
                {
                    JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
                });
        }
Exemplo n.º 18
0
        /// <summary>
        /// Generates interesting payloads for property cases.
        /// </summary>
        /// <param name="propertyPayloadTestCase">The property test case, where the JsonText represents 
        /// a single property and ExpectedJson is a JsonProperty instance.</param>
        /// <returns>Enumeration of all interesting test cases.</returns>
        public static IEnumerable<JsonReaderTestCaseDescriptor> PropertyPayloads(JsonReaderTestCaseDescriptor propertyTestCase)
        {
            Debug.Assert(
                propertyTestCase.ExpectedJson is JsonProperty || propertyTestCase.ExpectedException != null,
                "This method only works on property test cases.");

            // The property alone in an object
            yield return new JsonReaderTestCaseDescriptor(propertyTestCase) 
            { 
                JsonText = "^{^" + propertyTestCase.JsonText + "^}^",
                FragmentExtractor = (json) => json.Object().Properties.First()
            };

            // The property surrounded by other properties
            yield return new JsonReaderTestCaseDescriptor(propertyTestCase)
            {
                JsonText = "^{^\"firstprop\"^:^1^,^" + propertyTestCase.JsonText + "^,^\"lastprop\"^:^2^}^",
                FragmentExtractor = (json) => json.Object().Properties.Skip(1).First()
            };

            // The property as first property followed by another.
            yield return new JsonReaderTestCaseDescriptor(propertyTestCase)
            {
                JsonText = "^{^" + propertyTestCase.JsonText + "^,^\"lastprop\"^:^2^}^",
                FragmentExtractor = (json) => json.Object().Properties.First()
            };

            // The property as last property preceded by another
            yield return new JsonReaderTestCaseDescriptor(propertyTestCase)
            {
                JsonText = "^{^\"firstprop\"^:^1^,^" + propertyTestCase.JsonText + "^}^",
                FragmentExtractor = (json) => json.Object().Properties.Skip(1).First()
            };
        }
Exemplo n.º 19
0
        public void PropertyTests()
        {
            IEnumerable<JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"foo\"^:^42",
                    ExpectedJson = new JsonProperty("foo", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'foo\'^:^42",
                    ExpectedJson = new JsonProperty("foo", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "foo^:^42",
                    ExpectedJson = new JsonProperty("foo", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "_$32a$_^:^42",
                    ExpectedJson = new JsonProperty("_$32a$_", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "$a32^:^42",
                    ExpectedJson = new JsonProperty("$a32", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "32^:^42",
                    ExpectedJson = new JsonProperty("32", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "_^:^42",
                    ExpectedJson = new JsonProperty("_", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "$^:^42",
                    ExpectedJson = new JsonProperty("$", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\" \"^:^42",
                    ExpectedJson = new JsonProperty(" ", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'\t\'^:^42",
                    ExpectedJson = new JsonProperty("\t", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"\r\n\t   \"^:^42",
                    ExpectedJson = new JsonProperty("\r\n\t   ", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'\\r\\n\\t   \'^:^42",
                    ExpectedJson = new JsonProperty("\r\n\t   ", new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = new string('a', 5 * 1024) + "^:^42",
                    ExpectedJson = new JsonProperty(new string('a', 5 * 1024), new JsonPrimitiveValue(42))
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"\"^:^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidPropertyNameOrUnexpectedComma", string.Empty),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\'\'^:^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidPropertyNameOrUnexpectedComma", string.Empty),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "^:^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_InvalidPropertyNameOrUnexpectedComma", string.Empty),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"foo\"^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingColon", "foo"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{\"foo\"",
                    DisablePayloadCombinations = true,
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingColon", "foo"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{\"foo\"  ",
                    DisablePayloadCombinations = true,
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingColon", "foo"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"foo\"^,^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingColon", "foo"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "\"foo\"^:^,^42",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Property"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{\"foo\":",
                    DisablePayloadCombinations = true,
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_EndOfInputWithOpenScope"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.PropertyPayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
                {
                    JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
                });
        }
Exemplo n.º 20
0
        public void ObjectTests()
        {
            IEnumerable<JsonReaderTestCaseDescriptor> testCases = new JsonReaderTestCaseDescriptor[]
            {
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^}",
                    ExpectedJson = new JsonObject()
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^\"foo\"^:^42^}",
                    ExpectedJson = new JsonObject() { new JsonProperty("foo", new JsonPrimitiveValue(42)) }
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^\"foo\"^:^42^,^\"bar\"^:^\"some\"^}",
                    ExpectedJson = new JsonObject() { new JsonProperty("foo", new JsonPrimitiveValue(42)), new JsonProperty("bar", new JsonPrimitiveValue("some")) }
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{,",
                    DisablePayloadCombinations = true,
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_EndOfInputWithOpenScope"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^,^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^\"foo\"^:^42^,^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^,^\"foo\"^:^42^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^,^,^\"foo\"^:^42^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_UnexpectedComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^\"foo\"^:^42^^\"bar\"^:^43^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^\"foo\"^:^42^\"bar\"^:^43^}",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Object"),
                },
                new JsonReaderTestCaseDescriptor
                {
                    JsonText = "{^\"foo\"^:^{}^\"bar\"^:^43^]",
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReader_MissingComma", "Object"),
                },
            };

            testCases = testCases.PayloadCases(JsonReaderPayloads.ValuePayloads);
            testCases = testCases.PayloadCases(JsonReaderPayloads.WhitespacePaylods);

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                JsonReaderUtils.TestConfigurations,
                (testCase, testConfiguration) =>
                {
                    JsonReaderUtils.ReadAndVerifyJson(testCase, testConfiguration, this.JsonValueComparer, this.Assert, this.ExceptionVerifier);
                });
        }