Esempio 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);
            }
        }
Esempio 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);
            }
        }