コード例 #1
0
        /// <summary>
        /// Called to get the expected result of the test.
        /// </summary>
        /// <param name="testConfiguration">The test configuration to use.</param>
        /// <returns>The expected result.</returns>
        protected override ReaderTestExpectedResult GetExpectedResult(ReaderTestConfiguration testConfiguration)
        {
            ReaderTestExpectedResult expectedResult = base.GetExpectedResult(testConfiguration);

            if (expectedResult == null)
            {
                IEdmModel      model          = this.GetMetadataProvider(testConfiguration);
                ReaderMetadata readerMetadata = new ReaderMetadata(model, this.PayloadElement);

                // First use the input payload as the expected result.
                ODataPayloadElement expectedResultPayloadElement = this.PayloadElement;

                // If we have an override specifically for expected result, use that instead.
                if (this.ExpectedResultPayloadElement != null)
                {
                    expectedResultPayloadElement = this.ExpectedResultPayloadElement(testConfiguration);
                }

                if (expectedResultPayloadElement.ElementType == ODataPayloadElementType.BatchRequestPayload || expectedResultPayloadElement.ElementType == ODataPayloadElementType.BatchResponsePayload)
                {
                    if (this.ExpectedResultNormalizers.Count > 0)
                    {
                        expectedResultPayloadElement = new BatchPayloadExpectedResultNormalizer(
                            testConfiguration,
                            this.ApplyExpectedResultNormalizers).Normalize(expectedResultPayloadElement);
                    }

                    IEdmModel payloadModel = this.GetMetadataProvider(testConfiguration);
                    return(new BatchReaderTestExpectedResult(this.settings.BatchExpectedResultSettings)
                    {
                        ExpectedBatchPayload = expectedResultPayloadElement,
                        PayloadModel = payloadModel,
                        ExpectedException = this.ExpectedException,
                    });
                }
                else
                {
                    expectedResultPayloadElement = this.ApplyExpectedResultNormalizers(expectedResultPayloadElement, testConfiguration);
                }

                return(new PayloadReaderTestExpectedResult(this.settings.ExpectedResultSettings)
                {
                    ExpectedPayloadElement = expectedResultPayloadElement,
                    ExpectedException = this.ExpectedException,
                    ReaderMetadata = readerMetadata,
                    IgnorePropertyOrder = this.IgnorePropertyOrder,
                });
            }
            else
            {
                PayloadReaderTestExpectedResult payloadReaderTestExpectedResult = expectedResult as PayloadReaderTestExpectedResult;
                if (payloadReaderTestExpectedResult != null && payloadReaderTestExpectedResult.ReaderMetadata == null)
                {
                    IEdmModel model = this.GetMetadataProvider(testConfiguration);
                    payloadReaderTestExpectedResult.ReaderMetadata = new ReaderMetadata(model, this.PayloadElement);
                }

                return(expectedResult);
            }
        }
コード例 #2
0
        /// <summary>
        /// Called to get the expected result of the test.
        /// </summary>
        /// <param name="testConfiguration">The test configuration to use.</param>
        /// <returns>The expected result.</returns>
        protected override ReaderTestExpectedResult GetExpectedResult(ReaderTestConfiguration testConfiguration)
        {
            ReaderTestExpectedResult expectedResult = base.GetExpectedResult(testConfiguration);
            if (expectedResult == null)
            {
                IEdmModel model = this.GetMetadataProvider(testConfiguration);
                ReaderMetadata readerMetadata = new ReaderMetadata(model, this.PayloadElement);

                // First use the input payload as the expected result.
                ODataPayloadElement expectedResultPayloadElement = this.PayloadElement;

                // If we have an override specifically for expected result, use that instead.
                if (this.ExpectedResultPayloadElement != null)
                {
                    expectedResultPayloadElement = this.ExpectedResultPayloadElement(testConfiguration);
                }

                if (expectedResultPayloadElement.ElementType == ODataPayloadElementType.BatchRequestPayload || expectedResultPayloadElement.ElementType == ODataPayloadElementType.BatchResponsePayload)
                {
                    if (this.ExpectedResultNormalizers.Count > 0)
                    {
                        expectedResultPayloadElement = new BatchPayloadExpectedResultNormalizer(
                            testConfiguration,
                            this.ApplyExpectedResultNormalizers).Normalize(expectedResultPayloadElement);
                    }

                    IEdmModel payloadModel = this.GetMetadataProvider(testConfiguration);
                    return new BatchReaderTestExpectedResult(this.settings.BatchExpectedResultSettings)
                    {
                        ExpectedBatchPayload = expectedResultPayloadElement,
                        PayloadModel = payloadModel,
                        ExpectedException = this.ExpectedException,
                    };
                }
                else
                {
                    expectedResultPayloadElement = this.ApplyExpectedResultNormalizers(expectedResultPayloadElement, testConfiguration);
                }

                return new PayloadReaderTestExpectedResult(this.settings.ExpectedResultSettings)
                {
                    ExpectedPayloadElement = expectedResultPayloadElement,
                    ExpectedException = this.ExpectedException,
                    ReaderMetadata = readerMetadata,
                    IgnorePropertyOrder = this.IgnorePropertyOrder,
                };
            }
            else
            {
                PayloadReaderTestExpectedResult payloadReaderTestExpectedResult = expectedResult as PayloadReaderTestExpectedResult;
                if (payloadReaderTestExpectedResult != null && payloadReaderTestExpectedResult.ReaderMetadata == null)
                {
                    IEdmModel model = this.GetMetadataProvider(testConfiguration);
                    payloadReaderTestExpectedResult.ReaderMetadata = new ReaderMetadata(model, this.PayloadElement);
                }

                return expectedResult;
            }
        }