Ejemplo n.º 1
0
        public void Intercept(Castle.DynamicProxy.IInvocation invocation)
        {
            var method = invocation.GetConcreteMethod();

            method = invocation.InvocationTarget.GetType().
                     GetMethod(method.Name);

            if (method != null)
            {
                var attribute = method.GetCustomAttribute <MyTimerAttribute>();
                try
                {
                    if (attribute != null)
                    {
                        var sw = new Stopwatch();
                        sw.Start();
                        Console.WriteLine("Starting the log in Timer Interceptor");


                        invocation.Proceed();

                        sw.Stop();
                        Console.WriteLine($"Ending the log, ellapsed: {sw.ElapsedMilliseconds} ms");
                    }
                    else
                    {
                        invocation.Proceed();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception occurred in method: {invocation.Method.Name}: {ex.Message} ");
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Checks the last method invocation on the mock;
        ///     if Add was invoked the unexpected match is set up;
        /// </summary>
        /// <param name="invocation">The proxied method invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            try
            {
                invocation.Proceed();
            }
            finally
            {
                if (invocation.ReturnValue != null && invocation.ReturnValue is IInvocationList mockInvocations)
                {
                    if (mockInvocations.Any() && mockInvocations.Last().Method.Name.Equals("Add"))
                    {
                        Logger.LogDebug("I have detected that the previous mock invocation was an add");

                        var lastInvocation = mockInvocations.Last();
                        var methodInfo     = lastInvocation.Method;
                        var args           = lastInvocation.Arguments;

                        //We have everything we need to set up a match, so let's do it
                        var key   = args[0].ToString();
                        var value = args[1];

                        ProjectReflectionShortcuts.SetUpCacheEntryMethod(value.GetType()).Invoke(null, new[] { ((Mock <IAppCache>)invocation.Proxy).Object, key, value });
                    }
                }
            }
        }
Ejemplo n.º 3
0
            public void Intercept(Castle.DynamicProxy.IInvocation invocation)
            {
                if (invocation == null)
                {
                    throw new ArgumentNullException(nameof(invocation));
                }

                if (!object.Equals(invocation.InvocationTarget, _invocationTarget))
                {
                    var changeProxyTarget = (IChangeProxyTarget)invocation;
                    changeProxyTarget.ChangeInvocationTarget(_invocationTarget);
                    changeProxyTarget.ChangeProxyTarget(_invocationTarget);
                }

                invocation.Proceed();
            }
 public void Intercept(Castle.DynamicProxy.IInvocation invocation)
 {
     if (setters.ContainsKey(invocation.Method))
     {
         var prop = setters[invocation.Method];
         storage.Set(prop.Name, invocation.Arguments[0]);
         obs.OnNext(prop.Name);
     }
     else if (getters.ContainsKey(invocation.Method))
     {
         invocation.ReturnValue = storage.Get(getters[invocation.Method].Name);
     }
     else
     {
         invocation.Proceed(); //DataStorageInterceptor only implements properties, not methods
     }
 }
Ejemplo n.º 5
0
                public void Intercept(Castle.DynamicProxy.IInvocation invocation)
                {
                    if (invocation.Method.Name == nameof(IDisposable.Dispose))
                    {
                        Dispose();
                        return;
                    }
                    var parent = parent_;

                    if (invocation.InvocationTarget == parent)
                    {
                        invocation.Proceed();
                    }
                    else
                    {
                        invocation.ReturnValue = parent.interceptorHandler.Intercept(parent.Parent, invocation.Method, invocation.Arguments);
                    }
                }
Ejemplo n.º 6
0
        /// <inheritdoc />
        public void Intercept(IInvocation invocation)
        {
            object Proceed(object target, object[] arguments)
            {
                invocation.Proceed();
                return(invocation.ReturnValue);
            }

            var signature = new InvocationSignature(
                invocation.Method,
                invocation.MethodInvocationTarget,
                typeof(TService),
                typeof(TImplementation),
                invocation.Method.GetInvocationType());

            invocation.ReturnValue = _invocationInterceptor.Intercept(
                signature, Proceed, invocation.Arguments,
                invocation.InvocationTarget, invocation.Proxy);
        }
 public void Intercept(IInvocation invocation)
 {
     _logger.LogInformation("Calling method: {name}", invocation.Method.Name);
     invocation.Proceed();
 }