Exemplo n.º 1
0
        public async Task Ensure_Executor_Is_Correctly_Swapped_When_Evicted()
        {
            // arrange
            IRequestExecutorResolver resolver =
                new ServiceCollection()
                .AddGraphQL()
                .AddStarWarsRepositories()
                .AddStarWarsTypes()
                .Services
                .BuildServiceProvider()
                .GetRequiredService <IRequestExecutorResolver>();
            var evicted = false;
            var updated = false;

            var proxy = new RequestExecutorProxy(resolver, Schema.DefaultName);

            proxy.ExecutorEvicted += (sender, args) =>
            {
                evicted = true;
                updated = false;
            };
            proxy.ExecutorUpdated += (sender, args) => updated = true;

            // act
            IRequestExecutor a = await proxy.GetRequestExecutorAsync(CancellationToken.None);

            resolver.EvictRequestExecutor();
            IRequestExecutor b = await proxy.GetRequestExecutorAsync(CancellationToken.None);

            // assert
            Assert.NotSame(a, b);
            Assert.True(evicted);
            Assert.True(updated);
        }
Exemplo n.º 2
0
        public async Task Ensure_Executor_Is_Cached()
        {
            // arrange
            IRequestExecutorResolver resolver =
                new ServiceCollection()
                .AddGraphQL()
                .AddStarWarsRepositories()
                .AddStarWarsTypes()
                .Services
                .BuildServiceProvider()
                .GetRequiredService <IRequestExecutorResolver>();

            // act
            var proxy          = new RequestExecutorProxy(resolver, Schema.DefaultName);
            IRequestExecutor a = await proxy.GetRequestExecutorAsync(CancellationToken.None);

            IRequestExecutor b = await proxy.GetRequestExecutorAsync(CancellationToken.None);

            // assert
            Assert.Same(a, b);
        }
        /// <summary>
        /// Creates a new auto-update proxy for <see cref="IRequestExecutor"/>.
        /// </summary>
        /// <param name="requestExecutorProxy">
        /// The underlying manual proxy.
        /// </param>
        /// <param name="cancellationToken">
        /// The cancellation token.
        /// </param>
        /// <returns>
        /// Returns a new auto-update proxy for <see cref="IRequestExecutor"/>.
        /// </returns>
        public static async ValueTask <AutoUpdateRequestExecutorProxy> CreateAsync(
            RequestExecutorProxy requestExecutorProxy,
            CancellationToken cancellationToken = default)
        {
            if (requestExecutorProxy == null)
            {
                throw new ArgumentNullException(nameof(requestExecutorProxy));
            }

            IRequestExecutor executor = await requestExecutorProxy
                                        .GetRequestExecutorAsync(cancellationToken)
                                        .ConfigureAwait(false);

            return(new AutoUpdateRequestExecutorProxy(requestExecutorProxy, executor));
        }