예제 #1
0
        public void DontChangeContentTypeIfNotMSIE()
        {
            var agent = "Some_Client";

            var context = new HttpActionExecutedContext
            {
                ActionContext = new HttpActionContext
                {
                    ControllerContext = new HttpControllerContext()
                    {
                        Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/pictures/")
                    }
                }
            };

            context.ActionContext.Request.Headers.Add("User-Agent", agent);
            context.Response         = new HttpResponseMessage(HttpStatusCode.OK);
            context.Response.Content = new HttpMessageContent(new HttpResponseMessage(HttpStatusCode.OK));
            context.Response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var handler = new HandleBrowserResponseTypeAttribute();

            handler.OnActionExecuted(context);

            Assert.AreEqual("application/json", context.Response.Content.Headers.ContentType.ToString());
        }
예제 #2
0
        public void ChangeContentTypeToPlainTextIfMSIE()
        {
            var agent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";

            var context = new HttpActionExecutedContext
            {
                ActionContext = new HttpActionContext
                {
                    ControllerContext = new HttpControllerContext()
                    {
                        Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/pictures/")
                    }
                }
            };

            context.ActionContext.Request.Headers.Add("User-Agent", agent);
            context.Response         = new HttpResponseMessage(HttpStatusCode.OK);
            context.Response.Content = new HttpMessageContent(new HttpResponseMessage(HttpStatusCode.OK));
            context.Response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var handler = new HandleBrowserResponseTypeAttribute();

            handler.OnActionExecuted(context);

            Assert.AreEqual("text/plain", context.Response.Content.Headers.ContentType.ToString());
        }