Exemple #1
0
    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));
    }
Exemple #2
0
    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));
    }
Exemple #3
0
    public async Task GetBreachesAsync_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.GetBreachesAsync("DUMMY", CancellationToken.None));
    }
Exemple #4
0
    public async Task GetBreachesAsync_CancellationToken_WithNullValueForAccount_Throws()
    {
        using var httpClient = new HttpClient(new MockHttpMessageHandler());

        var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient);

        await Assert.ThrowsAsync <ArgumentNullException>(() => c.GetBreachesAsync(null, CancellationToken.None));
    }
Exemple #5
0
    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);
    }
Exemple #6
0
    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);
    }
Exemple #7
0
    public async Task GetBreachesAsync_CancellationToken_AfterDispose_Throws()
    {
        using var httpClient = new HttpClient(new MockHttpMessageHandler());

        var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient);

        c.Dispose();

        await Assert.ThrowsAsync <ObjectDisposedException>(() => c.GetBreachesAsync("DUMMY", CancellationToken.None));
    }
Exemple #8
0
    public async Task GetBreachesAsync_BreachModeCancellationToken_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, CancellationToken.None);

        Assert.NotNull(result);
        Assert.NotEmpty(result);
    }
Exemple #9
0
    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);
    }
Exemple #10
0
    public async Task GetBreachesAsync_WithoutApiKey_Throws()
    {
        using var httpClient = new HttpClient(new MockErroringHttpMessageHandler(desiredResultStatusCode: 401));

        var settings = this.ClientSettings;

        settings.ApiKey = string.Empty;

        using var c = new HaveIBeenPwnedClient(this.ClientSettings, httpClient);

        await Assert.ThrowsAsync <InvalidApiKeyException>(() => c.GetBreachesAsync("DUMMY"));
    }