public void Setup()
        {
            _argument = 7;
            _object   = new NextIntClass();

            var castleCoreFactory = new CastleCoreProxyFactory <INextIntInterface>();

            _castleCoreProxy = castleCoreFactory.CreateProxy(_object, new ProceedInterceptor());
        }
        public void ShouldThrowExceptionIfUnnderlyingObjectIsNull()
        {
            // Given
            var sut = new CastleCoreProxyFactory <ICollection>();

            // When
            Action action = () => sut.CreateProxy(null);

            // Then
            var exception = Assert.Throws <CaishenException>(action);

            Assert.Equal(CaishenExceptionReason.UnderlyingObjectIsNull, exception.Reason);
        }
        public void IfNotInterruptShouldCallUnderlyingObjectMethod()
        {
            // Given
            var testClass   = new TestClass();
            var interceptor = new LastInvocationInterceptor();
            var factory     = new CastleCoreProxyFactory <ITestClass>();
            var proxy       = factory.CreateProxy(testClass, interceptor);

            // When
            var result = proxy.GetNextInt(10);

            // Then
            Assert.Equal(11, result);
        }
        public void ShouldBePossibleToOverwriteValue()
        {
            // Given
            var testClass   = new TestClass();
            var interceptor = new ValueOverwritingInterceptor(20);
            var factory     = new CastleCoreProxyFactory <ITestClass>();
            var proxy       = factory.CreateProxy(testClass, interceptor);

            // When
            var result = proxy.GetNextInt(10);

            // Then
            Assert.Equal(20, result);
        }
        public void ShouldIntercept()
        {
            // Given
            var testClass   = new TestClass();
            var interceptor = new LastInvocationInterceptor();
            var factory     = new CastleCoreProxyFactory <ITestClass>();
            var proxy       = factory.CreateProxy(testClass, interceptor);

            // When
            proxy.GetNextInt(10);

            // Then
            var invocation = interceptor.LastInvocationParameter;

            Assert.NotNull(invocation);
            Assert.Equal(nameof(testClass.GetNextInt), invocation.Method.Name);
        }
        public void ShouldPassArguments()
        {
            // Given
            var testClass   = new TestClass();
            var interceptor = new LastInvocationInterceptor();
            var factory     = new CastleCoreProxyFactory <ITestClass>();
            var proxy       = factory.CreateProxy(testClass, interceptor);

            // When
            proxy.GetNextInt(10);

            // Then
            var invocation = interceptor.LastInvocationParameter;

            Assert.NotNull(invocation);
            var argument = Assert.Single(invocation.Arguments);

            Assert.Equal(10, argument);
        }