/// <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> /// Verifies that the result of the test is what is expected. /// It does so by delegating to the inner expected result provided in the constructor and additionally checking the reported <see cref="ODataFormat"/>. /// </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) { if (this.innerExpectedResult != null) { this.innerExpectedResult.VerifyResult(messageReader, payloadKind, testConfiguration); } ODataFormat actualFormat = ODataUtils.GetReadFormat(messageReader.MessageReader); this.settings.Assert.AreEqual(this.expectedFormat, actualFormat, "Formats don't match."); }
/// <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); } } }
/// <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); } } }
/// <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) { this.settings.Assert.IsTrue(payloadKind == ODataPayloadKind.MetadataDocument, "Only metadata payload kind is supported."); object metadata = this.settings.MessageToObjectModelReader.ReadMessage( messageReader, payloadKind, /*payloadModel*/ null, PayloadReaderTestDescriptor.ReaderMetadata.None, /*expectedBatchPayload*/ null, testConfiguration); IEdmModel actualModel = metadata as IEdmModel; this.settings.Assert.IsTrue(metadata != null && actualModel != null, "Expected a non-null model to be read."); }
/// <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) { object odataObject = this.settings.MessageToObjectModelReader.ReadMessage( messageReader, payloadKind, /*payloadModel*/ null, this.ReaderMetadata, /*expectedBatchPayload*/ null, testConfiguration); if (this.ODataObjectModelValidator != null) { this.ODataObjectModelValidator.ValidateODataObjectModel(odataObject); } // only compare the payloads if the expected payload is not 'null'; null indicates to skip the comparison if (this.ExpectedPayloadElement != null) { ODataPayloadElement actualPayloadElement = this.settings.ObjectModelToPayloadElementConverter.Convert(odataObject, !testConfiguration.IsRequest); if (this.IgnorePropertyOrder) { if (testConfiguration.Format == ODataFormat.Json && !testConfiguration.IsRequest) { this.settings.JsonLightResponseIgnorePropertyOrderODataPayloadElementComparer.Compare(this.ExpectedPayloadElement, actualPayloadElement); } else { this.settings.IgnorePropertyOrderODataPayloadElementComparer.Compare(this.ExpectedPayloadElement, actualPayloadElement); } } else { if (testConfiguration.Format == ODataFormat.Json && !testConfiguration.IsRequest) { this.settings.ODataJsonLightResponsePayloadElementComparer.Compare(this.ExpectedPayloadElement, actualPayloadElement); } else { this.settings.ODataPayloadElementComparer.Compare(this.ExpectedPayloadElement, actualPayloadElement); } } } }
/// <summary> /// Write payload kind to message. /// </summary> /// <param name="messageWriter">Message writer to write payload to.</param> /// <param name="payloadKind">The kind of payload we are writing.</param> /// <param name="payload">The payload to write.</param> /// <param name="functionImport">Function import whose parameters are to be written when the payload kind is Parameters.</param> /// <returns>The object read after writing.</returns> public ODataItem WriteMessage(ODataMessageWriterTestWrapper messageWriter, ODataMessageReaderTestWrapper messageReader, ODataPayloadKind payloadKind, object payload, IEdmOperationImport functionImport = null) { ExceptionUtilities.CheckArgumentNotNull(messageWriter, "messageWriter"); ExceptionUtilities.CheckArgumentNotNull(messageReader, "messageReader"); switch (payloadKind) { case ODataPayloadKind.Feed: this.WriteTopLevelFeed(messageWriter, messageReader, (ODataFeed)payload); break; case ODataPayloadKind.Entry: this.WriteTopLevelEntry(messageWriter, messageReader, (ODataEntry)payload); break; default: ExceptionUtilities.Assert(false, "The payload kind '{0}' is not yet supported by ObjectModelWriteReadStreamer.", payloadKind); break; } return readItems.SingleOrDefault(); }
public void StreamMessage(ODataMessageReaderTestWrapper reader, ODataMessageWriterTestWrapper writer, ODataPayloadKind payloadKind, WriterTestConfiguration config) { ExceptionUtilities.CheckArgumentNotNull(reader, "reader is required"); ExceptionUtilities.CheckArgumentNotNull(writer, "writer is required"); ExceptionUtilities.CheckArgumentNotNull(payloadKind, "payloadKind is required"); ExceptionUtilities.CheckArgumentNotNull(config, "config is required"); this.testConfiguration = config; switch(payloadKind) { case ODataPayloadKind.Entry: this.StartRead(reader.CreateODataEntryReader(), writer.CreateODataEntryWriter()); break; case ODataPayloadKind.Feed: this.StartRead(reader.CreateODataFeedReader(), writer.CreateODataFeedWriter()); break; default: throw new NotSupportedException("ObjectModelReadWriteStreamer currently supports only feed and entry"); }; }
/// <summary> /// Reads a batch operation response message from the batch reader. /// </summary> /// <param name="batchReader">The batch reader to read from.</param> /// <param name="expectedPart">The expected part representing the operation in the test OM; used to determine the expected payload kind.</param> /// <param name="indexInPart">The index of the operation in the current changeset or -1 for a top-level operation.</param> /// <returns>The <see cref="ODataBatchOperation"/> read from the batch reader.</returns> private ODataBatchOperation GetResponseOperation(ODataBatchReaderTestWrapper batchReader, IMimePart expectedPart, int indexInPart) { IMimePart responsePart = indexInPart < 0 ? ((MimePartData<HttpResponseData>)expectedPart).Body : ((BatchResponseChangeset)expectedPart).Operations.ElementAt(indexInPart); ODataPayloadElement expectedPartElement = null; ODataResponse odataResponse = responsePart as ODataResponse; if (odataResponse != null) { expectedPartElement = odataResponse.Body == null ? null : odataResponse.RootElement; } object partPayload = null; ODataBatchOperationResponseMessage responseMessage = batchReader.CreateOperationResponseMessage(); if (expectedPartElement != null) { ODataPayloadKind expectedPartKind = expectedPartElement.GetPayloadKindFromPayloadElement(); ODataMessageReaderSettings messageReaderSettings = new ODataMessageReaderSettings(this.testConfiguration.MessageReaderSettings) { DisableMessageStreamDisposal = false }; using (ODataMessageReader partMessageReader = new ODataMessageReader(responseMessage, messageReaderSettings, this.payloadModel)) { ODataMessageReaderTestWrapper partMessageReaderWrapper = new ODataMessageReaderTestWrapper( partMessageReader, messageReaderSettings, this.testConfiguration); partPayload = this.messageToObjectModelReader.ReadMessage( partMessageReaderWrapper, expectedPartKind, this.payloadModel, PayloadReaderTestDescriptor.ReaderMetadata.None, /*batchPayload*/ null, this.testConfiguration); } } return new ODataBatchResponseOperation { StatusCode = responseMessage.StatusCode, Headers = responseMessage.Headers, Payload = partPayload, }; }
/// <summary> /// Read a batch payload as the message content. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <param name="expectedBatchPayload">The expected batch payload element; this is used to guide the payload kind detection of the parts.</param> /// <returns>An <see cref="ODataBatch"/>, possibly with annotations.</returns> public ODataBatch ReadBatch(ODataMessageReaderTestWrapper messageReader, ODataPayloadElement expectedBatchPayload) { this.assert.IsNotNull(expectedBatchPayload, "Must have a batch payload element."); this.assert.IsTrue( expectedBatchPayload is BatchRequestPayload && this.testConfiguration.IsRequest || expectedBatchPayload is BatchResponsePayload && !this.testConfiguration.IsRequest, "Expected a request or a response batch payload depending on what we are reading."); ODataBatchReaderTestWrapper batchReader = messageReader.CreateODataBatchReader(); this.assert.AreEqual(ODataBatchReaderState.Initial, batchReader.State, "Reader states don't match."); IMimePart[] expectedParts = this.testConfiguration.IsRequest ? ((BatchRequestPayload)expectedBatchPayload).Parts.ToArray() : ((BatchResponsePayload)expectedBatchPayload).Parts.ToArray(); int expectedPartIndex = 0; List<ODataBatchPart> batchParts = new List<ODataBatchPart>(); List<ODataBatchOperation> changeSetOperations = null; bool errorReadingPartPayload = false; try { bool isCompleted = false; while (batchReader.Read()) { this.assert.IsFalse(isCompleted, "We should not be able to successfully read once we reached the 'Completed' state."); switch (batchReader.State) { case ODataBatchReaderState.Initial: this.assert.Fail("We should never be in state 'Initial' after we started reading."); break; case ODataBatchReaderState.Operation: IMimePart expectedPart = expectedParts[expectedPartIndex]; int indexInPart = changeSetOperations == null ? -1 : changeSetOperations.Count; try { ODataBatchOperation operation = this.testConfiguration.IsRequest ? this.GetRequestOperation(batchReader, expectedPart, indexInPart) : this.GetResponseOperation(batchReader, expectedPart, indexInPart); if (changeSetOperations == null) { batchParts.Add(operation); expectedPartIndex++; } else { changeSetOperations.Add(operation); } } catch (Exception) { // NOTE: The batch reader will not enter exception state when an error is raised while // reading a part payload. The batch reader might skip to the next part and continue reading. errorReadingPartPayload = true; throw; } break; case ODataBatchReaderState.ChangesetStart: this.assert.IsNull(changeSetOperations, "Must not have pending change set operations when detecting another changeset."); changeSetOperations = new List<ODataBatchOperation>(); break; case ODataBatchReaderState.ChangesetEnd: ODataBatchChangeset changeset = new ODataBatchChangeset { Operations = changeSetOperations, }; changeSetOperations = null; batchParts.Add(changeset); expectedPartIndex++; break; case ODataBatchReaderState.Completed: isCompleted = true; break; case ODataBatchReaderState.Exception: this.assert.Fail("We should never be in state 'Exception' without an exception being thrown."); break; default: this.assert.Fail("Unsupported batch reader state '" + batchReader.State + "' detected."); break; } } this.assert.AreEqual(ODataBatchReaderState.Completed, batchReader.State, "Expected state 'Completed' when done reading."); } catch (Exception e) { // NOTE: The batch reader will not enter exception state when an error is raised while // reading a part payload. The batch reader might skip to the next part and continue reading. if (ExceptionUtilities.IsCatchable(e) && !errorReadingPartPayload) { this.assert.AreEqual(ODataBatchReaderState.Exception, batchReader.State, "Expected the reader to be in 'Exception' state."); } throw; } return new ODataBatch { Parts = batchParts }; }
/// <summary> /// Read an error as the message content. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <returns>An <see cref="ODataError"/>, possibly with annotations.</returns> public ODataError ReadError(ODataMessageReaderTestWrapper messageReader) { return messageReader.ReadError(); }
/// <summary> /// Read a metadata document as the message content. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <returns>An <see cref="IEdmModel"/>, possibly with annotations.</returns> public IEdmModel ReadMetadataDocument(ODataMessageReaderTestWrapper messageReader) { return messageReader.ReadMetadataDocument(); }
/// <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) { // We are not verifying anything here other than reading the result in a non-compliant // way by not creating operation messages when we encounter an operation in a batch/changeset. ODataBatchReaderTestWrapper batchReader = messageReader.CreateODataBatchReader(); this.settings.Assert.AreEqual(ODataBatchReaderState.Initial, batchReader.State, "Reader states don't match."); while (batchReader.Read()) { // Just keep reading through the whole batch. // The batch reader should fail if no operation message is created for an operation. } }
private void WriteTopLevelEntry(ODataMessageWriterTestWrapper messageWriter, ODataMessageReaderTestWrapper messageReader, ODataEntry entry) { ODataWriter entryWriter = messageWriter.CreateODataEntryWriter(); Lazy<ODataReader> lazyEntryReader = new Lazy<ODataReader>(() => messageReader.CreateODataEntryReader()); this.WriteEntry(entryWriter, lazyEntryReader, entry); }
/// <summary> /// Read top-level entity reference links (collection) as the message content. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <returns>An <see cref="ODataEntityReferenceLinks"/>, possibly with annotations.</returns> public ODataEntityReferenceLinks ReadEntityReferenceLinks(ODataMessageReaderTestWrapper messageReader) { return messageReader.ReadEntityReferenceLinks(); }
/// <summary> /// Read an entry as the message content. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <param name="entitySet">The entity set to use for reading entry or feed payloads.</param> /// <param name="expectedEntityTypeReference">The expected entity type to pass to the reader.</param> /// <returns>An <see cref="ODataEntry"/>, possibly with annotations.</returns> public ODataEntry ReadTopLevelEntry(ODataMessageReaderTestWrapper messageReader, IEdmEntitySet entitySet, IEdmTypeReference expectedEntityTypeReference) { IEdmEntityType entityType = expectedEntityTypeReference == null ? null : expectedEntityTypeReference.Definition as IEdmEntityType; ODataReader entryReader = messageReader.CreateODataEntryReader(entitySet, entityType); try { // read the start of the entry entryReader.Read(); this.assert.AreEqual(ODataReaderState.EntryStart, entryReader.State, "Reader states don't match."); ODataEntry entry = this.ReadEntry(entryReader); this.assert.AreEqual(ODataReaderState.EntryEnd, entryReader.State, "Reader states don't match."); // read once more to the end-of-input bool moreToRead = entryReader.Read(); this.assert.IsFalse(moreToRead, "Expected to reach the end of the input."); return entry; } catch (Exception e) { if (ExceptionUtilities.IsCatchable(e)) { this.assert.AreEqual(ODataReaderState.Exception, entryReader.State, "Expected the reader to be in 'Exception' state."); } throw; } }
/// <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 abstract void VerifyResult( ODataMessageReaderTestWrapper messageReader, ODataPayloadKind payloadKind, ReaderTestConfiguration testConfiguration);
/// <summary> /// Reads the content of the <paramref name="payloadKind"/> from <paramref name="messageReader"/> /// and turns it into an annotated OData object model. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <param name="payloadKind">The kind of payload to read.</param> /// <param name="payloadModel">The model for the payload of the message; used for reading batch parts.</param> /// <param name="readerMetadata">The metadata information to be used when reading the actual payload.</param> /// <param name="batchPayload">The expected batch payload element; this is used to guide the payload kind detection of the parts.</param> /// <param name="testConfiguration">The test configuration under which to read the message.</param> /// <returns>The OData object model with possible annotations.</returns> public virtual object ReadMessage( ODataMessageReaderTestWrapper messageReader, ODataPayloadKind payloadKind, IEdmModel payloadModel, IReaderMetadata readerMetadata, ODataPayloadElement batchPayload, ReaderTestConfiguration testConfiguration) { ExceptionUtilities.CheckArgumentNotNull(messageReader, "messageReader"); ObjectModelReader reader = new ObjectModelReader(this, payloadModel, this.storePayloadOrder, testConfiguration); if (readerMetadata == null) { // Use empty reader metadata when none is specified to avoid repetitive checks below. readerMetadata = PayloadReaderTestDescriptor.ReaderMetadata.None; } switch (payloadKind) { case ODataPayloadKind.Property: if (readerMetadata.StructuralProperty != null) { return messageReader.ReadProperty(readerMetadata.StructuralProperty); } else if (readerMetadata.FunctionImport != null) { return messageReader.ReadProperty(readerMetadata.FunctionImport); } else { return messageReader.ReadProperty(readerMetadata.ExpectedType); } case ODataPayloadKind.Feed: return reader.ReadTopLevelFeed(messageReader, readerMetadata.EntitySet, readerMetadata.ExpectedType); case ODataPayloadKind.Entry: return reader.ReadTopLevelEntry(messageReader, readerMetadata.EntitySet, readerMetadata.ExpectedType); case ODataPayloadKind.Collection: return reader.ReadCollection(messageReader, readerMetadata.FunctionImport, readerMetadata.ExpectedType); case ODataPayloadKind.ServiceDocument: return reader.ReadServiceDocument(messageReader); case ODataPayloadKind.MetadataDocument: return reader.ReadMetadataDocument(messageReader); case ODataPayloadKind.Error: return reader.ReadError(messageReader); case ODataPayloadKind.EntityReferenceLink: return reader.ReadEntityReferenceLink(messageReader); case ODataPayloadKind.EntityReferenceLinks: return reader.ReadEntityReferenceLinks(messageReader); case ODataPayloadKind.Value: case ODataPayloadKind.BinaryValue: return reader.ReadValue(messageReader, readerMetadata.ExpectedType); case ODataPayloadKind.Batch: return reader.ReadBatch(messageReader, batchPayload); case ODataPayloadKind.Parameter: return reader.ReadParameters(messageReader, readerMetadata.FunctionImport); default: ExceptionUtilities.Assert(false, "The payload kind '{0}' is not yet supported by MessageToObjectModelReader.", payloadKind); return null; } }
/// <summary> /// Read a collection as the message content. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <param name="producingFunctionImport">The function import producing the collection to be read.</param> /// <param name="expectedItemTypeReference">The expected item type to pass to the reader.</param> /// <returns>An <see cref="ODataCollectionStart"/>, possibly with annotations.</returns> public object ReadCollection(ODataMessageReaderTestWrapper messageReader, IEdmOperationImport producingFunctionImport, IEdmTypeReference expectedItemTypeReference) { ODataCollectionReader collectionReader = producingFunctionImport != null ? messageReader.CreateODataCollectionReader(producingFunctionImport) : messageReader.CreateODataCollectionReader(expectedItemTypeReference); return this.ReadCollection(collectionReader); }
/// <summary> /// Read parameters as the message content. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <param name="functionImport">The function import to pass to the parameter reader.</param> /// <returns>A ComplexInstance representing parameters.</returns> public object ReadParameters(ODataMessageReaderTestWrapper messageReader, IEdmOperationImport functionImport) { // TODO: ODataLib test item: Add new ODataPayloadElement for parameters payload ODataParameterReader parameterReader = messageReader.CreateODataParameterReader(functionImport); ODataParameters odataParameters = new ODataParameters(); List<ODataProperty> parameters = new List<ODataProperty>(); try { // read the start of the parameters this.assert.AreEqual(ODataParameterReaderState.Start, parameterReader.State, "Reader states don't match."); while (parameterReader.Read()) { switch (parameterReader.State) { case ODataParameterReaderState.Value: odataParameters.Add(new KeyValuePair<string,object>(parameterReader.Name, parameterReader.Value)); break; case ODataParameterReaderState.Entry: ODataReader entryReader = parameterReader.CreateEntryReader(); entryReader.Read(); this.assert.AreEqual(ODataReaderState.EntryStart, entryReader.State, "Reader states don't match."); odataParameters.Add(new KeyValuePair<string,object>(parameterReader.Name, this.ReadEntry(entryReader))); this.assert.AreEqual(ODataReaderState.EntryEnd, entryReader.State, "Reader states don't match."); this.assert.IsFalse(entryReader.Read(), "Read() should return false after EntryEnd."); this.assert.AreEqual(ODataReaderState.Completed, entryReader.State, "Reader states don't match."); break; case ODataParameterReaderState.Feed: ODataReader feedReader = parameterReader.CreateFeedReader(); feedReader.Read(); this.assert.AreEqual(ODataReaderState.FeedStart, feedReader.State, "Reader states don't match."); odataParameters.Add(new KeyValuePair<string,object>(parameterReader.Name, this.ReadFeed(feedReader))); this.assert.AreEqual(ODataReaderState.FeedEnd, feedReader.State, "Reader states don't match."); this.assert.IsFalse(feedReader.Read(), "Read() should return false after EntryEnd."); this.assert.AreEqual(ODataReaderState.Completed, feedReader.State, "Reader states don't match."); break; case ODataParameterReaderState.Collection: ODataCollectionReader collectionReader = parameterReader.CreateCollectionReader(); odataParameters.Add(new KeyValuePair<string,object>(parameterReader.Name, this.ReadCollection(collectionReader))); break; default: this.assert.Fail("Unexpected state: " + parameterReader.State); break; } } this.assert.AreEqual(ODataParameterReaderState.Completed, parameterReader.State, "Reader states don't match."); return odataParameters; } catch (Exception e) { if (ExceptionUtilities.IsCatchable(e)) { this.assert.AreEqual(ODataParameterReaderState.Exception, parameterReader.State, "Expected the reader to be in 'Exception' state."); } throw; } }
private void WriteTopLevelFeed(ODataMessageWriterTestWrapper messageWriter, ODataMessageReaderTestWrapper messageReader, ODataFeed feed) { var feedWriter = messageWriter.CreateODataFeedWriter(); Lazy<ODataReader> lazyReader = new Lazy<ODataReader>(() => messageReader.CreateODataFeedReader()); this.WriteFeed(feedWriter, lazyReader, feed); }
/// <summary> /// Read a service document as the message content. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <returns>An <see cref="ODataServiceDocument"/>, possibly with annotations.</returns> public object ReadServiceDocument(ODataMessageReaderTestWrapper messageReader) { return messageReader.ReadServiceDocument(); }
/// <summary> /// Read top-level raw value as the message content. /// </summary> /// <param name="messageReader">The message reader to use for reading.</param> /// <param name="expectedValueTypeReference">The expected value type to pass to the reader.</param> /// <returns>An <see cref="System.Object"/> representing the raw value.</returns> public object ReadValue(ODataMessageReaderTestWrapper messageReader, IEdmTypeReference expectedValueTypeReference) { return messageReader.ReadValue(expectedValueTypeReference); }