public async Task GetOptionsForStandardExample()
        {
            string standardCode      = 1.ToString();
            string standardReference = "ST0127";

            await _StandardsApiClient.GetOptionsForStandard(standardCode);

            await _StandardsApiClient.GetOptionsForStandard(standardReference);
        }
Пример #2
0
        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 GetOptionsForStandard_Valid_StandardCode()
        {
            // arrange
            var standard = 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 expectedResponse = standard;

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

            // act
            var actual = await _ApiClient.GetOptionsForStandard("1");

            // assert
            Assert.That(actual, Is.EqualTo(expectedResponse));
        }