public override void RunTest(ReaderTestConfiguration testConfiguration) { //TODO: Use Logger to verify result, right now this change is only to unblock writer testcase checkin BaselineLogger logger = null; if (this.ShouldSkipForTestConfiguration(testConfiguration)) { return; } var originalPayload = this.PayloadElement; this.PayloadElement = this.PayloadElement.DeepCopy(); // Create messages (payload gets serialized in createInputMessage) TestMessage readerMessage = this.CreateInputMessage(testConfiguration); var settings = new ODataMessageWriterSettings() { Version = testConfiguration.Version, BaseUri = testConfiguration.MessageReaderSettings.BaseUri, EnableMessageStreamDisposal = testConfiguration.MessageReaderSettings.EnableMessageStreamDisposal, }; settings.SetContentType(testConfiguration.Format); WriterTestConfiguration writerConfig = new WriterTestConfiguration(testConfiguration.Format, settings, testConfiguration.IsRequest, testConfiguration.Synchronous); TestMessage writerMessage = TestWriterUtils.CreateOutputMessageFromStream(new TestStream(new MemoryStream()), writerConfig, this.PayloadKind, String.Empty, this.UrlResolver); IEdmModel model = this.GetMetadataProvider(testConfiguration); WriterTestExpectedResults expectedResult = this.GetExpectedResult(writerConfig); 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(readerMessage, model, testConfiguration)) using (ODataMessageWriterTestWrapper messageWriterWrapper = TestWriterUtils.CreateMessageWriter(writerMessage, model, writerConfig, this.settings.Assert)) { var streamer = new ObjectModelReadWriteStreamer(); streamer.StreamMessage(messageReaderWrapper, messageWriterWrapper, this.PayloadKind, writerConfig); expectedResult.VerifyResult(writerMessage, this.PayloadKind, writerConfig, logger); } }); this.PayloadElement = originalPayload; try { expectedResult.VerifyException(exception); } catch (Exception) { this.TraceFailureInformation(testConfiguration); throw; } }
private TestMessage CreateOutputMessage(Stream innerStream, WriterTestConfiguration testConfiguration, ODataPayloadElement payload) { TestStream messageStream = new TestStream(innerStream); TestWriterUtils.SetFailAsynchronousCalls(messageStream, testConfiguration.Synchronous); var boundary = this.PayloadElement.GetAnnotation <BatchBoundaryAnnotation>(); // We create a new test configuration for batch because the payload indicates whether we are dealing with a request or a response and the configuration won't know that in advance var newTestConfig = new WriterTestConfiguration(testConfiguration.Format, testConfiguration.MessageWriterSettings, this.PayloadElement is BatchRequestPayload, testConfiguration.Synchronous); TestMessage testMessage = TestWriterUtils.CreateOutputMessageFromStream(messageStream, newTestConfig, this.PayloadKind, boundary.BatchBoundaryInHeader, this.UrlResolver); return(testMessage); }
/// <summary> /// Called to create the output message for the writer test. /// </summary> /// <param name="innerStream">The <see cref="Stream"/> instance to be used as inner stream of the <see cref="TestStream"/>.</param> /// <param name="testConfiguration">The test configuration.</param> /// <returns>The newly created test message to use.</returns> protected virtual TestMessage CreateOutputMessage(Stream innerStream, WriterTestConfiguration testConfiguration) { TestStream messageStream = new TestStream(innerStream); if (testConfiguration.Synchronous) { messageStream.FailAsynchronousCalls = true; } else { messageStream.FailSynchronousCalls = true; } TestMessage testMessage = TestWriterUtils.CreateOutputMessageFromStream(messageStream, testConfiguration, this.PayloadKind, this.ContentType, this.UrlResolver); return(testMessage); }
/// <summary> /// Called to create the input message for the reader test. /// </summary> /// <param name="innerStream">The <see cref="Stream"/> instance to be used as inner stream of the <see cref="TestStream"/>.</param> /// <param name="testConfiguration">The test configuration.</param> /// <returns>The newly created test message to use.</returns> protected override TestMessage CreateOutputMessage(Stream innerStream, WriterTestConfiguration testConfiguration) { Debug.Assert(innerStream is StreamingTestStream, "StreamingTestStream expected."); StreamingTestStream streamingTestStream = (StreamingTestStream)innerStream; if (testConfiguration.Synchronous) { streamingTestStream.FailAsynchronousCalls = true; } else { streamingTestStream.FailSynchronousCalls = true; } TestMessage testMessage = TestWriterUtils.CreateOutputMessageFromStream( streamingTestStream, testConfiguration, this.PayloadKind, this.PayloadElement.GetCustomContentTypeHeader(), this.UrlResolver); return(testMessage); }