コード例 #1
0
ファイル: InterceptorTests.cs プロジェクト: Offline24/Caishen
        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);
        }
コード例 #2
0
ファイル: InterceptorTests.cs プロジェクト: Offline24/Caishen
        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);
        }
コード例 #3
0
ファイル: InterceptorTests.cs プロジェクト: Offline24/Caishen
        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);
        }