public void Intercept_WhenInvocationIsNotDispatchProxyInvocation_ThenThrowInvalidCastException()
        {
            var interceptorMock = new Mock <DispatchProxyInterceptor>();

            var interceptronInterceptorAdapter = new InterceptronInterceptorAdapter(interceptorMock.Object);

            Assert.Throws <InvalidCastException>(() => interceptronInterceptorAdapter.Intercept("Not an invocation"));
        }
        public void Ctor_WhenInterceptorIsNotNull_ThenReturnNewInterceptronInterceptorAdapter()
        {
            var interceptorMock = new Mock <DispatchProxyInterceptor>();

            var interceptronInterceptorAdapter = new InterceptronInterceptorAdapter(interceptorMock.Object);

            Assert.IsNotNull(interceptronInterceptorAdapter);
        }
        public void Intercept_WhenInvocationIsNull_ThenThrowArgumentNullException()
        {
            var interceptorMock = new Mock <DispatchProxyInterceptor>();

            var interceptronInterceptorAdapter = new InterceptronInterceptorAdapter(interceptorMock.Object);

            Assert.Throws <ArgumentNullException>(() => interceptronInterceptorAdapter.Intercept(null));
        }
        public void Intercept()
        {
            var expectedReturnedValue = "Returned value";
            var interceptorMock       = new Mock <IInterceptor>();
            var invocationMock        = new Mock <Castle.DynamicProxy.IInvocation>();

            invocationMock.Setup(i => i.ReturnValue).Returns(expectedReturnedValue);
            var interceptronInterceptorAdapter = new InterceptronInterceptorAdapter(interceptorMock.Object);

            var actualReturnedValue = interceptronInterceptorAdapter.Intercept(invocationMock.Object);

            Assert.AreEqual(expectedReturnedValue, actualReturnedValue);
            interceptorMock.Verify(i => i.Intercept(invocationMock.Object), Times.Once);
        }
        public void Intercept_WhenInvocationIsNotDispatchProxyInvocation_ThenThrowInvalidCastExceptiona()
        {
            var expectedReturnedValue = "Returned value";
            var interceptorMock       = new Mock <DispatchProxyInterceptor>();

            interceptorMock.Setup(i => i.Intercept(It.IsAny <DispatchProxyInvocation>()))
            .Returns(expectedReturnedValue);
            var invocation = new DispatchProxyInvocation(null, null, null);
            var interceptronInterceptorAdapter = new InterceptronInterceptorAdapter(interceptorMock.Object);

            var actualReturnedValue = interceptronInterceptorAdapter.Intercept(invocation);

            Assert.AreEqual(expectedReturnedValue, actualReturnedValue);
            Assert.AreEqual(interceptorMock.Object, interceptronInterceptorAdapter.Interceptor);
            interceptorMock.Verify(i => i.Intercept(invocation), Times.Once);
        }