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();
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            var serviceCollection = Init();

            IServiceProvider services = serviceCollection.BuildServiceProvider();

            _starWarsClient = services.GetRequiredService <IStarWarsClient>();

            FetchHeroes(Episode.NewHope);
            FetchHeroes(Episode.Empire);
        }
Beispiel #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();
        }
Beispiel #4
0
        public async Task CreateReview_By_Episode()
        {
            // arrange
            IStarWarsClient          client             = Services.GetRequiredService <IStarWarsClient>();
            IValueSerializerResolver serializerResolver = Services.GetRequiredService <IValueSerializerResolver>();

            // act
            var result = await client.CreateReviewAsync(Episode.Empire, new ReviewInput()
            {
                Commentary = "You", Stars = 4
            });

            // assert
            result.MatchSnapshot();
        }
Beispiel #5
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();
        }
Beispiel #6
0
        public async Task OnReview_By_Episode()
        {
            // arrange
            using IWebHost host = TestServerHelper.CreateServer(out int port);
            IServiceProvider services = CreateServices(
                "StarWarsClient", port,
                s => s.AddStarWarsClient());
            IStarWarsClient client = services.GetRequiredService <IStarWarsClient>();

            using var cts = new CancellationTokenSource(30000);

            // act
            var stream = await client.OnReviewAsync(Episode.Empire, cts.Token);

            // assert
            await Task.Delay(5000).ConfigureAwait(false);

            await client.CreateReviewAsync(
                Episode.Empire,
                new ReviewInput
            {
                Commentary = "You",
                Stars      = 4
            });

            await client.CreateReviewAsync(
                Episode.Empire,
                new ReviewInput
            {
                Commentary = "Me",
                Stars      = 4
            });

            int count = 0;

            await foreach (IOperationResult <IOnReview> result in stream.WithCancellation(cts.Token))
            {
                result.MatchSnapshot(new SnapshotNameExtension(count));

                count++;
                if (count > 1)
                {
                    break;
                }
            }

            await stream.DisposeAsync();
        }
        static async Task Main(string[] args)
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddHttpClient(
                "StarWarsClient",
                c => c.BaseAddress = new Uri("http://localhost:5000/graphql"));
            serviceCollection.AddStarWarsClient();

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

            IOperationResult <IGetHero> result = await client.GetHeroAsync(Episode.NewHope);

            Console.WriteLine(((ISomeDroid)result.Data.Hero).Name);

            result = await client.GetHeroAsync(Episode.Empire);

            Console.WriteLine(((ISomeHuman)result.Data.Hero).Name);
        }
Beispiel #8
0
        public async Task CreateReview_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
            var result = await client.CreateReviewAsync(
                Episode.Empire,
                new ReviewInput
            {
                Commentary = "You",
                Stars      = 4
            });

            // assert
            result.MatchSnapshot();
        }
Beispiel #9
0
 public SimpleStarWarsController(IStarWarsClient starWarsClient)
 {
     _starWarsClient = starWarsClient;
 }