예제 #1
0
        public async Task GetGrades()
        {
            // arrange
            var expectedResponse = new List <string>
            {
                "Pass", "Credit", "Merit", "Distinction", "Pass with excellence", "No grade awarded"
            };

            _MockHttp.When(HttpMethod.Get, $"{apiBaseAddress}/api/v1/certificate/grades")
            .Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(expectedResponse));

            // act
            var actual = await _ApiClient.GetGrades();

            // assert
            Assert.That(actual, Has.Count.EqualTo(6));
            Assert.That(actual, Contains.Item("Distinction"));
        }
        private async Task GetGrades()
        {
            string subscriptionKey = Settings.Default["SubscriptionKey"].ToString();
            string apiBaseAddress  = Settings.Default["ApiBaseAddress"].ToString();

            using (HttpClient httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(apiBaseAddress);
                httpClient.DefaultRequestHeaders.Add("Accept", "application/json");
                httpClient.DefaultRequestHeaders.Add("Cache-Control", "no-cache");
                httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);

                CertificateApiClient certificateApiClient = new CertificateApiClient(httpClient);

                var grades = new List <string>();

                try
                {
                    BusyIndicator.IsBusy = true;
                    var response = await certificateApiClient.GetGrades();

                    if (response != null)
                    {
                        grades.AddRange(response);
                    }
                }
                finally
                {
                    BusyIndicator.IsBusy = false;
                }

                if (grades.Any())
                {
                    SaveGrades(grades);
                }
            }
        }
 public async Task GetGradesExample()
 {
     await _CertificateApiClient.GetGrades();
 }