public void WriteCorsHeaders_NullCorsResult_Throws()
        {
            HttpResponseMessage response = new HttpResponseMessage();

            Assert.ThrowsArgumentNull(() =>
                response.WriteCorsHeaders(null),
                "corsResult");
        }
        public void WriteCorsHeaders_WritesAllowExposedHeaders()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            CorsResult corsResult = new CorsResult();
            corsResult.AllowedExposedHeaders.Add("baz");

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            string[] exposedHeaders = headers.GetValues("Access-Control-Expose-Headers").FirstOrDefault().Split(',');
            Assert.Contains("baz", exposedHeaders);
        }
        public void WriteCorsHeaders_WritesAllowMethods()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            CorsResult corsResult = new CorsResult();
            corsResult.AllowedMethods.Add("DELETE");
            corsResult.AllowedMethods.Add("PUT");

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            string[] allowMethods = headers.GetValues("Access-Control-Allow-Methods").FirstOrDefault().Split(',');
            Assert.Contains("DELETE", allowMethods);
            Assert.Contains("PUT", allowMethods);
        }
        public void WriteCorsHeaders_WritesAllowCredentials()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            CorsResult corsResult = new CorsResult
            {
                SupportsCredentials = true
            };

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            Assert.Equal("true", headers.GetValues("Access-Control-Allow-Credentials").FirstOrDefault());
        }
 public void WriteCorsHeaders_EmptyCorsResult_EmptyHeaders()
 {
     HttpResponseMessage response = new HttpResponseMessage();
     response.WriteCorsHeaders(new CorsResult());
     Assert.Empty(response.Headers);
 }
        public void WriteCorsHeaders_WritesPreflightMaxAge()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            CorsResult corsResult = new CorsResult
            {
                PreflightMaxAge = 10
            };

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            Assert.Equal("10", headers.GetValues("Access-Control-Max-Age").FirstOrDefault());
        }
        public void WriteCorsHeaders_WritesAllowOrigin()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            CorsResult corsResult = new CorsResult
            {
                AllowedOrigin = "*"
            };

            response.WriteCorsHeaders(corsResult);
            HttpResponseHeaders headers = response.Headers;

            Assert.Equal(1, headers.Count());
            Assert.Equal("*", headers.GetValues("Access-Control-Allow-Origin").FirstOrDefault());
        }