public void CanConvertFromTypeThrowsWithNullTypeForTtoObjectContentOfT() { ObjectContent objectContent = new ObjectContent <int>(5); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(objectContent.GetType()); ExceptionAssert.ThrowsArgumentNull("type", () => converter.CanConvertFromType(null)); }
public void GetValueConverterHttpContent() { foreach (HttpContent httpContent in HttpTestData.StandardHttpContents) { HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(httpContent.GetType()); Assert.IsNotNull(converter, "GetValueConverter returned null."); Assert.AreEqual(httpContent.GetType(), converter.Type, "Converter Type was not correct."); } }
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 CanConvertFromStringReturnsFalseForHttpRequestMessage() { HttpRequestMessage request = new HttpRequestMessage <int>(); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(request.GetType()); if (converter.CanConvertFromString) { Assert.Fail(string.Format("CanConvertFromString was wrong for HttpRequestMessage.")); } }
public void CanConvertFromStringReturnsTrueForT() { foreach (TestData testData in HttpTestData.ConvertableValueTypes) { HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(testData.Type); if (!converter.CanConvertFromString) { Assert.Fail(string.Format("CanConvertFromString was wrong for {0}.", testData.Type.Name)); } } }
public void GetValueConverterHttpResponseMessageOfT() { ObjectContentAssert.ExecuteForEachHttpResponseMessage( HttpTestData.RepresentativeValueAndRefTypeTestDataCollection, TestDataVariations.All, (response, type, obj) => { HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(response.GetType()); Assert.AreEqual(response.GetType(), converter.Type, "Converter Type is wrong."); }); }
public void ConvertTtoT() { TestDataAssert.Execute( HttpTestData.ConvertableValueTypes, (type, obj) => { Type convertType = obj == null ? type : obj.GetType(); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(convertType); object actualObj = converter.Convert(obj); TestDataAssert.AreEqual(obj, actualObj, string.Format("Conversion failed for {0}.", convertType.Name)); }); }
public void ConvertObjectContentOfTtoT() { ObjectContentAssert.ExecuteForEachObjectContent( HttpTestData.RepresentativeValueAndRefTypeTestDataCollection, TestDataVariations.All, (objectContent, type, obj) => { Type convertType = obj == null ? type : obj.GetType(); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(convertType); object actualValue = converter.Convert(objectContent); TestDataAssert.AreEqual(obj, actualValue, "Convert failed to return T from ObjectContent<T>."); }); }
public void ConvertHttpResponseMessageOfTtoT() { ObjectContentAssert.ExecuteForEachHttpResponseMessage( HttpTestData.RepresentativeValueAndRefTypeTestDataCollection, TestDataVariations.All, (response, type, obj) => { Type convertType = obj == null ? type : obj.GetType(); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(convertType); object actualValue = converter.Convert(response); TestDataAssert.AreEqual(obj, actualValue, string.Format("Convert from HttpResponseMessage<T> to T failed for {0}.", convertType)); }); }
public void ValueConverterReturnsConverterForAllHttpResponseMessageOfTTypes() { ObjectContentAssert.ExecuteForEachHttpResponseMessage( HttpTestData.ConvertableValueTypes, TestDataVariations.All, (response, type, obj) => { Type convertType = response.GetType(); HttpParameter hpd = new HttpParameter("aName", convertType); HttpParameterValueConverter converter = hpd.ValueConverter; Assert.IsNotNull("ValueConverter returned null."); Assert.AreEqual(convertType, converter.Type, "ValueConverter was made for wrong type."); }); }
public void CanConvertFromTypeReturnsTrueForObjectContentOfTtoT() { ObjectContentAssert.ExecuteForEachObjectContent( HttpTestData.RepresentativeValueAndRefTypeTestDataCollection, TestDataVariations.All, (objectContent, type, obj) => { HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(objectContent.Type); if (!converter.CanConvertFromType(objectContent.GetType())) { Assert.Fail(string.Format("CanConvertFromType failed for {0}.", objectContent.Type)); } }); }
public void GetValueConverterReturnsConverterForAllValueTypes() { TestDataAssert.Execute( HttpTestData.ConvertableValueTypes, TestDataVariations.AllSingleInstances | TestDataVariations.AsNullable, "GetValueConverter failed", (type, obj) => { Type convertType = obj.GetType(); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(convertType); Assert.IsNotNull(converter, "GetValueConverter returned null."); Assert.AreEqual(convertType, converter.Type, "Converter Type was not correct."); }); }
public void CanConvertFromTypeReturnsTrueForHttpResponseMessageOfTtoT() { ObjectContentAssert.ExecuteForEachHttpResponseMessage( HttpTestData.RepresentativeValueAndRefTypeTestDataCollection, TestDataVariations.All, (response, type, obj) => { Type convertType = obj == null ? type : obj.GetType(); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(convertType); if (!converter.CanConvertFromType(response.GetType())) { Assert.Fail(string.Format("CanConvertFromType failed for {0}.", convertType)); } }); }
public void ValueConverterReturnsConverterForAllValueTypes() { TestDataAssert.Execute( HttpTestData.ConvertableValueTypes, TestDataVariations.All, "ValueConverter failed", (type, obj) => { Type convertType = obj.GetType(); HttpParameter hpd = new HttpParameter("aName", convertType); HttpParameterValueConverter converter = hpd.ValueConverter; Assert.IsNotNull("ValueConverter returned null."); Assert.AreEqual(convertType, converter.Type, "ValueConverter was made for wrong type."); }); }
public void ConvertStringToHttpResponseMessageOfTThrows() { ObjectContentAssert.ExecuteForEachHttpResponseMessage( HttpTestData.ConvertableValueTypes, TestDataVariations.AllSingleInstances, (response, type, obj) => { Type convertType = obj == null ? type : obj.GetType(); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(response.GetType()); string errorMessage = SR.ValueConversionFailed(typeof(string).FullName, converter.Type.FullName); ExceptionAssert.Throws <InvalidOperationException>( errorMessage, () => converter.Convert("random string")); }); }
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 ConvertNullableOfTtoT() { TestDataAssert.Execute( HttpTestData.ConvertableValueTypes, TestDataVariations.AsNullable, "Nullable<T> to T failed.", (type, obj) => { Type nonNullableType = obj.GetType(); Assert.IsNull(Nullable.GetUnderlyingType(nonNullableType), "Test error: did not expect nullable object instance."); Assert.AreEqual(nonNullableType, Nullable.GetUnderlyingType(type), "Test error: expected only nullable types."); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(type); object actualValue = converter.Convert(obj); TestDataAssert.AreEqual(obj, actualValue, "Convert failed on Nullable<T> to T."); }); }
public void ConvertThrowsWithTtoHttpResponseMessageOfT() { ObjectContentAssert.ExecuteForEachHttpResponseMessage( HttpTestData.RepresentativeValueAndRefTypeTestDataCollection, TestDataVariations.All, (response, type, obj) => { if (obj != null) { Type convertType = obj.GetType(); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(response.GetType()); string errorMessage = SR.ValueConversionFailed(convertType.FullName, converter.Type.FullName); ExceptionAssert.Throws <InvalidOperationException>( errorMessage, () => converter.Convert(obj)); } }); }
public void ConvertStringToT() { TestDataAssert.Execute( HttpTestData.ConvertableValueTypes, TestDataVariations.AllSingleInstances, "Convert(string) failed", (type, obj) => { Type convertType = obj == null ? type : obj.GetType(); if (HttpParameterAssert.CanConvertToStringAndBack(obj)) { HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(convertType); string objAsString = obj.ToString(); object actualObj = converter.Convert(objAsString); Assert.IsNotNull(actualObj, "Convert from string returned null."); Assert.AreEqual(obj.GetType(), actualObj.GetType(), "Convert from string returned wrong type."); string actualObjAsString = actualObj.ToString(); Assert.AreEqual(objAsString, actualObjAsString, string.Format("Conversion failed for {0}.", convertType.Name)); } }); }
public void ConvertHttpResponseMessageOfNullableTtoT() { TestDataAssert.Execute( HttpTestData.ConvertableValueTypes, TestDataVariations.AsNullable, "HttpResponseMessage<Nullable<T>> failied.", (type, obj) => { Type nonNullableType = obj.GetType(); Assert.IsNull(Nullable.GetUnderlyingType(nonNullableType), "Test error: did not expect nullable object instance."); Assert.AreEqual(nonNullableType, Nullable.GetUnderlyingType(type), "Test error: expected only nullable types."); HttpResponseMessage request = (HttpResponseMessage)GenericTypeAssert.InvokeConstructor( typeof(HttpResponseMessage <>), type, new Type[] { type }, new object[] { obj }); HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(nonNullableType); object actualValue = converter.Convert(request); TestDataAssert.AreEqual(obj, actualValue, "Convert failed to return T from HttpReesponseMessage<T>."); }); }
public void GetValueConverterThrowsWithNullType() { ExceptionAssert.ThrowsArgumentNull("type", () => HttpParameterValueConverter.GetValueConverter(null)); }