Exemple #1
0
        public void Constructor3()
        {
            TestDataAssert.Execute(
                TestData.RepresentativeValueAndRefTypeTestDataCollection,
                (type, obj) =>
            {
                foreach (HttpMethod httpMethod in HttpTestData.AllHttpMethods)
                {
                    foreach (Uri uri in TestData.UriTestData)
                    {
                        foreach (IEnumerable <MediaTypeFormatter> formatterCollection in HttpTestData.AllFormatterCollections)
                        {
                            MediaTypeFormatter[] formatters = formatterCollection.ToArray();
                            HttpRequestMessage request      = GenericTypeAssert.InvokeConstructor <HttpRequestMessage>(
                                httpRequestMessageOfTType,
                                type,
                                new Type[] { type, typeof(HttpMethod), typeof(Uri), typeof(IEnumerable <MediaTypeFormatter>) },
                                new object[] { obj, httpMethod, uri, formatters });

                            GenericTypeAssert.IsCorrectGenericType <HttpRequestMessage>(request, type);
                            Assert.AreEqual(uri, request.RequestUri, "Uri property was not set.");
                            Assert.AreEqual(httpMethod, request.Method, "Method property was not set.");
                            ObjectContentAssert.IsCorrectGenericType(request.Content as ObjectContent, type);
                            ObjectContentAssert.ContainsFormatters(request.Content as ObjectContent, formatters);
                        }
                    }
                }
            });
        }
        public void Constructor4()
        {
            TestDataAssert.Execute(
                TestData.RepresentativeValueAndRefTypeTestDataCollection,
                (type, obj) =>
            {
                foreach (HttpStatusCode statusCode in HttpTestData.AllHttpStatusCodes)
                {
                    foreach (IEnumerable <MediaTypeFormatter> formatterCollection in HttpTestData.AllFormatterCollections)
                    {
                        MediaTypeFormatter[] formatters = formatterCollection.ToArray();
                        HttpResponseMessage response    = GenericTypeAssert.InvokeConstructor <HttpResponseMessage>(
                            httpResponseMessageOfTType,
                            type,
                            new Type[] { type, typeof(HttpStatusCode), typeof(IEnumerable <MediaTypeFormatter>) },
                            new object[] { obj, statusCode, formatters });

                        Assert.AreEqual(statusCode, response.StatusCode, "StatusCode was not set.");
                        GenericTypeAssert.IsCorrectGenericType <HttpResponseMessage>(response, type);
                        ObjectContentAssert.IsCorrectGenericType(response.Content as ObjectContent, type);
                        ObjectContentAssert.ContainsFormatters(response.Content as ObjectContent, formatters);
                    }
                }
            });
        }
Exemple #3
0
 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.");
     });
 }
Exemple #4
0
 public void IsAssignableFromParameterReturnsTrueForAllHttpResponseMessageOfTTypes()
 {
     ObjectContentAssert.ExecuteForEachHttpResponseMessage(
         HttpTestData.ConvertableValueTypes,
         TestDataVariations.All,
         (response, type, obj) =>
     {
         Type convertType  = response.GetType();
         HttpParameter hpd = new HttpParameter("aName", convertType);
         Assert.IsTrue(hpd.IsAssignableFromParameter(convertType), string.Format("IsAssignableFrom({0}) was false.", convertType.Name));
     });
 }
Exemple #5
0
 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));
     });
 }
Exemple #6
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>.");
     });
 }
Exemple #7
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));
         }
     });
 }
Exemple #8
0
 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.");
     });
 }
Exemple #9
0
 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"));
     });
 }
Exemple #10
0
 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.");
     });
 }
Exemple #11
0
 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));
         }
     });
 }
Exemple #12
0
        public void Constructor1()
        {
            TestDataAssert.Execute(
                TestData.RepresentativeValueAndRefTypeTestDataCollection,
                (type, obj) =>
            {
                HttpRequestMessage request = GenericTypeAssert.InvokeConstructor <HttpRequestMessage>(
                    httpRequestMessageOfTType,
                    type,
                    new Type[] { type },
                    new object[] { obj });

                GenericTypeAssert.IsCorrectGenericType <HttpRequestMessage>(request, type);
                ObjectContentAssert.IsCorrectGenericType(request.Content as ObjectContent, type);
            });
        }
Exemple #13
0
 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 Constructor2()
        {
            TestDataAssert.Execute(
                TestData.RepresentativeValueAndRefTypeTestDataCollection,
                (type, obj) =>
            {
                foreach (HttpStatusCode statusCode in HttpTestData.AllHttpStatusCodes)
                {
                    HttpResponseMessage response = GenericTypeAssert.InvokeConstructor <HttpResponseMessage>(
                        httpResponseMessageOfTType,
                        type,
                        new Type[] { type, typeof(HttpStatusCode) },
                        new object[] { obj, statusCode });

                    GenericTypeAssert.IsCorrectGenericType <HttpResponseMessage>(response, type);
                    ObjectContentAssert.IsCorrectGenericType(response.Content as ObjectContent, type);
                    Assert.AreEqual(statusCode, response.StatusCode, "StatusCode was not set.");
                }
            });
        }
Exemple #15
0
        public void Constructor2()
        {
            TestDataAssert.Execute(
                TestData.RepresentativeValueAndRefTypeTestDataCollection,
                (type, obj) =>
            {
                foreach (IEnumerable <MediaTypeFormatter> formatterCollection in HttpTestData.AllFormatterCollections)
                {
                    MediaTypeFormatter[] formatters = formatterCollection.ToArray();
                    HttpRequestMessage request      = GenericTypeAssert.InvokeConstructor <HttpRequestMessage>(
                        httpRequestMessageOfTType,
                        type,
                        new Type[] { type, typeof(IEnumerable <MediaTypeFormatter>) },
                        new object[] { obj, formatters });

                    GenericTypeAssert.IsCorrectGenericType <HttpRequestMessage>(request, type);
                    ObjectContentAssert.IsCorrectGenericType(request.Content as ObjectContent, type);
                    ObjectContentAssert.ContainsFormatters(request.Content as ObjectContent, formatters);
                }
            });
        }