예제 #1
0
        public async Task Execute_StarWarsGetHero_Test()
        {
            // arrange
            CancellationToken ct = new CancellationTokenSource(20_000).Token;

            using IWebHost host = TestServerHelper.CreateServer(
                      _ => { },
                      out var port);
            var serviceCollection = new ServiceCollection();

            serviceCollection
            .AddStarWarsGetHeroClient()
            .ConfigureHttpClient(
                c => c.BaseAddress = new Uri("http://localhost:" + port + "/graphql"))
            .ConfigureWebSocketClient(
                c => c.Uri = new Uri("ws://localhost:" + port + "/graphql"));

            IServiceProvider      services = serviceCollection.BuildServiceProvider();
            StarWarsGetHeroClient client   = services.GetRequiredService <StarWarsGetHeroClient>();

            // act
            IOperationResult <IGetHeroResult> result = await client.GetHero.ExecuteAsync(ct);

            // assert
            Assert.Equal("R2-D2", result.Data !.Hero !.Name);
        }
예제 #2
0
        public async Task Watch_CacheFirst_StarWarsGetHero_Test()
        {
            // arrange
            CancellationToken ct = new CancellationTokenSource(20_000).Token;

            using IWebHost host = TestServerHelper.CreateServer(
                      _ => { },
                      out var port);
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddStarWarsGetHeroClient()
            .ConfigureHttpClient(
                c => c.BaseAddress = new Uri("http://localhost:" + port + "/graphql"))
            .ConfigureWebSocketClient(
                c => c.Uri = new Uri("ws://localhost:" + port + "/graphql"));

            IServiceProvider      services = serviceCollection.BuildServiceProvider();
            StarWarsGetHeroClient client   = services.GetRequiredService <StarWarsGetHeroClient>();

            // act
            await client.GetHero.ExecuteAsync(ct);

            string?     name    = null;
            IDisposable session =
                client.GetHero
                .Watch(ExecutionStrategy.CacheFirst)
                .Subscribe(result =>
            {
                name = result.Data?.Hero?.Name;
            });

            while (name is null && !ct.IsCancellationRequested)
            {
                await Task.Delay(10, ct);
            }

            session.Dispose();

            // assert
            Assert.Equal("R2-D2", name);
        }
예제 #3
0
        public async Task Update_Once()
        {
            // arrange
            CancellationToken ct = new CancellationTokenSource(20_000).Token;

            using IWebHost host = TestServerHelper.CreateServer(
                      _ => { },
                      out var port);
            var serviceCollection = new ServiceCollection();

            serviceCollection
            .AddStarWarsGetHeroClient()
            .ConfigureHttpClient(
                c => c.BaseAddress = new Uri("http://localhost:" + port + "/graphql"))
            .ConfigureWebSocketClient(
                c => c.Uri = new Uri("ws://localhost:" + port + "/graphql"));

            IServiceProvider      services = serviceCollection.BuildServiceProvider();
            StarWarsGetHeroClient client   = services.GetRequiredService <StarWarsGetHeroClient>();

            await client.GetHero.ExecuteAsync(ct);

            // act
            var count = 0;

            using IDisposable session =
                      client.GetHero
                      .Watch(ExecutionStrategy.CacheAndNetwork)
                      .Subscribe(_ =>
            {
                count++;
            });

            await Task.Delay(1000, ct);

            // assert
            Assert.Equal(1, count);
        }