Esempio n. 1
0
        static async Task Main()
        {
            int distance = 0;

            while (true)
            {
                Console.WriteLine("Set distance: ");
                if (int.TryParse(Console.ReadLine(), out distance) && distance > 0)
                {
                    break;
                }

                Console.WriteLine("Distance must be a positive number");
            }

            var swApi = new SWApiService(new ApiService());

            try
            {
                var result = await swApi.GetAllStarshipsParallelly();

                foreach (var starship in result.OrderBy(x => x.Name))
                {
                    Console.WriteLine($"{starship.Name}: {starship.CalculateStops(distance)?.ToString() ?? "unknown"}");
                }
            }
            catch (HttpRequestException)
            {
                Console.WriteLine("There was an error while communicating with SW API");
            }
        }
Esempio n. 2
0
        public async Task TestGetStarshipsParallelly()
        {
            var result = await service.GetAllStarshipsParallelly();

            Assert.NotEmpty(result);
            Assert.Equal(result.Count, StarshipApiServiceMock.Starships.Count);
        }
Esempio n. 3
0
        public async Task TestStarshipParallelGetOrder()
        {
            var slowService = new SWApiService(new StarshipSlowApiServiceMock());
            var starships   = await slowService.GetAllStarships();

            var starships2 = await slowService.GetAllStarshipsParallelly();

            Assert.Equal(starships.Count, starships2.Count);
            for (int i = 0; i < starships.Count; i++)
            {
                Assert.True(StarshipsEqual(starships[i], starships2[i]));
            }
        }
Esempio n. 4
0
        private async Task TestStarshipsCollection(StarshipsResponse response, Action <List <Starship> > test)
        {
            var mock = new Mock <IApiService>();

            mock.Setup(x => x.GetRequestAsync(It.IsNotNull <string>())).Returns(Task.FromResult(JsonConvert.SerializeObject(response)));
            mock.Setup(x => x.GetRequestAsync <StarshipsResponse>(It.IsNotNull <string>())).Returns(Task.FromResult(response));

            var mockService = new SWApiService(mock.Object);
            var starships   = await mockService.GetAllStarships();

            var starships2 = await mockService.GetAllStarshipsParallelly();

            test.Invoke(starships);
            test.Invoke(starships2);
        }
Esempio n. 5
0
        public async Task TestGetStarshipsParallelly()
        {
            var result = await service.GetAllStarshipsParallelly();

            Assert.NotEmpty(result);
        }