예제 #1
0
        public void PropertySetterValueTypeIntercepted <T>(T expectedValue)
            where T : struct
        {
            // Given
            var proxyFactory = Context.ProxyFactory;
            var interceptor  = new SetterInterceptor(true);
            var decoratee    = new FooValueTypeSetter <T>();

            // When
            var foo = proxyFactory.CreateDecorator <IFooValueTypeSetter <T> >(decoratee, interceptor);

            foo.Setter = expectedValue;

            // Then
            Assert.NotNull(foo);
            Assert.Equal(0u, decoratee.CallCount);
            Assert.Equal(default, decoratee.Value);
예제 #2
0
        public void PropertySetterValueType <T>(T expectedValue)
            where T : struct
        {
            // Given
            var proxyFactory = Context.ProxyFactory;
            var interceptor  = new SetterInterceptor(false);
            var decoratee    = new FooValueTypeSetter <T>();

            // When
            var foo = proxyFactory.CreateDecorator <IFooValueTypeSetter <T> >(decoratee, interceptor);

            foo.Setter = expectedValue;

            // Then
            Assert.NotNull(foo);
            Assert.Equal(1u, decoratee.CallCount);
            Assert.Equal(expectedValue, decoratee.Value);

            Assert.Single(interceptor.ForwardedInvocations);
            var invocation = interceptor.ForwardedInvocations.Single();

            invocation.ShouldInterceptPropertyWithName(nameof(IFooValueTypeSetter <T> .Setter));
            invocation.ShouldHavePropertyValue(typeof(T), expectedValue);
        }