示例#1
0
        public async Task ValueTaskWithSingleValueTypeParameterAsync()
        {
            // Given
            var proxyFactory      = Context.ProxyFactory;
            var interceptor       = new AsyncInterceptor(false);
            var expectedValueType = 13;
            var decoratee         = new FooValueTaskValueTypeParameter();

            // When
            var foo  = proxyFactory.CreateDecorator <IFooValueTaskValueTypeParameter>(decoratee, interceptor);
            var task = foo.MethodWithOneParameterAsync(expectedValueType);
            await task.ConfigureAwait(false);

            // Then
            Assert.NotNull(foo);
            Assert.Equal(1u, decoratee.CallCount);
            Assert.Equal(expectedValueType, decoratee.Parameter);

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

            invocation.ShouldInterceptMethodWithName(nameof(IFooValueTaskValueTypeParameter.MethodWithOneParameterAsync));
            invocation.ShouldBeAsyncInvocationOfType(AsyncInvocationType.ValueTask);
            invocation.ShouldHaveParameterInCountOf(1);
            invocation.ShouldHaveParameterIn("first", typeof(int), expectedValueType);
        }
        public async Task Should_Intercept_Asynchronous_Methods_With_An_Async_Operations_Prior_To_Calling_Proceed()
        {
            // Arrange
            IInterfaceWithAsynchronousMethod target = new ClassWithAsynchronousMethod();
            IInterceptor interceptor = new AsyncInterceptor();

            IInterfaceWithAsynchronousMethod proxy =
                generator.CreateInterfaceProxyWithTargetInterface(target, interceptor);

            // Act
            await proxy.Method().ConfigureAwait(false);
        }
示例#3
0
        public async Task ValueTaskWithSingleValueTypeParameterInterceptedAsync()
        {
            // Given
            var proxyFactory      = Context.ProxyFactory;
            var interceptor       = new AsyncInterceptor(true);
            var expectedValueType = 13;
            var decoratee         = new FooValueTaskValueTypeParameter();

            // When
            var foo  = proxyFactory.CreateDecorator <IFooValueTaskValueTypeParameter>(decoratee, interceptor);
            var task = foo.MethodWithOneParameterAsync(expectedValueType);
            await task.ConfigureAwait(false);

            // Then
            Assert.NotNull(foo);
            Assert.Equal(0u, decoratee.CallCount);
            Assert.Equal(default, decoratee.Parameter);
        public async Task TaskWithoutParametersAsync()
        {
            // Given
            var proxyFactory = CreateFactory();
            var interceptor  = new AsyncInterceptor();

            // When
            var foo  = proxyFactory.CreateForInterface <IFooTaskParameterless>(interceptor);
            var task = foo.MethodWithoutParameterAsync();
            await task.ConfigureAwait(false);

            // Then
            Assert.NotNull(foo);

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

            invocation.ShouldInterceptMethodWithName(nameof(IFooTaskParameterless.MethodWithoutParameterAsync));
            invocation.ShouldBeAsyncInvocationOfType(AsyncInvocationType.Task);
            invocation.ShouldHaveNoParameterIn();
        }
        public async Task TaskWithFirstOverloadedReferenceTypeMethodAsync()
        {
            // Given
            var proxyFactory          = CreateFactory();
            var interceptor           = new AsyncInterceptor();
            var expectedReferenceType = typeof(int);

            // When
            var foo  = proxyFactory.CreateForInterface <IFooTaskReferenceTypeOverloads>(interceptor);
            var task = foo.MethodWithOverloadAsync(expectedReferenceType);
            await task.ConfigureAwait(false);

            // Then
            Assert.NotNull(foo);

            var invocation = interceptor.ForwardedInvocations.Single();

            invocation.ShouldInterceptMethodWithName(nameof(IFooTaskReferenceTypeOverloads.MethodWithOverloadAsync));
            invocation.ShouldBeAsyncInvocationOfType(AsyncInvocationType.Task);
            invocation.ShouldHaveParameterInCountOf(1);
            invocation.ShouldHaveParameterIn("first", typeof(object), expectedReferenceType);
        }
示例#6
0
        public async Task ValueTaskWithoutParametersInterceptedAsync()
        {
            // Given
            var proxyFactory = Context.ProxyFactory;
            var interceptor  = new AsyncInterceptor(true);
            var decoratee    = new FooValueTaskParameterless();

            // When
            var foo  = proxyFactory.CreateDecorator <IFooValueTaskParameterless>(decoratee, interceptor);
            var task = foo.MethodWithoutParameterAsync();
            await task.ConfigureAwait(false);

            // Then
            Assert.NotNull(foo);
            Assert.Equal(0u, decoratee.CallCount);

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

            invocation.ShouldInterceptMethodWithName(nameof(IFooValueTaskParameterless.MethodWithoutParameterAsync));
            invocation.ShouldBeAsyncInvocationOfType(AsyncInvocationType.ValueTask);
            invocation.ShouldHaveNoParameterIn();
        }
示例#7
0
        public async Task ValueTaskWithSecondOverloadedValueTypeMethodAsync()
        {
            // Given
            var proxyFactory            = CreateFactory();
            var interceptor             = new AsyncInterceptor();
            var firstExpectedValueType  = 13;
            var secondExpectedValueType = 42.0;

            // When
            var foo  = proxyFactory.CreateForInterface <IFooValueTaskValueTypeOverloads>(interceptor);
            var task = foo.MethodWithOverloadAsync(firstExpectedValueType, secondExpectedValueType);
            await task.ConfigureAwait(false);

            // Then
            Assert.NotNull(foo);

            var invocation = interceptor.ForwardedInvocations.Single();

            invocation.ShouldInterceptMethodWithName(nameof(IFooValueTaskValueTypeOverloads.MethodWithOverloadAsync));
            invocation.ShouldBeAsyncInvocationOfType(AsyncInvocationType.ValueTask);
            invocation.ShouldHaveParameterInCountOf(2);
            invocation.ShouldHaveParameterIn("first", typeof(int), firstExpectedValueType);
            invocation.ShouldHaveParameterIn("second", typeof(double), secondExpectedValueType);
        }