Esempio n. 1
0
 public void GetValueConverterObjectContentOfT()
 {
     ObjectContentAssert.ExecuteForEachObjectContent(
         HttpTestData.RepresentativeValueAndRefTypeTestDataCollection,
         TestDataVariations.All,
         (objectContent, type, obj) =>
     {
         HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(objectContent.GetType());
         Assert.AreEqual(objectContent.GetType(), converter.Type, "Converter Type is wrong.");
     });
 }
Esempio n. 2
0
 public void IsAssignableFromParameterReturnsTrueForAllObjectContentOfTTypes()
 {
     ObjectContentAssert.ExecuteForEachObjectContent(
         HttpTestData.ConvertableValueTypes,
         TestDataVariations.All,
         (objectContent, type, obj) =>
     {
         Type convertType  = objectContent.GetType();
         HttpParameter hpd = new HttpParameter("aName", convertType);
         Assert.IsTrue(hpd.IsAssignableFromParameter(convertType), string.Format("IsAssignableFrom({0}) was false.", convertType.Name));
     });
 }
Esempio n. 3
0
 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>.");
     });
 }
Esempio n. 4
0
 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));
         }
     });
 }
Esempio n. 5
0
 public void ValueConverterReturnsConverterForAllObjectContentOfTTypes()
 {
     ObjectContentAssert.ExecuteForEachObjectContent(
         HttpTestData.ConvertableValueTypes,
         TestDataVariations.All,
         (objectContent, type, obj) =>
     {
         Type convertType  = objectContent.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.");
     });
 }
Esempio n. 6
0
 public void ConvertStringToObjectContentOfTThrows()
 {
     ObjectContentAssert.ExecuteForEachObjectContent(
         HttpTestData.ConvertableValueTypes,
         TestDataVariations.AllSingleInstances,
         (objectContent, type, obj) =>
     {
         Type convertType = obj == null ? type : obj.GetType();
         HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(objectContent.GetType());
         string errorMessage = SR.ValueConversionFailed(typeof(string).FullName, converter.Type.FullName);
         ExceptionAssert.Throws <InvalidOperationException>(
             errorMessage,
             () => converter.Convert("random string"));
     });
 }
Esempio n. 7
0
 public void ConvertThrowsWithTtoObjectContentOfT()
 {
     ObjectContentAssert.ExecuteForEachObjectContent(
         HttpTestData.RepresentativeValueAndRefTypeTestDataCollection,
         TestDataVariations.All,
         (objectContent, type, obj) =>
     {
         if (obj != null)
         {
             Type convertType = obj.GetType();
             HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(objectContent.GetType());
             string errorMessage = SR.ValueConversionFailed(convertType.FullName, converter.Type.FullName);
             ExceptionAssert.Throws <InvalidOperationException>(
                 errorMessage,
                 () => converter.Convert(obj));
         }
     });
 }