public void FindsHandlerForCustomTypeWithCharset()
 {
     var table = new MediaTypeHandlerTable();
     var actual = table.GetMediaTypeHandler("application/vnd.test.towel+json; charset=utf-8");
     Assert.NotNull(actual);
     Assert.IsType<TestMediaTypeHandler>(actual);
 }
 public void FindsHandlerForDirectType()
 {
     var table = new MediaTypeHandlerTable();
     var actual = table.GetMediaTypeHandler(MediaType.Json);
     Assert.NotNull(actual);
     Assert.IsType<TestMediaTypeHandler>(actual);
 }
Exemplo n.º 3
0
        public void FindsHandlerForCustomTypeWithCharset()
        {
            var table  = new MediaTypeHandlerTable();
            var actual = table.GetMediaTypeHandler("application/vnd.test.towel+json; charset=utf-8");

            Assert.NotNull(actual);
            Assert.IsType <TestMediaTypeHandler>(actual);
        }
Exemplo n.º 4
0
        public void FindsHandlerForDirectType()
        {
            var table  = new MediaTypeHandlerTable();
            var actual = table.GetMediaTypeHandler(MediaType.Json);

            Assert.NotNull(actual);
            Assert.IsType <TestMediaTypeHandler>(actual);
        }
 public void FindsHandlerForDirectTypeList()
 {
     var table = new MediaTypeHandlerTable();
     string matchedType;
     var actual = table.GetMediaTypeHandler(new[] {"application/foo", MediaType.Json}, out matchedType);
     Assert.NotNull(actual);
     Assert.IsType<TestMediaTypeHandler>(actual);
     Assert.Equal(MediaType.Json, matchedType);
 }
 public void FindsHandlerForHal()
 {
     var table = new MediaTypeHandlerTable();
     string matchedType;
     const string customType = "application/hal+json";
     var actual = table.GetMediaTypeHandler(new[] {customType}, out matchedType);
     Assert.NotNull(actual);
     Assert.IsType<HalMediaTypeHandler>(actual);
     Assert.Equal(customType, matchedType);
 }
 public void FindsHandlerForCustomTypeList()
 {
     var table = new MediaTypeHandlerTable();
     string matchedType;
     const string customType = "application/vnd.test.towel+json";
     var actual = table.GetMediaTypeHandler(new[] {"application/foo", customType}, out matchedType);
     Assert.NotNull(actual);
     Assert.IsType<TestMediaTypeHandler>(actual);
     Assert.Equal(customType, matchedType);
 }
Exemplo n.º 8
0
        public void FindsHandlerForDirectTypeList()
        {
            var    table = new MediaTypeHandlerTable();
            string matchedType;
            var    actual = table.GetMediaTypeHandler(new[] { "application/foo", MediaType.Json }, out matchedType);

            Assert.NotNull(actual);
            Assert.IsType <TestMediaTypeHandler>(actual);
            Assert.Equal(MediaType.Json, matchedType);
        }
Exemplo n.º 9
0
        public void FindsHandlerForHal()
        {
            var          table = new MediaTypeHandlerTable();
            string       matchedType;
            const string customType = "application/hal+json";
            var          actual     = table.GetMediaTypeHandler(new[] { customType }, out matchedType);

            Assert.NotNull(actual);
            Assert.IsType <HalMediaTypeHandler>(actual);
            Assert.Equal(customType, matchedType);
        }
Exemplo n.º 10
0
        public void FindsHandlerForCustomTypeList()
        {
            var          table = new MediaTypeHandlerTable();
            string       matchedType;
            const string customType = "application/vnd.test.towel+json";
            var          actual     = table.GetMediaTypeHandler(new[] { "application/foo", customType }, out matchedType);

            Assert.NotNull(actual);
            Assert.IsType <TestMediaTypeHandler>(actual);
            Assert.Equal(customType, matchedType);
        }
Exemplo n.º 11
0
        /// <summary>
        /// This method supports the framework directly and should not be used from your code
        /// </summary>
        /// <typeparam name="T">The input model type.</typeparam>
        /// <param name="context">The context.</param>
        /// <returns>The model de-serialized from the input stream.</returns>
        public static T Impl <T>(IContext context)
        {
            if (context.Request.InputStream.Length == 0)
            {
                return(default(T));
            }

            var mediaTypeHandlerTable = new MediaTypeHandlerTable();
            var mediaTypeHandler      = mediaTypeHandlerTable.GetMediaTypeHandler(context.Request.GetContentType());

            return((T)mediaTypeHandler.Read(context.Request.InputStream, typeof(T)));
        }
Exemplo n.º 12
0
        /// <summary>
        /// This method supports the framework directly and should not be used from your code
        /// </summary>
        /// <typeparam name="T">The input model type.</typeparam>
        /// <param name="handler">The handler.</param>
        /// <param name="context">The context.</param>
        public static void Impl <T>(IInput <T> handler, IContext context)
        {
            if (context.Request.InputStream.CanSeek && context.Request.InputStream.Length == 0)
            {
                return;
            }

            var mediaTypeHandlerTable = new MediaTypeHandlerTable();
            var mediaTypeHandler      = mediaTypeHandlerTable.GetMediaTypeHandler(context.Request.GetContentType());

            handler.Input = mediaTypeHandler.Read <T>(context.Request.InputStream).Result;
        }
Exemplo n.º 13
0
        /// <summary>
        /// This method supports the framework directly and should not be used from your code
        /// </summary>
        /// <typeparam name="T">The input model type.</typeparam>
        /// <param name="handler">The handler.</param>
        /// <param name="context">The context.</param>
        public static void Impl <T>(IInput <T> handler, IContext context)
        {
            if (context.Request.InputStream.Length == 0)
            {
                return;
            }

            var mediaTypeHandlerTable = new MediaTypeHandlerTable();
            var mediaTypeHandler      = mediaTypeHandlerTable.GetMediaTypeHandler(context.Request.GetContentType());

            handler.Input = (T)mediaTypeHandler.Read(context.Request.InputStream, typeof(T));
        }
Exemplo n.º 14
0
        /// <summary>
        /// This method supports the framework directly and should not be used from your code
        /// </summary>
        /// <typeparam name="T">The input model type.</typeparam>
        /// <param name="context">The context.</param>
        /// <returns>The model de-serialized from the input stream.</returns>
        public static T Impl <T>(IContext context)
        {
            if (context.Request.InputStream.CanSeek && context.Request.InputStream.Length == 0)
            {
                return(default(T));
            }

            var mediaTypeHandlerTable = new MediaTypeHandlerTable();
            var mediaTypeHandler      = mediaTypeHandlerTable.GetMediaTypeHandler(context.Request.GetContentType());

            return(mediaTypeHandler.Read <T>(context.Request.InputStream).Result);
        }
Exemplo n.º 15
0
 private static bool TryGetMediaTypeHandler(IContext context, IList <string> acceptedTypes, out IMediaTypeHandler mediaTypeHandler)
 {
     try
     {
         string matchedType;
         mediaTypeHandler = new MediaTypeHandlerTable().GetMediaTypeHandler(acceptedTypes, out matchedType);
     }
     catch (UnsupportedMediaTypeException)
     {
         context.Response.Status = "415 Unsupported media type requested.";
         mediaTypeHandler        = null;
         return(false);
     }
     return(true);
 }
Exemplo n.º 16
0
 private static bool TryGetMediaTypeHandler(IContext context, out IMediaTypeHandler mediaTypeHandler)
 {
     try
     {
         string matchedType;
         mediaTypeHandler = new MediaTypeHandlerTable().GetMediaTypeHandler(context.Request.AcceptTypes, out matchedType);
     }
     catch (UnsupportedMediaTypeException)
     {
         context.Response.StatusCode = 415;
         context.Response.StatusDescription = "Unsupported media type requested.";
         mediaTypeHandler = null;
         return false;
     }
     return true;
 }
Exemplo n.º 17
0
 private static bool TryGetMediaTypeHandler(IContext context, IList<string> acceptedTypes, out IMediaTypeHandler mediaTypeHandler)
 {
     if (acceptedTypes == null || (acceptedTypes.Count == 1 && acceptedTypes[0].StartsWith("*/*")))
     {
         mediaTypeHandler = null;
         return false;
     }
     try
     {
         string matchedType;
         mediaTypeHandler = new MediaTypeHandlerTable().GetMediaTypeHandler(acceptedTypes, out matchedType);
     }
     catch (UnsupportedMediaTypeException)
     {
         context.Response.Status = "415 Unsupported media type requested.";
         mediaTypeHandler = null;
         return false;
     }
     return true;
 }