public async Task GetBreachesAsync_BreachModeCancellationToken_WithImATeapot_Throws() { using var httpClient = new HttpClient(new MockErroringHttpMessageHandler(desiredResultStatusCode: 418)); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <HaveIBeenPwnedClientException>(() => c.GetBreachesAsync("DUMMY", BreachMode.Default, CancellationToken.None)); }
public async Task IsPwnedPasswordAsync_WithNullValueForPassword_Throws() { using var httpClient = new HttpClient(new MockHttpMessageHandler()); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <ArgumentNullException>(() => c.IsPwnedPasswordAsync(null)); }
public async Task GetBreachesAsync_BreachMode_WithInvalidApiKey_Throws(BreachMode breachMode) { using var httpClient = new HttpClient(new MockErroringHttpMessageHandler(desiredResultStatusCode: 401)); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <InvalidApiKeyException>(() => c.GetBreachesAsync("DUMMY", breachMode)); }
public async Task GetAllBreachesAsync_NotFound_ThrowsHaveIBeenPwnedClientException() { using var httpClient = new HttpClient(new MockErroringHttpMessageHandler(desiredResultStatusCode: 404)); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <HaveIBeenPwnedClientException>(() => c.GetAllBreachesAsync()); }
public async Task GetPastesAsync_WithImATeapot_Throws() { using var httpClient = new HttpClient(new MockErroringHttpMessageHandler(desiredResultStatusCode: 418)); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <HaveIBeenPwnedClientException>(() => c.GetPastesAsync("DUMMY")); }
public async Task GetPastesAsync_CancellationToken_WithNullValueForEmailAddress_Throws() { using var httpClient = new HttpClient(new MockHttpMessageHandler()); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <ArgumentNullException>(() => c.GetPastesAsync(null, CancellationToken.None)); }
public async Task GetPastesAsync_CancellationToken_WithInvalidApiKey_Throws() { using var httpClient = new HttpClient(new MockErroringHttpMessageHandler(desiredResultStatusCode: 401)); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <InvalidApiKeyException>(() => c.GetPastesAsync("DUMMY", CancellationToken.None)); }
public async Task GetPastesAsync_CancellationToken_NotFound_ThrowsHaveIBeenPwnedClientException() { using var httpClient = new HttpClient(new MockErroringHttpMessageHandler(desiredResultStatusCode: 404)); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <HaveIBeenPwnedClientException>(() => c.GetPastesAsync("UNKNOWN", CancellationToken.None)); }
public void Ctor_AppendsAplicationJsonMediaTypeToAcceptHeader() { using (var httpClient = new HttpClient()) using (var client = new HaveIBeenPwnedClient(this.ClientSettings, httpClient)) { Assert.Contains("application/json", httpClient.DefaultRequestHeaders.Accept.ToString()); } }
public void Ctor_OverridesUserAgentOfHttpClient() { using (var httpClient = new HttpClient()) using (var client = new HaveIBeenPwnedClient(this.ClientSettings, httpClient)) { Assert.Equal(this.ClientSettings.ApplicationName, httpClient.DefaultRequestHeaders.UserAgent.ToString()); } }
public async Task GetPastesAsync_WithCancellationToken_RateLimitExceeded_ThrowsRateLimitExceededException() { using var cancellationTokenSource = new CancellationTokenSource(); using var httpClient = new HttpClient(new MockErroringHttpMessageHandler(desiredResultStatusCode: 429)); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <RateLimitExceededException>(() => c.GetPastesAsync("DUMMY", CancellationToken.None)); }
public async Task GetBreachesAsync_WithNullValueForAccount_Throws() { using var httpClient = new HttpClient(new MockHttpMessageHandler()); var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); await Assert.ThrowsAsync <ArgumentNullException>(() => c.GetBreachesAsync(null)); }
public async Task GetBreachesAsync_WithValidInputAndExludeUnVerifiedBreaches_DoesNotThrow() { using var httpClient = new HttpClient(); using var c = new HaveIBeenPwnedClient(CreateSettings(), httpClient); var result = await c.GetBreachesAsync("*****@*****.**", BreachMode.ExcludeUnverified); Assert.NotNull(result); }
public async Task GetBreachesAsync_WithValidInput_DoesNotThrow() { using var httpClient = new HttpClient(); using var c = new HaveIBeenPwnedClient(CreateSettings(), httpClient); var result = await c.GetBreachesAsync("*****@*****.**"); Assert.NotNull(result); }
public void Object_ImplementsIHaveIBeenPwnedClient() { using (var httpClient = new HttpClient(new MockHttpMessageHandler())) { var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); Assert.IsAssignableFrom <IHaveIBeenPwnedClient>(c); } }
public async Task IsPwnedPasswordAsync_CancellationToken_KnownInput_Succeeds() { using var httpClient = new HttpClient(new MockHttpMessageHandler()); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); var result = await c.IsPwnedPasswordAsync("P@ssw0rd", CancellationToken.None); Assert.True(result); }
public async Task GetAllBreachesAsync_DoesNotThrow() { using var httpClient = new HttpClient(); using var c = new HaveIBeenPwnedClient(CreateSettings(), httpClient); var result = await c.GetAllBreachesAsync(); Assert.NotNull(result); }
public async Task GetPastesAsync_CancellationToken_AfterDispose_Throws() { using var httpClient = new HttpClient(new MockHttpMessageHandler()); var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); c.Dispose(); await Assert.ThrowsAsync <ObjectDisposedException>(() => c.GetPastesAsync("DUMMY", CancellationToken.None)); }
public async Task GetBreachesAsync_WithValidInputAndCancellationToken_DoesNotThrow() { using var cancellationTokenSource = new CancellationTokenSource(); using var httpClient = new HttpClient(); using var c = new HaveIBeenPwnedClient(CreateSettings(), httpClient); var result = await c.GetBreachesAsync("*****@*****.**", cancellationTokenSource.Token); Assert.NotNull(result); }
public async Task GetAllBreachesAsync_WithValidInput_Succeeds() { using var httpClient = new HttpClient(new MockHttpMessageHandler()); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); var result = await c.GetAllBreachesAsync(); Assert.NotNull(result); Assert.NotEmpty(result); }
public async Task GetPastesAsync_CancellationToken_WithValidInput_Succeeds() { using var httpClient = new HttpClient(new MockHttpMessageHandler()); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); var result = await c.GetPastesAsync("*****@*****.**", CancellationToken.None); Assert.NotNull(result); Assert.NotEmpty(result); }
public async Task GetPastesAsync_WithUnknownEmail_DoesNotThrow() { using var httpClient = new HttpClient(); using var c = new HaveIBeenPwnedClient(CreateSettings(), httpClient); var result = await c.GetPastesAsync("*****@*****.**"); Assert.NotNull(result); Assert.Empty(result); }
public async Task GetAllBreachesAsync_AfterDispose_Throws() { using var httpClient = new HttpClient(new MockHttpMessageHandler()); var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); c.Dispose(); await Assert.ThrowsAsync <ObjectDisposedException>(() => c.GetAllBreachesAsync()); }
public async Task GetPastesAsync_WithValidInput_ReturnsResults() { using var httpClient = new HttpClient(); using var c = new HaveIBeenPwnedClient(CreateSettings(), httpClient); var result = await c.GetPastesAsync("*****@*****.**"); Assert.NotNull(result); Assert.NotEmpty(result); }
public async Task Dispose_WhenCreatedWithHttpClient_DoesNotDisposeInjectedHttpClient() { using (var httpClient = new HttpClient(new MockHttpMessageHandler())) { var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); c.Dispose(); await Assert.ThrowsAsync <InvalidOperationException>(() => httpClient.GetAsync("/")); // Not an ObjectDisposedException } }
public async Task GetBreachesAsync_BreachMode_WithValidInput_Succeeds(BreachMode breachMode) { using var httpClient = new HttpClient(new MockHttpMessageHandler()); using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient); var result = await c.GetBreachesAsync("*****@*****.**", breachMode); Assert.NotNull(result); Assert.NotEmpty(result); }
public async Task GetAllBreachesAsync_WithCancellationToken_DoesNotThrow() { using var cancellationTokenSource = new CancellationTokenSource(); using var httpClient = new HttpClient(); using var c = new HaveIBeenPwnedClient(CreateSettings(), httpClient); var result = await c.GetAllBreachesAsync(cancellationTokenSource.Token); Assert.NotNull(result); }
public async Task IsPasswordPwned_WhenCalledWithPwnedPassword_ReturnsTrue() { // Arrange IHaveIBeenPwnedClient client = new HaveIBeenPwnedClient(); // Act bool isPwnedPassword = await client.IsPasswordPwned("password123"); // Assert Assert.IsTrue(isPwnedPassword); }
public async Task IsPasswordPwned_WhenCalledWithSecurePassword_ReturnsFalse() { // Arrange IHaveIBeenPwnedClient client = new HaveIBeenPwnedClient(); // Act bool isPwnedPassword = await client.IsPasswordPwned("AV3ryLongS3cureP4ssw0rd(H0p3fully)"); // Assert Assert.IsFalse(isPwnedPassword); }
public async Task GetPastesAsync_WithUnknownEmailAndCancellationToken_DoesNotThrow() { using var cancellationTokenSource = new CancellationTokenSource(); using var httpClient = new HttpClient(); using var c = new HaveIBeenPwnedClient(CreateSettings(), httpClient); var result = await c.GetPastesAsync("*****@*****.**", cancellationTokenSource.Token); Assert.NotNull(result); Assert.Empty(result); }