コード例 #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);
        }
コード例 #2
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);