public void GenericContentsSystemHttpContentType(object expected) { var content = new ObjectContent(expected.GetType(), expected).ToHttpContent(); Assert.Equal(typeof(SystemStringContent), content.GetType()); Assert.Equal("application/json", content.Headers.ContentType.MediaType); Assert.Equal("utf-8", content.Headers.ContentType.CharSet); }
public void ConvertHttpResponseMessageOfTtoObjectContentOfT() { ObjectContentAssert.ExecuteForEachHttpResponseMessage( HttpTestData.RepresentativeValueAndRefTypeTestDataCollection, TestDataVariations.All, (response, type, obj) => { Type convertType = obj == null ? type : obj.GetType(); ObjectContent objectContent = (ObjectContent)GenericTypeAssert.InvokeConstructor(typeof(ObjectContent <>), convertType, new Type[] { convertType }, new object[] { obj }); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(objectContent.GetType()); ObjectContent convertedContent = converter.Convert(response) as ObjectContent; Assert.IsNotNull(convertedContent, "Failed to convert to ObjectContent."); Assert.AreEqual(((ObjectContent)response.Content).ReadAs(), convertedContent.ReadAs(), "Incorrect value."); }); }
public void CanConvertFromStringReturnsFalseForObjectContent() { ObjectContent objectContent = new ObjectContent <int>(5); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(objectContent.GetType()); if (converter.CanConvertFromString) { Assert.Fail(string.Format("CanConvertFromString was wrong for ObjectContent.")); } }
public void CanConvertFromTypeThrowsWithNullTypeForTtoObjectContentOfT() { ObjectContent objectContent = new ObjectContent <int>(5); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(objectContent.GetType()); ExceptionAssert.ThrowsArgumentNull("type", () => converter.CanConvertFromType(null)); }