public void Construct()
        {
            var invocationMock = new Mock<IInvocation>();
            var loggerMock = new Mock<ILogger>();

            var adapter = new CastleInvocationToAlternateMethodContextAdapter(invocationMock.Object, loggerMock.Object, new Mock<IMessageBroker>().Object, new Mock<IProxyFactory>().Object, () => new ExecutionTimer(Stopwatch.StartNew()), () => RuntimePolicy.On);

            Assert.Equal(invocationMock.Object, adapter.Invocation);
            Assert.Equal(loggerMock.Object, adapter.Logger);
        }
        public void ReturnInvocationTargetFromInvocation()
        {
            var expected = new { Any = "Object" };
            var invocationMock = new Mock<IInvocation>();
            invocationMock.Setup(i => i.InvocationTarget).Returns(expected);
            var loggerMock = new Mock<ILogger>();

            var adapter = new CastleInvocationToAlternateMethodContextAdapter(invocationMock.Object, loggerMock.Object, new Mock<IMessageBroker>().Object, new Mock<IProxyFactory>().Object, () => new ExecutionTimer(Stopwatch.StartNew()), () => RuntimePolicy.On);

            Assert.Equal(expected, adapter.InvocationTarget);
            invocationMock.Verify(i => i.InvocationTarget, Times.Once());
        }
        public void SetReturnValueOnInvocation()
        {
            var expected = new { Any = "Object" };
            var invocationMock = new Mock<IInvocation>();
            var loggerMock = new Mock<ILogger>();

            var adapter = new CastleInvocationToAlternateMethodContextAdapter(invocationMock.Object, loggerMock.Object, new Mock<IMessageBroker>().Object, new Mock<IProxyFactory>().Object, () => new ExecutionTimer(Stopwatch.StartNew()), () => RuntimePolicy.On);

            adapter.ReturnValue = expected;
            
            invocationMock.VerifySet(i=>i.ReturnValue = expected, Times.Once());
        }
 /// <summary>
 /// Intercepts the specified invocation.
 /// </summary>
 /// <param name="invocation">The invocation.</param>
 public void Intercept(IInvocation invocation)
 {
     var context = new CastleInvocationToAlternateMethodContextAdapter(invocation, Logger, MessageBroker, ProxyFactory, TimerStrategy, RuntimePolicyStrategy);
     Implementation.NewImplementation(context);
 }
Example #5
0
        /// <summary>
        /// Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            var context = new CastleInvocationToAlternateMethodContextAdapter(invocation, Logger, MessageBroker, ProxyFactory, TimerStrategy, RuntimePolicyStrategy);

            Implementation.NewImplementation(context);
        }
        public void ProceedOnInvocation()
        {
            var invocationMock = new Mock<IInvocation>();
            var loggerMock = new Mock<ILogger>();

            var adapter = new CastleInvocationToAlternateMethodContextAdapter(invocationMock.Object, loggerMock.Object, new Mock<IMessageBroker>().Object, new Mock<IProxyFactory>().Object, () => new ExecutionTimer(Stopwatch.StartNew()), () => RuntimePolicy.On);

            adapter.Proceed();
            invocationMock.Verify(i => i.Proceed(), Times.Once());
        }
        public void ReturnGetConcreteMethodFromInvocation()
        {
            var expected = GetType().GetMethods().First();
            var invocationMock = new Mock<IInvocation>();
            invocationMock.Setup(i => i.GetConcreteMethod()).Returns(expected);
            var loggerMock = new Mock<ILogger>();

            var adapter = new CastleInvocationToAlternateMethodContextAdapter(invocationMock.Object, loggerMock.Object, new Mock<IMessageBroker>().Object, new Mock<IProxyFactory>().Object, () => new ExecutionTimer(Stopwatch.StartNew()), () => RuntimePolicy.On);

            Assert.Equal(expected, adapter.GetConcreteMethod());
            invocationMock.Verify(i => i.GetConcreteMethod(), Times.Once());
        }
        public void ReturnGenericArgumentsFromInvocation()
        {
            var expected = new Type[] { typeof(object), typeof(string)};
            var invocationMock = new Mock<IInvocation>();
            invocationMock.Setup(i => i.GenericArguments).Returns(expected);
            var loggerMock = new Mock<ILogger>();

            var adapter = new CastleInvocationToAlternateMethodContextAdapter(invocationMock.Object, loggerMock.Object, new Mock<IMessageBroker>().Object, new Mock<IProxyFactory>().Object, () => new ExecutionTimer(Stopwatch.StartNew()), () => RuntimePolicy.On);

            Assert.Equal(expected, adapter.GenericArguments);
            invocationMock.Verify(i => i.GenericArguments, Times.Once());
        }