private async Task IsPwnedTest(HttpClient httpClient, string password, Predicate <int> outcomePredicate) { #if !NETCOREAPP2_0 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; #endif using (var client = new PwnedPasswordClient(httpClient)) { var result = await client.IsPwnedAsync(password); Assert.True(outcomePredicate(result)); } }
public void PwnedPasswordClient_GetPasswordResults_ParsesToPwnedPasswords() { // Test Setup var mockClient = new Mock <IHttpHandler>(); mockClient.Setup(m => m.GetAsync(It.Is <string>(s => string.Equals(s, "range/21BD1", StringComparison.OrdinalIgnoreCase)))) .ReturnsAsync(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(KnownPwnedPasswords.GetPwnedPasswordsInApiFormat()) }); PwnedPasswordClient._httpHandler = mockClient.Object; var results = new PwnedPasswordClient().GetPasswordResults("21BD1"); Assert.Equal(KnownPwnedPasswords.PwnedPasswords.Values, results); }