示例#1
0
        public static HttpResponseMessage AllPage1()
        {
            var starshipResultSWAPI = new StarshipResultSWAPI()
            {
                Count   = 3,
                Next    = "page2",
                Results = new List <StarshipSWAPI>()
                {
                    new StarshipSWAPI()
                    {
                        Name        = "Millennium Falcon",
                        Consumables = "2 months",
                        MGLT        = "75"
                    },
                    new StarshipSWAPI()
                    {
                        Name        = "Y-wing",
                        Consumables = "1 week",
                        MGLT        = "80"
                    }
                }
            };

            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new StringContent(
                    JsonConvert.SerializeObject(starshipResultSWAPI), System.Text.Encoding.UTF8, "application/json")
            });
        }
示例#2
0
        public async Task <IEnumerable <Starship> > GetAllStarshipsAsync()
        {
            StarshipResultSWAPI starshipSWAPI = null;

            var urlSWAPI = _settings.GetAppSetting("UrlSWAPIConfiguration");

            do
            {
                await _retryPolicy.ExecuteAsync(async() =>
                {
                    var response = _httpClient.Get(urlSWAPI);

                    if (response.IsSuccessStatusCode)
                    {
                        var outputDataJson = response.Content.ReadAsStringAsync().Result;

                        starshipSWAPI = JsonConvert.DeserializeObject <StarshipResultSWAPI>(outputDataJson);
                        MapToDomain(starshipSWAPI.Results);
                        urlSWAPI = starshipSWAPI.Next;
                    }
                });
            } while (starshipSWAPI != null && !string.IsNullOrEmpty(starshipSWAPI.Next));

            return(_starships);
        }
示例#3
0
        public static HttpResponseMessage AllPage2()
        {
            var starshipResultSWAPI = new StarshipResultSWAPI()
            {
                Count   = 1,
                Next    = null,
                Results = new List <StarshipSWAPI>()
                {
                    new StarshipSWAPI()
                    {
                        Name        = "X-wing",
                        Consumables = "1 week",
                        MGLT        = "100"
                    }
                }
            };

            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK)
            {
                Content = new StringContent(
                    JsonConvert.SerializeObject(starshipResultSWAPI), System.Text.Encoding.UTF8, "application/json")
            });
        }