/// <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; } }
/// <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); } }
/// <summary> /// Constructor. /// </summary> /// <param name="innerExpectedResult">The inner <see cref="ReaderTestExpectedResult"/> that is doing most of the work.</param> /// <param name="expectedFormat">The expected <see cref="ODataFormat"/> for the specified content type.</param> /// <param name="settings">Settings to use.</param> public ContentTypeReaderTestExpectedResult(ReaderTestExpectedResult innerExpectedResult, ODataFormat expectedFormat, ReaderTestExpectedResult.ReaderTestExpectedResultSettings settings) : base(settings) { this.innerExpectedResult = innerExpectedResult; this.expectedFormat = expectedFormat; this.settings = settings; }
/// <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) { return(new MetadataReaderTestExpectedResult(this.settings.ExpectedResultSettings) { ExpectedException = this.ExpectedException, }); } else { return(expectedResult); } }
/// <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 innerExpectedResult = base.GetExpectedResult(testConfiguration); return(new ContentTypeReaderTestExpectedResult(innerExpectedResult, this.ExpectedFormat, this.settings.ExpectedResultSettings)); }