Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void Should_call_to_generic_method_with_generic_parameters()
        {
            var a = new MethodInterceptorTargetParameter();
            var interceptorWasCalled = false;

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

            InterceptInstance.GenericMethodWithGenericParameters(a);
            Assert.That(interceptorWasCalled);
        }
Ejemplo n.º 3
0
        public void Should_invoke_static_method_with_value_and_generic_with_no_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);
            };

            MethodInterceptorTarget.StaticMethodWithGenericAndValueTypeArgsAndNoReturnType(1, a);
            Assert.That(interceptorWasCalled);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }