Exemplo n.º 1
0
        public async Task GenericTaskWithSecondOverloadedValueTypeMethodAsync()
        {
            // Given
            var proxyFactory            = CreateFactory();
            var interceptor             = new AsyncGenericValueTypeTaskInterceptor();
            var firstExpectedValueType  = 13;
            var secondExpectedValueType = 42.0;

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

            // Then
            Assert.NotNull(foo);
            Assert.Equal(42, result);

            var invocation = interceptor.ForwardedInvocations.Single();

            invocation.ShouldInterceptMethodWithName(nameof(IFooGenericTaskValueTypeOverloads.MethodWithOverloadAsync));
            invocation.ShouldBeAsyncInvocationOfType(AsyncInvocationType.GenericTask);
            invocation.ShouldHaveParameterInCountOf(2);
            invocation.ShouldHaveParameterIn("first", typeof(int), firstExpectedValueType);
            invocation.ShouldHaveParameterIn("second", typeof(double), secondExpectedValueType);
        }
Exemplo n.º 2
0
        public async Task GenericTaskWithoutValueTypeParametersAsync()
        {
            // Given
            var proxyFactory = CreateFactory();
            var interceptor  = new AsyncGenericValueTypeTaskInterceptor();

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

            // Then
            Assert.NotNull(foo);
            Assert.Equal(42, result);

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

            invocation.ShouldInterceptMethodWithName(nameof(IFooGenericTaskValueTypeParameterless.MethodWithoutParameterAsync));
            invocation.ShouldBeAsyncInvocationOfType(AsyncInvocationType.GenericTask);
            invocation.ShouldHaveNoParameterIn();
        }