Beispiel #1
0
        public void AreSameTypesShouldReturnFalseWithDifferentTypes()
        {
            var first  = typeof(List <>);
            var second = typeof(int);

            Assert.False(Reflection.AreSameTypes(first, second));
        }
Beispiel #2
0
        public void AreSameTypesShouldReturnFalseWithInheritedTypes()
        {
            var first  = typeof(List <>);
            var second = typeof(IEnumerable <>);

            Assert.False(Reflection.AreSameTypes(first, second));
        }
Beispiel #3
0
        public void AreSameTypesShouldReturnTrueWithSameTypes()
        {
            var first  = typeof(int);
            var second = typeof(int);

            Assert.True(Reflection.AreSameTypes(first, second));
        }
Beispiel #4
0
        public void AreSameTypesShouldReturnFalseWithObjectsOfDifferentTypes()
        {
            var first  = 1;
            var second = "Test";

            Assert.False(Reflection.AreSameTypes(first, second));
        }
Beispiel #5
0
        public void AreSameTypesShouldReturnTrueWithObjectsOfSameTypes()
        {
            var first  = "Test";
            var second = "Another Test";

            Assert.True(Reflection.AreSameTypes(first, second));
        }
        public void GetDefaultMediaTypeFormattersShouldReturnProperFormatters()
        {
            var defaultFormatters = MediaTypeFormatterValidator.GetDefaultMediaTypeFormatters();

            Assert.IsNotNull(defaultFormatters);

            var result = defaultFormatters
                         .All(f => Reflection.AreSameTypes(f.GetType(), typeof(FormUrlEncodedMediaTypeFormatter)) ||
                              Reflection.AreSameTypes(f.GetType(), typeof(JQueryMvcFormUrlEncodedFormatter)) ||
                              Reflection.AreSameTypes(f.GetType(), typeof(JsonMediaTypeFormatter)) ||
                              Reflection.AreSameTypes(f.GetType(), typeof(XmlMediaTypeFormatter)));

            Assert.AreEqual(4, defaultFormatters.Count());
            Assert.IsTrue(result);
        }
Beispiel #7
0
        public static ActionTestContext ConvertMethodResult(this ActionTestContext testContext)
        {
            var methodReturnType = testContext.Method.ReturnType;

            if (Reflection.AreAssignableByGeneric(ActionResultGenericType, methodReturnType))
            {
                var methodResultType = testContext.MethodResult.GetType();

                if (Reflection.AreSameTypes(ObjectResultType, methodResultType))
                {
                    var objectResult = testContext.MethodResult as ObjectResult;

                    testContext.MethodResult = objectResult?.Value;
                }
            }

            return(testContext);
        }
Beispiel #8
0
        /// <summary>
        /// Tests whether the resolved route will not be handled by a HttpMessageHandler of the provided type.
        /// </summary>
        /// <typeparam name="THandler">Type of HttpMessageHandler.</typeparam>
        /// <returns>The same route test builder.</returns>
        public IAndResolvedRouteTestBuilder ToNoHandlerOfType <THandler>()
            where THandler : HttpMessageHandler
        {
            var actualHandler = this.GetActualRouteInfo().HttpMessageHandler;

            if (actualHandler != null)
            {
                var expectedHandlerType = typeof(THandler);
                var actualHandlerType   = actualHandler.GetType();

                if (Reflection.AreSameTypes(expectedHandlerType, actualHandlerType))
                {
                    this.ThrowNewRouteAssertionException(
                        string.Format("not be handled by {0}", expectedHandlerType.ToFriendlyTypeName()),
                        "in fact found the same type of handler");
                }
            }

            return(this);
        }