public void CreateCollectionReaderArgumentTest() { IEdmEntityType entityType = null; IEdmComplexType complexType = null; IEdmModel model = this.CreateTestMetadata(out entityType, out complexType); IEdmEntityContainer defaultContainer = model.FindEntityContainer("TestNS.TestContainer"); IEdmOperationImport primitiveValueFunctionImport = defaultContainer.FindOperationImports("PrimitiveValueFunctionImport").Single(); IEdmOperationImport collectionOfEntitiesFunctionImport = defaultContainer.FindOperationImports("CollectionOfEntitiesFunctionImport").Single(); this.CombinatorialEngineProvider.RunCombinations( this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testConfiguration) => { TestMessage message = TestReaderUtils.CreateInputMessageFromStream(new TestStream(), testConfiguration); ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(message, null, testConfiguration); this.Assert.ExpectedException( () => messageReader.CreateODataCollectionReader(new EdmComplexTypeReference(complexType, false)), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedTypeSpecifiedWithoutMetadata", "expectedItemTypeReference"), this.ExceptionVerifier); messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration); this.Assert.ExpectedException( () => messageReader.CreateODataCollectionReader(new EdmEntityTypeReference(entityType, false)), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedCollectionTypeWrongKind", "Entity"), this.ExceptionVerifier); messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration); this.Assert.ExpectedException( () => messageReader.CreateODataCollectionReader(collectionOfEntitiesFunctionImport), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedCollectionTypeWrongKind", "Entity"), this.ExceptionVerifier); }); }
public void MessageReaderConstructorVersionsTest() { var versions = new[] { new { DataServiceVersion = "4.0", ODataVersion = ODataVersion.V4, ExpectedException = (ExpectedException)null }, new { DataServiceVersion = "4.01", ODataVersion = ODataVersion.V401, ExpectedException = (ExpectedException)null }, new { DataServiceVersion = "5.0", ODataVersion = ODataVersion.V4, ExpectedException = ODataExpectedExceptions.ODataException("ODataUtils_UnsupportedVersionHeader", "5.0") }, new { DataServiceVersion = "0.5", ODataVersion = ODataVersion.V4, ExpectedException = ODataExpectedExceptions.ODataException("ODataUtils_UnsupportedVersionHeader", "0.5") }, }; this.CombinatorialEngineProvider.RunCombinations( settingsActionTestCases, versions, ODataVersionUtils.AllSupportedVersions, (settingsAction, version, maxProtocolVersion) => { TestMessage message = settingsAction.Response ? (TestMessage) new TestResponseMessage(new MemoryStream()) : (TestMessage) new TestRequestMessage(new MemoryStream()); message.SetHeader(ODataConstants.ODataVersionHeader, version.DataServiceVersion); ODataMessageReaderSettings settings = new ODataMessageReaderSettings() { MaxProtocolVersion = maxProtocolVersion }; ExpectedException expectedException = version.ExpectedException ?? (maxProtocolVersion < version.ODataVersion ? ODataExpectedExceptions.ODataException("ODataUtils_MaxProtocolVersionExceeded", version.ODataVersion.ToText(), maxProtocolVersion.ToText()) : (ExpectedException)null); this.Assert.ExpectedException( () => settingsAction.Action(message, settings), expectedException, this.ExceptionVerifier); }); }
public void MessageReaderConstructorArgumentValidationTest() { TestRequestMessage requestMessage = new TestRequestMessage(new MemoryStream()); TestResponseMessage responseMessage = new TestResponseMessage(new MemoryStream()); this.CombinatorialEngineProvider.RunCombinations( settingsActionTestCases, (settingsAction) => { TestMessage message = settingsAction.Response ? (TestMessage)responseMessage : (TestMessage)requestMessage; // Verify that relative BaseUri will fail this.Assert.ExpectedException( () => settingsAction.Action(message, new ODataMessageReaderSettings { BaseUri = new Uri("foo", UriKind.Relative) }), ODataExpectedExceptions.ODataException("ReaderValidationUtils_MessageReaderSettingsBaseUriMustBeNullOrAbsolute", "foo/"), this.ExceptionVerifier); // Verify the None UndeclaredPropertyBehaviorKinds works on both request and response. this.Assert.ExpectedException( () => settingsAction.Action(message, new ODataMessageReaderSettings { UndeclaredPropertyBehaviorKinds = ODataUndeclaredPropertyBehaviorKinds.None }), null, this.ExceptionVerifier); // Verify the IgnoreUndeclaredValueProperty UndeclaredPropertyBehaviorKinds fails on requests. this.Assert.ExpectedException( () => settingsAction.Action(message, new ODataMessageReaderSettings { UndeclaredPropertyBehaviorKinds = ODataUndeclaredPropertyBehaviorKinds.IgnoreUndeclaredValueProperty }), settingsAction.Response ? null : ODataExpectedExceptions.ODataException("ReaderValidationUtils_UndeclaredPropertyBehaviorKindSpecifiedOnRequest"), this.ExceptionVerifier); // Verify the ReportUndeclaredLinkProperty UndeclaredPropertyBehaviorKinds fails on requests. this.Assert.ExpectedException( () => settingsAction.Action(message, new ODataMessageReaderSettings { UndeclaredPropertyBehaviorKinds = ODataUndeclaredPropertyBehaviorKinds.ReportUndeclaredLinkProperty }), settingsAction.Response ? null : ODataExpectedExceptions.ODataException("ReaderValidationUtils_UndeclaredPropertyBehaviorKindSpecifiedOnRequest"), this.ExceptionVerifier); // Verify the IgnoreUndeclaredValueProperty | ReportUndeclaredLinkProperty UndeclaredPropertyBehaviorKinds fails on requests. this.Assert.ExpectedException( () => settingsAction.Action(message, new ODataMessageReaderSettings { UndeclaredPropertyBehaviorKinds = ODataUndeclaredPropertyBehaviorKinds.IgnoreUndeclaredValueProperty | ODataUndeclaredPropertyBehaviorKinds.ReportUndeclaredLinkProperty }), settingsAction.Response ? null : ODataExpectedExceptions.ODataException("ReaderValidationUtils_UndeclaredPropertyBehaviorKindSpecifiedOnRequest"), this.ExceptionVerifier); }); }
/// <summary> /// Constructor. /// </summary> /// <param name="messageReader">The message reader to wrap.</param> /// <param name="testConfiguration">The test configuration to use.</param> /// <param name="message">The message to read from.</param> /// <remarks> /// This constructor is used if special checks against <paramref name="message"/> should be performed. /// Use the constructor overload that does not take a <see cref="TestMessage"/> argument to prevent any checks /// around disposal of the message. /// </remarks> public ODataMessageReaderTestWrapper(ODataMessageReader messageReader, ODataMessageReaderSettings messageReaderSettings, ReaderTestConfiguration testConfiguration, TestMessage message) { ExceptionUtilities.CheckArgumentNotNull(messageReader, "messageReader"); ExceptionUtilities.CheckArgumentNotNull(testConfiguration, "testConfiguration"); ExceptionUtilities.CheckArgumentNotNull(message, "message"); this.messageReader = messageReader; this.messageReaderSettings = messageReaderSettings; this.testConfiguration = testConfiguration; this.message = message; ExceptionUtilities.Assert(this.message.TestStream == null || this.message.TestStream.DisposeCount == 0, "If the underlying message stream is a TestStream, its dispose count must be 0."); ExceptionUtilities.Assert(!this.message.StreamRetrieved, "GetMessage and GetMessageAsync must not be called previously on the given message."); }
/// <summary> /// Verifies that the result of the test is what the test expected. /// </summary> /// <param name="stream">The stream after writing the message content. This method should use it /// to read the message content and verify it.</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( TestMessage message, ODataPayloadKind payloadKind, WriterTestConfiguration testConfiguration, BaselineLogger logger) { // Get observed payload #if !SILVERLIGHT var observed = TestWriterUtils.ReadToString(message); if (logger != null) logger.LogPayload(TestWriterUtils.BaseLineFixup(observed)); #endif // TODO: Handle SILVERLIGHT }
/// <summary> /// Verifies the result of the write-read. /// </summary> /// <param name="message">The test message is not used but is required to keep the method signature the same.</param> /// <param name="payloadKind">The payload kind is not used but is required to keep the method signature the same.</param> /// <param name="testConfiguration">The test configuration is used for some fixups.</param> public override void VerifyResult(TestMessage message, ODataPayloadKind payloadKind, WriterTestConfiguration testConfiguration, BaselineLogger logger=null) { //TODO: Use Logger to verify result, right now this change is only to unblock writer testcase checkin Debug.Assert(ObservedElement != null, "ObservedElement not provided"); // Fixup the expected and get the content type ODataPayloadElement expected = this.ExpectedPayload.DeepCopy(); ODataPayloadElement observed = this.ObservedElement.DeepCopy(); observed.Accept(new RemoveTypeNameAnnotationFromComplexInCollection()); expected.Accept(new ReorderProperties()); expected.Accept(new RemoveComplexWithNoProperties()); // Compare this.settings.PayloadElementComparer.Compare(expected, observed); }
/// <summary> /// Constructor. /// </summary> /// <param name="messageWriter">The message writer to wrap.</param> /// <param name="testConfiguration">The test configuration to use.</param> /// <param name="messageStream">the stream of the message.</param> /// <param name="message">The message to write to.</param> /// <param name="assert">The assertion handler for the test.</param> public ODataMessageWriterTestWrapper(ODataMessageWriter messageWriter, WriterTestConfiguration testConfiguration, TestMessage message, AssertionHandler assert) { ExceptionUtilities.CheckArgumentNotNull(messageWriter, "messageWriter"); ExceptionUtilities.CheckArgumentNotNull(testConfiguration, "testConfiguration"); this.messageWriter = messageWriter; this.testConfiguration = testConfiguration; this.message = message; this.assert = assert; if (message != null && message.TestStream != null && assert != null) { this.assert.AreEqual(0, message.TestStream.DisposeCount, "If the underlying message stream is a TestStream, its dispose count must be 0."); this.assert.AreEqual(false, message.StreamRetrieved, "GetMessage and GetMessageAsync must not be called privously on the given message."); } }
/// <summary> /// Verifies that the result of the test is what the test expected. /// </summary> /// <param name="stream">The stream after writing the message content. This method should use it /// to read the message content and verify it.</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( TestMessage message, ODataPayloadKind payloadKind, WriterTestConfiguration testConfiguration, BaselineLogger logger) { this.settings.Assert.IsTrue(payloadKind == ODataPayloadKind.MetadataDocument, "Only metadata payload kind is supported."); // read the message content using the Taupo infrastructure ExceptionUtilities.CheckArgumentNotNull(message.TestStream, "stream != null"); #if !SILVERLIGHT var observed = TestWriterUtils.ReadToString(message); if (logger != null) logger.LogPayload(TestWriterUtils.BaseLineFixup(observed)); #endif // TODO: Handle SILVERLIGHT }
public void CreateResourceReaderArgumentTest() { IEdmEntityType entityType = null; IEdmComplexType complexType = null; IEdmModel model = this.CreateTestMetadata(out entityType, out complexType); this.CombinatorialEngineProvider.RunCombinations( this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testConfiguration) => { TestMessage message = TestReaderUtils.CreateInputMessageFromStream(new TestStream(), testConfiguration); ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(message, null, testConfiguration); this.Assert.ExpectedException( () => messageReader.CreateODataResourceReader(entityType), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedTypeSpecifiedWithoutMetadata", "resourceType"), this.ExceptionVerifier); }); }
protected override TestMessage CreateInputMessage(ReaderTestConfiguration testConfiguration) { MemoryStream memoryStream = new MemoryStream(this.RawMessage); TestStream messageStream = new TestStream(memoryStream); if (testConfiguration.Synchronous) { messageStream.FailAsynchronousCalls = true; } else { messageStream.FailSynchronousCalls = true; } TestMessage testMessage = TestReaderUtils.CreateInputMessageFromStream( messageStream, testConfiguration, this.PayloadElement.GetPayloadKindFromPayloadElement(), this.BatchContentTypeHeader, this.UrlResolver); return(testMessage); }
public void MessageReaderConstructorArgumentValidationTest() { TestRequestMessage requestMessage = new TestRequestMessage(new MemoryStream()); TestResponseMessage responseMessage = new TestResponseMessage(new MemoryStream()); this.CombinatorialEngineProvider.RunCombinations( settingsActionTestCases, (settingsAction) => { TestMessage message = settingsAction.Response ? (TestMessage)responseMessage : (TestMessage)requestMessage; // Verify that relative BaseUri will fail this.Assert.ExpectedException( () => settingsAction.Action(message, new ODataMessageReaderSettings { BaseUri = new Uri("foo", UriKind.Relative) }), ODataExpectedExceptions.ODataException("ReaderValidationUtils_MessageReaderSettingsBaseUriMustBeNullOrAbsolute", "foo/"), this.ExceptionVerifier); var settings = new ODataMessageReaderSettings(); settings.Validations |= ValidationKinds.ThrowOnUndeclaredPropertyForNonOpenType; this.Assert.ExpectedException( () => settingsAction.Action(message, settings), null, this.ExceptionVerifier); settings.Validations &= ~ValidationKinds.ThrowOnUndeclaredPropertyForNonOpenType; this.Assert.ExpectedException( () => settingsAction.Action(message, settings), settingsAction.Response ? null : ODataExpectedExceptions.ODataException("ReaderValidationUtils_UndeclaredPropertyBehaviorKindSpecifiedOnRequest"), this.ExceptionVerifier); }); }
/// <summary> /// Verifies that the result of the test (the message reader) is what the test expected. /// </summary> /// <param name="stream">Stream which contains the results of the write.</param> /// <param name="payloadKind">The payload kind specified in the test descriptor.</param> /// <param name="testConfiguration">The test configuration to use.</param> public virtual void VerifyResult( TestMessage message, ODataPayloadKind payloadKind, WriterTestConfiguration testConfiguration, BaselineLogger logger) { // throw if not implemented; eventually we can make this method abstract when the WriterTestExpectedResults // are not used directly anymore throw new NotImplementedException("Subclasses must implement their own validation logic."); }
/// <summary> /// This method reuses the message stream to cause a failure. /// </summary> /// <param name="newTestConfig">The configuration to use</param> /// <param name="testMessage">The message to write to</param> private void ReuseMessage(WriterTestConfiguration config, TestMessage testMessage) { ExceptionUtilities.CheckArgumentNotNull(config, "config"); ExceptionUtilities.CheckArgumentNotNull(testMessage, "testMessage"); using (ODataMessageWriterTestWrapper messageWriterWrapper = TestWriterUtils.CreateMessageWriter(testMessage, null, config, this.Assert, null)) { var batchWriter = messageWriterWrapper.CreateODataBatchWriter(); batchWriter.WriteStartBatch(); var newMessage = batchWriter.CreateOperationRequestMessage("GET", new Uri("http://www.odata.org")); // This line should fail messageWriterWrapper.CreateODataEntryWriter(); } }
public void ReadPropertyArgumentTest() { IEdmEntityType entityType = null; IEdmComplexType complexType = null; IEdmModel model = this.CreateTestMetadata(out entityType, out complexType); IEdmEntityContainer container = model.FindEntityContainer("TestContainer"); IEdmOperationImport entityValueFunctionImport = container.FindOperationImports("EntityValueFunctionImport").Single(); IEdmOperationImport entityCollectionValueFunctionImport = container.FindOperationImports("CollectionOfEntitiesFunctionImport").Single(); IEdmStructuralProperty entityValueStructuralProperty = (IEdmStructuralProperty)complexType.FindProperty("EntityProp"); IEdmStructuralProperty entityCollectionValueStructuralProperty = (IEdmStructuralProperty)complexType.FindProperty("EntityCollectionProp"); this.CombinatorialEngineProvider.RunCombinations( this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testConfiguration) => { TestMessage message = TestReaderUtils.CreateInputMessageFromStream(new TestStream(), testConfiguration); ODataMessageReaderTestWrapper messageReader = TestReaderUtils.CreateMessageReader(message, null, testConfiguration); this.Assert.ExpectedException( () => messageReader.ReadProperty(new EdmComplexTypeReference(complexType, false)), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedTypeSpecifiedWithoutMetadata", "expectedPropertyTypeReference"), this.ExceptionVerifier); messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration); this.Assert.ExpectedException( () => messageReader.ReadProperty(new EdmEntityTypeReference(entityType, false)), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"), this.ExceptionVerifier); messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration); this.Assert.ExpectedException( () => messageReader.ReadProperty(new EdmCollectionType(new EdmEntityTypeReference(entityType, false)).ToTypeReference()), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityCollectionKind"), this.ExceptionVerifier); messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration); this.Assert.ExpectedException( () => messageReader.ReadProperty(entityValueFunctionImport), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"), this.ExceptionVerifier); messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration); this.Assert.ExpectedException( () => messageReader.ReadProperty(entityCollectionValueFunctionImport), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityCollectionKind"), this.ExceptionVerifier); messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration); this.Assert.ExpectedException( () => messageReader.ReadProperty(entityValueStructuralProperty), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"), this.ExceptionVerifier); messageReader = TestReaderUtils.CreateMessageReader(message, model, testConfiguration); this.Assert.ExpectedException( () => messageReader.ReadProperty(entityCollectionValueStructuralProperty), ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityCollectionKind"), this.ExceptionVerifier); }); }
/// <summary> /// This method calls tries to end the batch before ending the changeset /// </summary> /// <param name="newTestConfig">The config to use</param> /// <param name="testMessage">The message to use</param> private void CallEndBatchBeforeEndChangeset(WriterTestConfiguration config, TestMessage testMessage) { ExceptionUtilities.CheckArgumentNotNull(config, "config"); ExceptionUtilities.CheckArgumentNotNull(testMessage, "testMessage"); using (ODataMessageWriterTestWrapper messageWriterWrapper = TestWriterUtils.CreateMessageWriter(testMessage, null, config, this.Assert, null)) { var batchWriter = messageWriterWrapper.CreateODataBatchWriter(); batchWriter.WriteStartBatch(); batchWriter.WriteStartChangeset(); // This line should fail batchWriter.WriteEndBatch(); } }
/// <summary> /// Helper method to create <see cref="ODataMessageReader"/> instance. /// </summary> /// <param name="message">The test message to use.</param> /// <param name="model">The model to use.</param> /// <param name="testConfiguration">The test configuration.</param> /// <returns>The test wrapper for the newly created message reader.</returns> public static ODataMessageReaderTestWrapper CreateMessageReader( TestMessage message, IEdmModel model, ReaderTestConfiguration testConfiguration) { ODataMessageReader messageReader; if (testConfiguration.IsRequest) { TestRequestMessage requestMessage = (TestRequestMessage)message; messageReader = new ODataMessageReader(requestMessage, testConfiguration.MessageReaderSettings, model); } else { TestResponseMessage responseMessage = (TestResponseMessage)message; messageReader = new ODataMessageReader(responseMessage, testConfiguration.MessageReaderSettings, model); } return new ODataMessageReaderTestWrapper(messageReader, testConfiguration.MessageReaderSettings, testConfiguration, message); }
/// <summary> /// This method tries to write operations with DisableMessageStreamDisposal set to true /// </summary> /// <param name="newTestConfig">The config to use</param> /// <param name="testMessage">The message to use</param> private void WriteWhenSetToStreamDispose(WriterTestConfiguration config, TestMessage testMessage) { ExceptionUtilities.CheckArgumentNotNull(config, "config"); ExceptionUtilities.CheckArgumentNotNull(testMessage, "testMessage"); config.MessageWriterSettings.DisableMessageStreamDisposal = true; using (ODataMessageWriterTestWrapper messageWriterWrapper = TestWriterUtils.CreateMessageWriter(testMessage, null, config, this.Assert, null)) { var batchWriter = messageWriterWrapper.CreateODataBatchWriter(); batchWriter.WriteStartBatch(); batchWriter.WriteStartChangeset(); var opmessage1 = batchWriter.CreateOperationRequestMessage("PUT", new Uri("http://www.odata.org/Customers")); var messageWriterSettings = new ODataMessageWriterSettings(config.MessageWriterSettings); messageWriterSettings.SetContentType(ODataFormat.Atom); var messageConfig = new WriterTestConfiguration(ODataFormat.Atom, messageWriterSettings, config.IsRequest, config.Synchronous); using (ODataMessageWriterTestWrapper opWriterWrapper = TestWriterUtils.CreateMessageWriter(opmessage1.GetStream(), messageConfig, this.Assert, messageWriterSettings, null)) { var entryWriter = opWriterWrapper.CreateODataEntryWriter(); entryWriter.WriteStart(new ODataEntry() { Id = new Uri("http://id"), TypeName = "Entry1", EditLink = new Uri("http://www.odata.org/Customers(1)"), ReadLink = new Uri("http://www.odata.org/Customers(1)"), Properties = new ODataProperty[] { new ODataProperty() { Name = "Property", Value= 5 } } }); entryWriter.WriteEnd(); } // This line should fail var opmessage2 = batchWriter.CreateOperationRequestMessage("POST", new Uri("http://www.odata.org/Customers")); } }
/// <summary> /// Set the default content type header for a message of the given payload kind. /// </summary> /// <param name="testMessage">The test message to set the Content-Type header on.</param> /// <param name="format">The format of the message.</param> /// <param name="payloadKind">The payload kind for which to determine and set the content type.</param> public static void SetContentType(this TestMessage testMessage, ODataFormat format, ODataPayloadKind payloadKind) { string contentType = TestMediaTypeUtils.GetDefaultContentType(payloadKind, format); testMessage.SetHeader(ODataConstants.ContentTypeHeader, contentType); }
/// <summary> /// This method calls WriteChangesetStart before WriteBatchStart. /// </summary> /// <param name="newTestConfig">The config to use</param> /// <param name="testMessage">The message to use</param> private void StartChangesetWithoutStartingBatch(WriterTestConfiguration config, TestMessage testMessage) { ExceptionUtilities.CheckArgumentNotNull(config, "config"); ExceptionUtilities.CheckArgumentNotNull(testMessage, "testMessage"); config.MessageWriterSettings.DisableMessageStreamDisposal = true; using (ODataMessageWriterTestWrapper messageWriterWrapper = TestWriterUtils.CreateMessageWriter(testMessage, null, config, this.Assert, null)) { var batchWriter = messageWriterWrapper.CreateODataBatchWriter(); // This line should fail batchWriter.WriteStartChangeset(); } }
/// <summary> /// Traces interesting information if on test failure. /// </summary> /// <param name="message">The message to dump the failure information for.</param> /// <param name="messageStream">The message stream to get the message content from.</param> /// <param name="testConfiguration">The test configuration to use.</param> protected void TraceFailureInformation(TestMessage message, Stream messageStream, WriterTestConfiguration testConfiguration) { try { Trace.WriteLine("----- HTTP Message start ------------------------------------------"); TestRequestMessage requestMessage = message as TestRequestMessage; if (requestMessage != null) { Trace.WriteLine(requestMessage.Method.ToString() + " " + requestMessage.Url + " HTTP/1.1"); } TestResponseMessage responseMessage = message as TestResponseMessage; if (responseMessage != null) { Trace.WriteLine(responseMessage.StatusCode.ToString()); } foreach (var header in message.Headers) { Trace.WriteLine(header.Key + ": " + header.Value); } Trace.WriteLine(""); Trace.WriteLine(this.DumpOutputMessageContent(messageStream, testConfiguration)); Trace.WriteLine("----- HTTP Message end --------------------------------------------"); string additionalDescription = this.DumpAdditionalTestDescriptions(testConfiguration); if (!string.IsNullOrEmpty(additionalDescription)) { Trace.WriteLine(""); Trace.WriteLine("----- Additional test description ---------------------------------"); Trace.WriteLine(additionalDescription); } } catch (Exception innerException) { // Ignore all exceptions here since we want to fail with the original test exception. Trace.WriteLine("Failed to dump the test message."); Trace.WriteLine(innerException); } }
/// <summary> /// Writes the payload to the stream using the given callback, then verifies the payload using the test deserializer /// </summary> /// <param name="originalPayload">The payload being tested, of which a copy will be made</param> /// <param name="message">The stream to write to</param> /// <param name="odataVersion">The OData protocol version to be used for writing payloads.</param> /// <param name="format">The current format</param> /// <param name="writeToStream">The callback to write to the stream</param> private void WriteAndLogODataPayload(ODataPayloadElement originalPayload, TestMessage message, ODataVersion odataVersion, ODataFormat format, Action<ODataPayloadElement> writeToStream) { ExceptionUtilities.CheckArgumentNotNull(originalPayload, "originalPayload"); ExceptionUtilities.CheckArgumentNotNull(writeToStream, "writeToStream"); // This is needed because we may modify the payload in use but the same is used in another iteration of the combinatorial engine var payload = originalPayload.DeepCopy(); WriteToStream(format, writeToStream, payload); var newPayload = TestWriterUtils.ReadToString(message); this.Logger.LogPayload(newPayload); }
/// <summary> /// Called to create the input message for the reader test. /// </summary> /// <param name="testConfiguration">The test configuration.</param> /// <returns>The newly created test message to use.</returns> protected override TestMessage CreateInputMessage(ReaderTestConfiguration testConfiguration) { MemoryStream memoryStream = new MemoryStream(this.GetPayload(testConfiguration)); TestStream messageStream = new TestStream(memoryStream); if (testConfiguration.Synchronous) { messageStream.FailAsynchronousCalls = true; } else { messageStream.FailSynchronousCalls = true; } this.testMessage = TestReaderUtils.CreateInputMessageFromStream( messageStream, testConfiguration, /*payloadKind*/ null, this.ContentType, /*urlResolver*/ null); if (this.TestMessageWrapper != null) { this.testMessage = this.TestMessageWrapper(this.testMessage); } return this.testMessage; }