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); }); }
/// <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); }