コード例 #1
0
        public void ExecuteGenericMethod_CallNotExistingMethod_ThrowsException()
        {
            var instance = new GenericMethodTestClass();

            Assert.Throws <MissingMethodException>(() => instance.ExecuteGenericMethod("NotExisting",
                                                                                       new[] { new GenericArgument("T", typeof(int)) }, 1234));

            Assert.Throws <MissingMethodException>(() =>
                                                   instance.ExecuteGenericMethod <string>(nameof(GenericMethodTestClass.GetData),
                                                                                          new[]
            {
                new GenericArgument("T2", typeof(int)),
                new GenericArgument("T3", typeof(DateTime))
            },
                                                                                          123,
                                                                                          345));
        }
コード例 #2
0
        public void ExecuteGenericMethod_CallMethodWithResultAndType_MethodReturnsResult()
        {
            const int value    = 12345;
            var       instance = new GenericMethodTestClass();

            var result = instance.ExecuteGenericMethod <int>(nameof(GenericMethodTestClass.GetData),
                                                             new[] { typeof(int) }, value);

            Assert.Equal(value, result);
        }
コード例 #3
0
        public void ExecuteGenericMethod_CallVoidMethodWithType_MethodWasCalled()
        {
            const int value    = 1234;
            var       instance = new GenericMethodTestClass();

            instance.ExecuteGenericMethod(nameof(GenericMethodTestClass.DoSomething),
                                          new[] { typeof(int) }, value);

            Assert.Equal(value.ToString(), instance.Data);
        }
コード例 #4
0
        public void ExecuteGenericMethod_CallMethodWithResultAndTwoGenericTypeParametersAndTypeNotExactlyMatching_MethodReturnsResult()
        {
            var value    = new TestDataClassSpecial();
            var dateTime = DateTime.Now;

            var instance = new GenericMethodTestClass();

            var result = instance.ExecuteGenericMethod <string>(nameof(GenericMethodTestClass.GetData),
                                                                new[]
            {
                typeof(TestDataClassBase),
                typeof(DateTime)
            },
                                                                value,
                                                                dateTime);

            Assert.Equal(value.ToString() + dateTime, result);
        }
コード例 #5
0
        public void ExecuteGenericMethod_CallMethodWithResultAndTwoGenericTypeParametersAndType_MethodReturnsResult()
        {
            const int value    = 12345;
            var       dateTime = DateTime.Now;

            var instance = new GenericMethodTestClass();

            var result = instance.ExecuteGenericMethod <string>(nameof(GenericMethodTestClass.GetData),
                                                                new[]
            {
                typeof(int),
                typeof(DateTime)
            },
                                                                value,
                                                                dateTime);

            Assert.Equal(value.ToString() + dateTime, result);
        }