public async Task AsyncEnumerableValueTypeWithSingleParameterAsync() { // Given var proxyFactory = Context.ProxyFactory; var expectedValue = 17; var expectedResults = new[] { 13, 42, 99 }; var interceptor = new AsyncEnumerableInterceptor <int>(Array.Empty <int>(), false); var decoratee = new FooAsyncEnumerableValueTypeParameter(expectedResults); var actualResults = new List <int>(); // When var foo = proxyFactory.CreateDecorator <IFooAsyncEnumerableValueTypeParameter>(decoratee, interceptor); var task = foo.MethodWithOneParameterAsync(expectedValue); await foreach (var result in task.ConfigureAwait(false)) { actualResults.Add(result); } // Then Assert.NotNull(foo); Assert.Equal(3, actualResults.Count); Assert.Equal(expectedResults, actualResults); Assert.Equal(1u, decoratee.CallCount); Assert.Single(interceptor.ForwardedInvocations); var invocation = interceptor.ForwardedInvocations.Single(); invocation.ShouldInterceptMethodWithName(nameof(IFooAsyncEnumerableValueTypeParameter.MethodWithOneParameterAsync)); invocation.ShouldBeAsyncInvocationOfType(AsyncInvocationType.AsyncEnumerable); invocation.ShouldHaveParameterInCountOf(1); invocation.ShouldHaveParameterIn("first", typeof(int), expectedValue); }
public async Task AsyncEnumerableReferenceTypeWithoutParametersInterceptedAsync() { // Given var proxyFactory = Context.ProxyFactory; var expectedResults = new object?[] { new object(), null, new object() }; var interceptor = new AsyncEnumerableInterceptor <object?>(expectedResults, true); var decoratee = new FooAsyncEnumerableReferenceTypeParameterless(Array.Empty <object?>()); var actualResults = new List <object?>(); // When var foo = proxyFactory.CreateDecorator <IFooAsyncEnumerableReferenceTypeParameterless>(decoratee, interceptor); var task = foo.MethodWithoutParameterAsync(); await foreach (var result in task.ConfigureAwait(false)) { actualResults.Add(result); } // Then Assert.NotNull(foo); Assert.Equal(3, actualResults.Count); Assert.Equal(expectedResults, actualResults); Assert.Equal(0u, decoratee.CallCount); Assert.Single(interceptor.ForwardedInvocations); var invocation = interceptor.ForwardedInvocations.Single(); invocation.ShouldInterceptMethodWithName(nameof(IFooAsyncEnumerableValueTypeParameterless.MethodWithoutParameterAsync)); invocation.ShouldBeAsyncInvocationOfType(AsyncInvocationType.AsyncEnumerable); invocation.ShouldHaveNoParameterIn(); }