Esempio n. 1
0
        /// <summary>
        /// Runs the test specified by this test descriptor.
        /// </summary>
        /// <param name="testConfiguration">The test configuration to use for running the test.</param>
        public virtual void RunTest(ReaderTestConfiguration testConfiguration)
        {
            if (this.ShouldSkipForTestConfiguration(testConfiguration))
            {
                return;
            }

            TestMessage message = this.CreateInputMessage(testConfiguration);
            IEdmModel   model   = this.GetMetadataProvider(testConfiguration);
            ReaderTestExpectedResult expectedResult = this.GetExpectedResult(testConfiguration);

            ExceptionUtilities.Assert(expectedResult != null, "The expected result could not be determined for the test. Did you specify it?");

            Exception exception = TestExceptionUtils.RunCatching(() =>
            {
                using (ODataMessageReaderTestWrapper messageReaderWrapper = TestReaderUtils.CreateMessageReader(message, model, testConfiguration))
                {
                    expectedResult.VerifyResult(messageReaderWrapper, this.PayloadKind, testConfiguration);
                }
            });

            try
            {
                expectedResult.VerifyException(exception);
            }
            catch (Exception)
            {
                this.TraceFailureInformation(testConfiguration);
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Verifies that the result of the test (the message reader) is what the test expected.
        /// </summary>
        /// <param name="messageReader">The message reader which is the result of the test. This method should use it to read the results
        /// of the parsing and verify those.</param>
        /// <param name="payloadKind">The payload kind specified in the test descriptor.</param>
        /// <param name="testConfiguration">The test configuration to use.</param>
        public override void VerifyResult(
            ODataMessageReaderTestWrapper messageReader,
            ODataPayloadKind payloadKind,
            ReaderTestConfiguration testConfiguration)
        {
            // First compare the payload kind detection results.
            IEnumerable <ODataPayloadKindDetectionResult> actualDetectionResults = messageReader.DetectPayloadKind();

            this.VerifyPayloadKindDetectionResult(actualDetectionResults);

            // Then try to read the message as the detected kind if requested
            if (this.ReadDetectedPayloads)
            {
                bool firstResult = true;
                foreach (PayloadKindDetectionResult result in this.ExpectedDetectionResults)
                {
                    if (firstResult)
                    {
                        // For the first result use the existing message reader
                        firstResult = false;
                    }
                    else
                    {
                        // For all subsequent results we need to reset the test stream and create a new message reader
                        // over it.
                        this.TestMessage.Reset();
                        messageReader = TestReaderUtils.CreateMessageReader(this.TestMessage, result.Model, testConfiguration);

                        // Detect the payload kinds again and make sure we can also read the subsequent payload kinds
                        // immediately after detection.
                        actualDetectionResults = messageReader.DetectPayloadKind();
                        this.VerifyPayloadKindDetectionResult(actualDetectionResults);
                    }

                    TestExceptionUtils.ExpectedException(
                        this.settings.Assert,
                        () =>
                    {
                        using (messageReader)
                        {
                            this.settings.MessageToObjectModelReader.ReadMessage(
                                messageReader,
                                result.PayloadKind,
                                result.Model,
                                new PayloadReaderTestDescriptor.ReaderMetadata(result.ExpectedType),
                                /*expectedBatchPayload*/ null,
                                testConfiguration);
                        }
                    },
                        result.ExpectedException,
                        this.settings.ExceptionVerifier);
                }
            }
        }