示例#1
0
        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);
                });
        }
示例#2
0
        /// <summary>
        /// Helper method to create a test message from its content.
        /// </summary>
        /// <param name="messageContent">Stream with the content of the message.</param>
        /// <param name="testConfiguration">The test configuration.</param>
        /// <param name="payloadKind">The payload kind to use to compute and set the content type header; or null if no content type header should be set.</param>
        /// <param name="customContentTypeHeader">A custom content type header to be used in the message.</param>
        /// <param name="urlResolver">Url resolver to add to the test message created.</param>
        /// <returns>Newly created test message.</returns>
        public static TestMessage CreateInputMessageFromStream(
            TestStream messageContent, 
            ReaderTestConfiguration testConfiguration,
            ODataPayloadKind? payloadKind,
            string customContentTypeHeader,
            IODataUrlResolver urlResolver)
        {
            TestMessage message;
            if (testConfiguration.IsRequest)
            {
                if (urlResolver != null)
                {
                    message = new TestRequestMessageWithUrlResolver(messageContent, urlResolver, testConfiguration.Synchronous ? TestMessageFlags.NoAsynchronous : TestMessageFlags.NoSynchronous);
                }
                else
                {
                    message = new TestRequestMessage(messageContent, testConfiguration.Synchronous ? TestMessageFlags.NoAsynchronous : TestMessageFlags.NoSynchronous);
                }
            }
            else
            {
                if (urlResolver != null)
                {
                    message = new TestResponseMessageWithUrlResolver(messageContent, urlResolver, testConfiguration.Synchronous ? TestMessageFlags.NoAsynchronous : TestMessageFlags.NoSynchronous);
                }
                else
                {
                    message = new TestResponseMessage(messageContent, testConfiguration.Synchronous ? TestMessageFlags.NoAsynchronous : TestMessageFlags.NoSynchronous);
                }
            }

            // set the OData-Version header
            message.SetHeader(ODataConstants.ODataVersionHeader, testConfiguration.Version.ToText());

            if (customContentTypeHeader != null)
            {
                message.SetHeader(ODataConstants.ContentTypeHeader, customContentTypeHeader);
            }
            else if (payloadKind.HasValue)
            {
                message.SetContentType(testConfiguration.Format, payloadKind.Value);
            }

            return message;
        }
示例#3
0
        public void PublicSetOnProperties()
        {
            var requestMessage = new TestRequestMessage(new MemoryStream());
            var exception = TestExceptionUtils.RunCatching(() => requestMessage.Url = new Uri("http://www.odata.org"));
            ExceptionUtilities.Assert(exception == null, "No exception was expected. Exception was thrown {0}", exception);

            var responseMessage= new TestResponseMessage(new MemoryStream());
            exception = TestExceptionUtils.RunCatching(() => responseMessage.StatusCode = 5);
            ExceptionUtilities.Assert(exception == null, "No exception was expected. Exception was thrown {0}", exception);
        }
 /// <summary>
 /// Creates an <see cref="ODataMessageReader"/> from the specified <paramref name="memoryStream"/>.
 /// </summary>
 /// <param name="memoryStream">The <see cref="MemoryStream"/> used as input for the message reader.</param>
 /// <returns>An <see cref="ODataMessageReader"/> instance.</returns>
 private ODataMessageReader CreateMessageReader(MemoryStream memoryStream)
 {
     // Create a test message around the memory stream, set the content-type header and then create
     // the message reader
     if (this.IsResponse)
     {
         TestResponseMessage responseMessage = new TestResponseMessage(memoryStream, TestMessageFlags.NoAsynchronous);
         responseMessage.SetHeader(ODataConstants.ContentTypeHeader, "multipart/mixed; boundary=" + this.BatchBoundary);
         return new ODataMessageReader(responseMessage);
     }
     else
     {
         TestRequestMessage requestMessage = new TestRequestMessage(memoryStream, TestMessageFlags.NoAsynchronous);
         requestMessage.SetHeader(ODataConstants.ContentTypeHeader, "multipart/mixed; boundary=" + this.BatchBoundary);
         return new ODataMessageReader(requestMessage);
     }
 }