コード例 #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);
                        }
                    }
                }
            });
        }
コード例 #2
0
        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);
                    }
                }
            });
        }
コード例 #3
0
 public static HttpRequestMessage CreateGenericRequest(Type type, object objectInstance, HttpMethod httpMethod, Uri uri, IEnumerable <MediaTypeFormatter> formatters)
 {
     return(GenericTypeAssert.InvokeConstructor(
                typeof(HttpRequestMessage <>),
                type,
                new Type[] { type, typeof(HttpMethod), typeof(Uri), typeof(IEnumerable <MediaTypeFormatter>) },
                new object[] { objectInstance, httpMethod, uri, formatters }) as HttpRequestMessage);
 }
コード例 #4
0
        public void Constructor()
        {
            TestDataAssert.Execute(
                TestData.RepresentativeValueAndRefTypeTestDataCollection,
                (type, obj) =>
            {
                HttpRequestMessage request = GenericTypeAssert.InvokeConstructor <HttpRequestMessage>(
                    httpRequestMessageOfTType,
                    type);

                GenericTypeAssert.IsCorrectGenericType <HttpRequestMessage>(request, type);
                Assert.IsNotNull(request.Content, "default contructor should have set Content.");
            });
        }
コード例 #5
0
 public void IsAssignableFromParameterOfTReturnsTrueForAllValueTypes()
 {
     TestDataAssert.Execute(
         HttpTestData.ConvertableValueTypes,
         TestDataVariations.All,
         "ValueConverter failed",
         (type, obj) =>
     {
         Type convertType  = obj.GetType();
         HttpParameter hpd = new HttpParameter("aName", convertType);
         bool result       = (bool)GenericTypeAssert.InvokeGenericMethod(hpd, isAssignableFromParameterOfTMethodName, convertType /*, new Type[0], new object[0]*/);
         Assert.IsTrue(result, string.Format("IsAssignableFromParameter<{0}>() was false.", convertType.Name));
     });
 }
コード例 #6
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.");
     });
 }
コード例 #7
0
 public void Constructor3ThrowsWithNullFormatters()
 {
     TestDataAssert.Execute(
         TestData.RepresentativeValueAndRefTypeTestDataCollection,
         (type, obj) =>
     {
         ExceptionAssert.ThrowsArgumentNull <TargetInvocationException>(
             "formatters",
             () => GenericTypeAssert.InvokeConstructor <HttpResponseMessage>(
                 httpResponseMessageOfTType,
                 type,
                 new Type[] { type, typeof(IEnumerable <MediaTypeFormatter>) },
                 new object[] { obj, null }));
     });
 }
コード例 #8
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);
            });
        }
コード例 #9
0
        public static HttpOperationHandler GetGenericHandlerForTypes(Type[] parameterTypes)
        {
            Type handlerType = null;

            switch (parameterTypes.Length)
            {
            case 2: handlerType = typeof(SHttpOperationHandler01 <,>); break;

            case 3: handlerType = typeof(SHttpOperationHandler02 <, ,>); break;

            case 4: handlerType = typeof(SHttpOperationHandler03 <, , ,>); break;

            case 5: handlerType = typeof(SHttpOperationHandler04 <, , , ,>); break;

            case 6: handlerType = typeof(SHttpOperationHandler05 <, , , , ,>); break;

            case 7: handlerType = typeof(SHttpOperationHandler06 <, , , , , ,>); break;

            case 8: handlerType = typeof(SHttpOperationHandler07 <, , , , , , ,>); break;

            case 9: handlerType = typeof(SHttpOperationHandler08 <, , , , , , , ,>); break;

            case 10: handlerType = typeof(SHttpOperationHandler09 <, , , , , , , , ,>); break;

            case 11: handlerType = typeof(SHttpOperationHandler10 <, , , , , , , , , ,>); break;

            case 12: handlerType = typeof(SHttpOperationHandler11 <, , , , , , , , , , ,>); break;

            case 13: handlerType = typeof(SHttpOperationHandler12 <, , , , , , , , , , , ,>); break;

            case 14: handlerType = typeof(SHttpOperationHandler13 <, , , , , , , , , , , , ,>); break;

            case 15: handlerType = typeof(SHttpOperationHandler14 <, , , , , , , , , , , , , ,>); break;

            case 16: handlerType = typeof(SHttpOperationHandler15 <, , , , , , , , , , , , , , ,>); break;

            case 17: handlerType = typeof(SHttpOperationHandler16 <, , , , , , , , , , , , , , , ,>); break;

            default:
                Assert.Fail("Test Error: The type array can not be used to create a generic HttpOperationHandler");
                break;
            }

            return(GenericTypeAssert.InvokeConstructor <HttpOperationHandler>(handlerType, parameterTypes, new object[] { "output" }));
        }
コード例 #10
0
        public void Constructor()
        {
            TestDataAssert.Execute(
                TestData.RepresentativeValueAndRefTypeTestDataCollection,
                (type, obj) =>
            {
                foreach (HttpStatusCode statusCode in HttpTestData.AllHttpStatusCodes)
                {
                    HttpResponseMessage response = GenericTypeAssert.InvokeConstructor <HttpResponseMessage>(
                        httpResponseMessageOfTType,
                        type,
                        statusCode);

                    GenericTypeAssert.IsCorrectGenericType <HttpResponseMessage>(response, type);
                    Assert.IsNotNull(response.Content, "default contructor should have set Content.");
                    Assert.AreEqual(statusCode, response.StatusCode, "StatusCode was not set.");
                }
            });
        }
コード例 #11
0
        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.");
                }
            });
        }
コード例 #12
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);
                }
            });
        }
コード例 #13
0
        /// <summary>
        /// Creates an instance of the generic <see cref="HttpRequestMessage"/> for every value
        /// in the given <paramref name="testDataCollection"/> and invokes the <paramref name="codeUnderTest"/>.
        /// </summary>
        /// <param name="testDataCollection">The collection of test data.</param>
        /// <param name="flags">The test variations.</param>
        /// <param name="codeUnderTest">The code to invoke with each <see cref="HttpRequestMessage"/>.</param>
        public static void ExecuteForEachHttpRequestMessage(IEnumerable <TestData> testDataCollection, TestDataVariations flags, Action <HttpRequestMessage, Type, object> codeUnderTest)
        {
            Assert.IsNotNull(testDataCollection, "testDataCollection cannot be null.");
            Assert.IsNotNull(codeUnderTest, "codeUnderTest cannot be null.");

            TestDataAssert.Execute(
                testDataCollection,
                flags,
                "Failed in ExecuteForEachHttpRequestMessage.",
                (type, obj) =>
            {
                Type convertType           = obj == null ? type : obj.GetType();
                HttpRequestMessage request =
                    (HttpRequestMessage)GenericTypeAssert.InvokeConstructor(
                        typeof(HttpRequestMessage <>),
                        convertType,
                        new Type[] { convertType },
                        new object[] { obj });

                codeUnderTest(request, type, obj);
            });
        }
コード例 #14
0
        /// <summary>
        /// Creates an instance of the generic <see cref="ObjectContent"/> for every value
        /// in the given <paramref name="testDataCollection"/> and invokes the <paramref name="codeUnderTest"/>.
        /// </summary>
        /// <param name="testDataCollection">The collection of test data.</param>
        /// <param name="flags">The test variations.</param>
        /// <param name="codeUnderTest">The code to invoke with each <see cref="ObjectContent"/>.</param>
        public static void ExecuteForEachObjectContent(IEnumerable <TestData> testDataCollection, TestDataVariations flags, Action <ObjectContent, Type, object> codeUnderTest)
        {
            Assert.IsNotNull(testDataCollection, "testDataCollection cannot be null.");
            Assert.IsNotNull(codeUnderTest, "codeUnderTest cannot be null.");

            TestDataAssert.Execute(
                testDataCollection,
                flags,
                "Failed in ExecuteForEachObjectContent.",
                (type, obj) =>
            {
                Type convertType            = obj == null ? type : obj.GetType();
                ObjectContent objectContent =
                    (ObjectContent)GenericTypeAssert.InvokeConstructor(
                        typeof(ObjectContent <>),
                        convertType,
                        new Type[] { convertType },
                        new object[] { obj });

                codeUnderTest(objectContent, type, obj);
            });
        }
コード例 #15
0
 public void Constructor3ThrowsWithNullFormatters()
 {
     TestDataAssert.Execute(
         TestData.RepresentativeValueAndRefTypeTestDataCollection,
         (type, obj) =>
     {
         foreach (HttpMethod httpMethod in HttpTestData.AllHttpMethods)
         {
             foreach (Uri uri in TestData.UriTestData)
             {
                 ExceptionAssert.ThrowsArgumentNull <TargetInvocationException>(
                     "formatters",
                     () =>
                 {
                     HttpRequestMessage request = GenericTypeAssert.InvokeConstructor <HttpRequestMessage>(
                         httpRequestMessageOfTType,
                         type,
                         new Type[] { type, typeof(HttpMethod), typeof(Uri), typeof(IEnumerable <MediaTypeFormatter>) },
                         new object[] { obj, httpMethod, uri, null });
                 });
             }
         }
     });
 }
コード例 #16
0
        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>.");
            });
        }
コード例 #17
0
 public static void IsCorrectGenericType(ObjectContent objectContent, Type genericTypeParameter)
 {
     GenericTypeAssert.IsCorrectGenericType <ObjectContent>(objectContent, genericTypeParameter);
     Assert.AreEqual(genericTypeParameter, objectContent.Type, "objectContent.Type did not match its generic parameter.");
 }