public async Task GetOptionsForAllStandards() { // arrange var standard1 = Builder <StandardOptions> .CreateNew().With(so => so.StandardCode = 1) .With(so => so.StandardReference = "ST0127") .With(cd => cd.CourseOption = new List <string> { "English", "French", "German" }).Build(); var standard2 = Builder <StandardOptions> .CreateNew().With(so => so.StandardCode = 6) .With(so => so.StandardReference = "ST0156") .With(cd => cd.CourseOption = new List <string> { "Overhead lines", "Underground cables", "Substation fitting" }).Build(); var expectedResponse = new List <StandardOptions> { standard1, standard2 }; _MockHttp.When(HttpMethod.Get, $"{apiBaseAddress}/api/v1/standards/options") .Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(expectedResponse)); // act var actual = await _ApiClient.GetOptionsForAllStandards(); // assert Assert.That(actual, Has.Count.EqualTo(2)); Assert.That(actual.FirstOrDefault(so => so.StandardCode == 1), Is.Not.Null); }
private async Task GetStandardOptions() { 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); StandardsApiClient standardsApiClient = new StandardsApiClient(httpClient); List <StandardOptions> options = new List <StandardOptions>(); try { BusyIndicator.IsBusy = true; if (string.IsNullOrWhiteSpace(_ViewModel.Standard)) { var response = await standardsApiClient.GetOptionsForAllStandards(); if (response != null) { options.AddRange(response); } } else { var response = await standardsApiClient.GetOptionsForStandard(_ViewModel.Standard); if (response != null) { options.Add(response); } } } finally { BusyIndicator.IsBusy = false; } if (options.Any()) { SaveStandardOptions(options); } else { string sMessageBoxText = "There are no options for the specified standard"; string sCaption = "No Options Found"; MessageBox.Show(sMessageBoxText, sCaption, MessageBoxButton.OK, MessageBoxImage.Warning); } } }
public async Task GetOptionsForAllStandardsExample() { await _StandardsApiClient.GetOptionsForAllStandards(); }