public async Task Execute_StarWarsIntrospection_Test()
        {
            // arrange
            CancellationToken ct = new CancellationTokenSource(20_000).Token;

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

            serviceCollection.AddHttpClient(
                StarWarsIntrospectionClient.ClientName,
                c => c.BaseAddress = new Uri("http://localhost:" + port + "/graphql"));
            serviceCollection.AddWebSocketClient(
                StarWarsIntrospectionClient.ClientName,
                c => c.Uri = new Uri("ws://localhost:" + port + "/graphql"));
            serviceCollection.AddStarWarsIntrospectionClient();
            IServiceProvider            services = serviceCollection.BuildServiceProvider();
            StarWarsIntrospectionClient client   = services.GetRequiredService <StarWarsIntrospectionClient>();

            // act
            IOperationResult <IIntrospectionQueryResult> result =
                await client.IntrospectionQuery.ExecuteAsync(ct);


            // assert
            result.MatchSnapshot();
        }
Ejemplo n.º 2
0
        public async Task GetHero_By_Episode()
        {
            // arrange
            TestServer httpServer = ServerFactory.Create(
                services => services.AddStarWars(),
                app => app.UseGraphQL());

            HttpClient httpClient = httpServer.CreateClient();

            httpClient.BaseAddress = new Uri("http://localhost:5000");

            var clientFactory = new Mock <IHttpClientFactory>();

            clientFactory.Setup(t => t.CreateClient(It.IsAny <string>())).Returns(httpClient);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IHttpClientFactory>(clientFactory.Object);
            serviceCollection.AddDefaultScalarSerializers();
            serviceCollection.AddStarWarsClient();

            var services = serviceCollection.BuildServiceProvider();

            // act
            IStarWarsClient             client = services.GetRequiredService <IStarWarsClient>();
            IOperationResult <IGetHero> result = await client.GetHeroAsync(Episode.Empire);

            // assert
            result.MatchSnapshot();
        }
Ejemplo n.º 3
0
        public async Task GetHero_By_Episode()
        {
            // arrange
            IStarWarsClient client = Services.GetRequiredService <IStarWarsClient>();

            // act
            IOperationResult <IGetHero> result = await client.GetHeroAsync(Episode.Empire);

            // assert
            result.MatchSnapshot();
        }
Ejemplo n.º 4
0
        public async Task GetHero_By_Episode()
        {
            // arrange
            using IWebHost host = TestServerHelper.CreateServer(out int port);
            IServiceProvider services = CreateServices(
                "StarWarsClient", port,
                s => s.AddStarWarsClient());
            IStarWarsClient client = services.GetRequiredService <IStarWarsClient>();

            // act
            IOperationResult <IGetHero> result = await client.GetHeroAsync(Episode.Empire);

            // assert
            result.MatchSnapshot();
        }
Ejemplo n.º 5
0
        public async Task Execute_EntityIdOrData_Test()
        {
            // arrange
            CancellationToken ct  = new CancellationTokenSource(20_000).Token;
            var serviceCollection = new ServiceCollection();

            serviceCollection
            .AddGraphQLServer()
            .AddQueryType <Query>()
            .AddType <IBar>()
            .AddType <Baz>()
            .AddType <Baz2>()
            .AddType <Quox>()
            .AddType <Quox2>();
            serviceCollection.AddEntityIdOrDataClient().ConfigureInMemoryClient();
            IServiceProvider     services = serviceCollection.BuildServiceProvider();
            EntityIdOrDataClient client   = services.GetRequiredService <EntityIdOrDataClient>();

            // act
            IOperationResult <IGetFooResult> result = await client.GetFoo.ExecuteAsync(ct);

            // assert
            result.MatchSnapshot();
        }