예제 #1
0
        public void ShouldWrapCall()
        {
            // Given
            var testClass   = new TestClass();
            var proxyObject = _sut.CreateProxy(testClass);

            // When
            var result = proxyObject.GetNextInt(2);

            // Then
            Assert.Equal(3, result);
        }
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }