public void FindsHandlerForDirectType() { var table = new ContentTypeHandlerTable(); var actual = table.GetContentTypeHandler(ContentType.Json); Assert.NotNull(actual); Assert.IsType<TestContentTypeHandler>(actual); }
public void FindsHandlerForCustomType() { var table = new ContentTypeHandlerTable(); var actual = table.GetContentTypeHandler("application/vnd.test.towel+json"); Assert.NotNull(actual); Assert.IsType<TestContentTypeHandler>(actual); }
public void FindsHandlerForDirectTypeList() { var table = new ContentTypeHandlerTable(); string matchedType; var actual = table.GetContentTypeHandler(new[] {"application/foo", ContentType.Json}, out matchedType); Assert.NotNull(actual); Assert.IsType<TestContentTypeHandler>(actual); Assert.Equal(ContentType.Json, matchedType); }
public void FindsHandlerForCustomTypeList() { var table = new ContentTypeHandlerTable(); string matchedType; const string customType = "application/vnd.test.towel+json"; var actual = table.GetContentTypeHandler(new[] {"application/foo", customType}, out matchedType); Assert.NotNull(actual); Assert.IsType<TestContentTypeHandler>(actual); Assert.Equal(customType, matchedType); }
private static bool TryGetContentTypeHandler(IContext context, out IContentTypeHandler contentTypeHandler) { try { string matchedType; contentTypeHandler = new ContentTypeHandlerTable().GetContentTypeHandler(context.Request.AcceptTypes, out matchedType); } catch (UnsupportedMediaTypeException) { context.Response.StatusCode = 415; context.Response.StatusDescription = "Unsupported media type requested."; contentTypeHandler = null; return false; } return true; }