Пример #1
0
            public void TheResponseShouldNotBeSet()
            {
                TestHelper.EnsureEDM();

                var httpConfiguration = new HttpConfiguration();

                var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://services.odata.org/OData/Products");

                httpRequestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, httpConfiguration);

                var controllerContext = new HttpControllerContext(httpConfiguration, new Mock <IHttpRouteData>().Object, httpRequestMessage);

                var actionContext = new HttpActionContext(controllerContext, new Mock <HttpActionDescriptor>().Object);

                var attribute = new ODataVersionHeaderValidationAttribute();

                attribute.OnActionExecuting(actionContext);

                Assert.Null(actionContext.Response);
            }
Пример #2
0
            public void AnHttpResponseExceptionIsThrown()
            {
                TestHelper.EnsureEDM();

                var httpConfiguration = new HttpConfiguration();

                var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://services.odata.org/OData/Products");

                httpRequestMessage.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, httpConfiguration);
                httpRequestMessage.Headers.Add(ODataHeaderNames.ODataMaxVersion, "3.0");

                var controllerContext = new HttpControllerContext(httpConfiguration, new Mock <IHttpRouteData>().Object, httpRequestMessage);

                var actionContext = new HttpActionContext(controllerContext, new Mock <HttpActionDescriptor>().Object);

                var attribute = new ODataVersionHeaderValidationAttribute();

                attribute.OnActionExecuting(actionContext);

                Assert.Equal(HttpStatusCode.NotAcceptable, actionContext.Response.StatusCode);
                Assert.Equal("406", ((ODataErrorContent)((ObjectContent <ODataErrorContent>)actionContext.Response.Content).Value).Error.Code);
                Assert.Equal(Messages.UnsupportedODataVersion, ((ODataErrorContent)((ObjectContent <ODataErrorContent>)actionContext.Response.Content).Value).Error.Message);
            }