Exemple #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);
        public void PropertySetterReferenceType <T>(T?expectedValue)
            where T : class
        {
            // Given
            var proxyFactory = Context.ProxyFactory;
            var interceptor  = new SetterInterceptor();

            // When
            var foo = proxyFactory.CreateForInterface <IFooReferenceTypeSetter <T> >(interceptor);

            foo.Setter = expectedValue;

            // Then
            Assert.NotNull(foo);

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

            invocation.ShouldInterceptPropertyWithName(nameof(IFooReferenceTypeSetter <T> .Setter));
            invocation.ShouldHavePropertyValue(typeof(T), expectedValue);
        }
        public void PropertyIndexedSetterValueType <T>(T expectedValue, T expectedIndex)
            where T : struct
        {
            // Given
            var proxyFactory = Context.ProxyFactory;
            var interceptor  = new SetterInterceptor();

            // When
            var foo = proxyFactory.CreateForInterface <IFooValueTypeIndexedSetter <T> >(interceptor);

            foo[expectedIndex] = expectedValue;

            // Then
            Assert.NotNull(foo);

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

            invocation.ShouldInterceptPropertyWithName("Item");
            invocation.ShouldHavePropertyValue(typeof(T), expectedValue);
            invocation.ShouldHaveParameterInCountOf(1);
            invocation.ShouldHaveParameterIn("first", typeof(T), expectedIndex);
        }
Exemple #4
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);
        }