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); } } } }
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)); }