示例#1
0
        public void Should_call_generic_method_where_value_type_is_first_parameter_and_has_value_return_type()
        {
            var a = 1;
            var b = new MethodInterceptorTargetParameter();
            var interceptorWasCalled = false;

            Intercept.Call +=
                (invocation) =>
                    {
                        interceptorWasCalled = true;
                        Assert.That(a, Is.EqualTo((int) invocation.ParameterValues[0]));
                        Assert.That(b, Is.EqualTo(invocation.ParameterValues[1]));
                    };

            InterceptInstance.GenericMethodWithInvertedParamsAndValueReturnType(1, b);
            Assert.That(interceptorWasCalled);
        }
示例#2
0
        public void Should_call_generic_method_with_two_generic_parameters()
        {
            var a = 1;
            var b = new MethodInterceptorTargetParameter();
            var interceptorWasCalled = false;

            Intercept.Call +=
                (invocation) =>
                    {
                        interceptorWasCalled = true;
                        Assert.That(a, Is.EqualTo((int) invocation.ParameterValues[0]));
                        Assert.That(b, Is.EqualTo(invocation.ParameterValues[1]));
                    };

            InterceptInstance.GenericMethodWithTwoGenericParameters(1, b);
            Assert.That(interceptorWasCalled);
        }
示例#3
0
        public void Should_call_generic_with_all_kinds_of_parameters_and_return_a_value_type()
        {
            var a = 1;
            double b = 2;
            var parameterClass = new MethodInterceptorTargetParameter();
            var interceptorWasCalled = false;

            Intercept.Call +=
                (invocation) =>
                    {
                        interceptorWasCalled = true;
                        Assert.That(a == (int) invocation.ParameterValues[1]);
                        Assert.That(b == (double) invocation.ParameterValues[2]);
                        Assert.That(parameterClass == invocation.ParameterValues[0]);

                        if (invocation.InvocationLifecycle == InvocationLifecycleType.AfterInvocation)
                            Assert.That(invocation.Result, Is.EqualTo(b));
                    };

            InterceptInstance.GenericMethodWithGenericParamsAndValueReturnType(parameterClass, a, b);
            Assert.That(interceptorWasCalled);
        }
示例#4
0
        public void Should_invoke_static_method_with_value_and_generic_with_value_return_type()
        {
            var a = new MethodInterceptorTargetParameter();
            var interceptorWasCalled = false;

            Intercept.Call +=
                (invocation) =>
                    {
                        interceptorWasCalled = true;
                        Assert.That((int) invocation.ParameterValues[0] == 1);
                        Assert.That(invocation.ParameterValues[1] == a);
                    };

            var result = MethodInterceptorTarget.StaticMethodWithGenericAndValueTypeArgsAndValueReturnType(1, a);
            Assert.That(result == 1);
            Assert.That(interceptorWasCalled);
        }
示例#5
0
        public void Should_intercept_method_with_class_args_and_call()
        {
            var a = new MethodInterceptorTargetParameter();
            var interceptorWasCalled = false;

            Intercept.Call +=
                (invocation) => { interceptorWasCalled = true; };

            InterceptInstance.HavingMethodWithClassArgsAndClassReturnType(a);
            Assert.That(interceptorWasCalled);
        }
示例#6
0
        public void Should_have_instance_when_calling_instance_method()
        {
            var a = 1;
            var b = new MethodInterceptorTargetParameter();
            var interceptorWasCalled = false;

            Intercept.Call +=
                (invocation) =>
                    {
                        interceptorWasCalled = true;
                        Assert.That(invocation.Instance, Is.Not.Null);
                    };

            InterceptInstance.GenericMethodWithInvertedParams(a, b);
            Assert.That(interceptorWasCalled);
        }
示例#7
0
        public void Should_call_to_generic_with_generic_parameters_and_value_types()
        {
            var a = 1;
            double b = 2;
            var parameterClass = new MethodInterceptorTargetParameter();
            var interceptorWasCalled = false;

            Intercept.Call +=
                (invocation) =>
                    {
                        interceptorWasCalled = true;
                        Assert.That(a, Is.EqualTo((int) invocation.ParameterValues[1]));
                        Assert.That(b, Is.EqualTo((double) invocation.ParameterValues[2]));
                        Assert.That(parameterClass, Is.EqualTo(invocation.ParameterValues[0]));

                        if (invocation.InvocationLifecycle == InvocationLifecycleType.AfterInvocation)
                            Assert.That(invocation.Result, Is.Null);
                    };

            InterceptInstance.GenericMethodWithGenericParametersAndValueTypeArgs(parameterClass, a, b);
            Assert.That(interceptorWasCalled);
        }
示例#8
0
        public void Should_call_to_generic_method_with_generic_parameters_and_generic_return_type()
        {
            var a = new MethodInterceptorTargetParameter();
            var interceptorWasCalled = false;

            Intercept.Call +=
                (invocation) =>
                    {
                        interceptorWasCalled = true;
                        Assert.That(a, Is.EqualTo(invocation.ParameterValues[0]));

                        if (invocation.InvocationLifecycle == InvocationLifecycleType.AfterInvocation)
                            Assert.That(invocation.Result, Is.EqualTo(a));
                    };

            InterceptInstance.GenericMethodWithGenericParametersAndGenericReturnType(a);
            Assert.That(interceptorWasCalled);
        }