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); } } }); }
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 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); }
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."); }); }
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 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 })); }); }
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); }); }
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" })); }
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."); } }); }
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."); } }); }
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); } }); }
/// <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); }); }
/// <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); }); }
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 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 }); }); } } }); }