static void Main(string[] args)
        {
            int distance = GetDistanceFromUserInput();

            Console.WriteLine("Fetching data, please wait...");

            var url = ConfigurationManager.AppSettings.Get("StarWarsApiUrl");

            using (var apiClient = new ApiClient(url))
            {
                //var apiClient = new ApiClient(url);
                var deserializer = new ApiResponseDeserializer();
                var mapper       = new StarShipMap();

                var service = new StarShipService(apiClient, deserializer, mapper);

                var result = Task.Run(() => service.GetNumberOfStopsForStarShips(distance)).Result;

                foreach (var item in result.OrderBy(x => x.ShipName))
                {
                    //Console.WriteLine("Ship name: {0} Number of stops: {1}", item.ShipName, item.NumberOfStopsRequired);
                    Console.WriteLine("{0}: {1}", item.ShipName, item.NumberOfStopsRequired);
                }

                Console.ReadKey();
            }
        }
        public async Task ItShouldReturnADeserializedApiResponse()
        {
            var response = await this.ApiClient.GetStarShipList();

            var deserializer = new ApiResponseDeserializer();

            var deserializedResponse = await deserializer.DeserializeResponse(response);

            Assert.IsNotNull(deserializedResponse.NextPageNumber);
            Assert.IsFalse(string.IsNullOrWhiteSpace(deserializedResponse.StarShipCount));

            Assert.IsFalse(deserializedResponse.StarShips.Any(x => string.IsNullOrWhiteSpace(x.ShipName)));
            Assert.IsFalse(deserializedResponse.StarShips.Any(x => string.IsNullOrWhiteSpace(x.MegalightsPerHour)));
            Assert.IsFalse(deserializedResponse.StarShips.Any(x => string.IsNullOrWhiteSpace(x.Consumables)));
        }
        public async Task ItShouldReturnADeserializedApiResponseIfThePageRequestedWasTheLastPage()
        {
            //Page 4 is currently the last page for the StarShips API
            var response = await this.ApiClient.GetStartShipListByPage(4);

            var deserializer = new ApiResponseDeserializer();

            var deserializedResponse = await deserializer.DeserializeResponse(response);

            Assert.IsNull(deserializedResponse.NextPageNumber);
            Assert.IsFalse(string.IsNullOrWhiteSpace(deserializedResponse.StarShipCount));

            Assert.IsFalse(deserializedResponse.StarShips.Any(x => string.IsNullOrWhiteSpace(x.ShipName)));
            Assert.IsFalse(deserializedResponse.StarShips.Any(x => string.IsNullOrWhiteSpace(x.MegalightsPerHour)));
            Assert.IsFalse(deserializedResponse.StarShips.Any(x => string.IsNullOrWhiteSpace(x.Consumables)));
        }
Exemple #4
0
 public WhenRequestingNumberOfStopsForAllStarShips()
 {
     this.deserializer = new ApiResponseDeserializer();
     this.mapper       = new StarShipMap();
     this.service      = new StarShipService(this.ApiClient, deserializer, mapper);
 }
 public StarShipService(ApiClient apiClient, ApiResponseDeserializer apiResponseDeserializer, StarShipMap mapper)
 {
     this.apiClient            = apiClient;
     this.responseDeserializer = apiResponseDeserializer;
     this.mapper = mapper;
 }