コード例 #1
0
        public async Task <ScoundrelInfo[]> FindScoundrels(FindScoundrelModel findScoundrelModel)
        {
            var firstName = findScoundrelModel.FirstName;
            var lastName  = findScoundrelModel.LastName;
            var gender    = findScoundrelModel.Gender;
            var dob       = findScoundrelModel.DateOfBirth;
            var postCode  = findScoundrelModel.Postcode;

            var request =
                WebRequest.CreateHttp(
                    $"{PEOPLE_URL}?FirstName={firstName}&LastName={lastName}&gender={gender}&DateOfBirth={dob}&PostCode={postCode}");

            request.Method = "GET";
            request.Headers.Add(HttpRequestHeader.Authorization, CREDENTIALS);
            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    if (responseStream == null)
                    {
                        return(await Task.FromResult(Array.Empty <ScoundrelInfo>()));
                    }
                    using (var textReader = new StreamReader(responseStream))
                    {
                        var responseBody = await textReader.ReadToEndAsync();

                        var scoundrels = JsonConvert.DeserializeObject <ScoundrelInfo[]>(responseBody);
                        return(scoundrels);
                    }
                }
            }
        }
コード例 #2
0
        public async Task SearchScoundrels()
        {
            var lastName      = "Powell";
            var findScoundrel = new FindScoundrelModel {
                LastName = lastName
            };
            var scoundrels = await CLIENT.FindScoundrels(findScoundrel);

            Assert.Collection(scoundrels, s => Assert.Equal(lastName, s.LastName));
        }