Пример #1
0
        public void TryResolveGenericMethod_WithArgumentsNotMatchingTypeConstraint_ReturnsFalse()
        {
            var typeArgs = new[]
            {
                typeof(IEnumerable <int>), typeof(bool), typeof(string), typeof(Tuple <int, Func <bool, Guid> >),
                typeof(Guid)
            };

            MethodInfo methodInstance;

            Assert.That(GenericTestMethodInfo.TryResolveGenericMethod(typeArgs, out methodInstance), Is.False);
        }
Пример #2
0
        public void TryResolveGenericMethod_WithArgumentsNotMatchingStructConstraint_ReturnsFalse()
        {
            // type AppDomain does not satisfy TStruct: struct
            var typeArgs = new[]
            {
                typeof(IEnumerable <int>), typeof(MemoryStream), typeof(string),
                typeof(Tuple <int, Func <MemoryStream, bool?> >), typeof(bool?)
            };

            MethodInfo methodInstance;

            Assert.That(GenericTestMethodInfo.TryResolveGenericMethod(typeArgs, out methodInstance), Is.False);
        }
Пример #3
0
        public void TryResolveGenericMethod_WithSomeArgumentsInherited_ResolvesMethod()
        {
            var typeArgs = new[]
            {
                typeof(IGrouping <Uri, int>), typeof(MemoryStream), typeof(string),
                typeof(Tuple <int, Func <MemoryStream, Guid> >), typeof(Guid)
            };

            MethodInfo methodInstance;

            Assert.That(GenericTestMethodInfo.TryResolveGenericMethod(typeArgs, out methodInstance), Is.EqualTo(true));
            Assert.That(methodInstance.GetGenericArguments(),
                        Is.EquivalentTo(new[] { typeof(int), typeof(MemoryStream), typeof(Guid) }));
        }
Пример #4
0
        public void TryResolveGenericMethod_WithPerfectlyMatchingArguments_ResolvesMethod()
        {
            // Should make GenericTestMethodInfo instance with <int,MemoryStream,Guid>
            var typeArgs = new[]
            {
                typeof(IEnumerable <int>), typeof(MemoryStream), typeof(string),
                typeof(Tuple <int, Func <MemoryStream, Guid> >), typeof(Guid)
            };

            MethodInfo methodInstance;

            Assert.That(GenericTestMethodInfo.TryResolveGenericMethod(typeArgs, out methodInstance), Is.EqualTo(true));
            Assert.That(methodInstance.GetGenericArguments(),
                        Is.EquivalentTo(new[] { typeof(int), typeof(MemoryStream), typeof(Guid) }));
        }