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 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 Task <IEnumerable <Breach> > GetBreachesAsync(string account, BreachMode modes, CancellationToken cancellationToken) { return(Task.FromResult(breaches)); }
public Task <IEnumerable <Breach> > GetBreachesAsync(string account, BreachMode modes) { return(Task.FromResult(breaches)); }
public async Task GetBreachesAsync_BreachMode(BreachMode breachMode) { var result = await this._client.GetBreachesAsync("benchmark", breachMode); }
public Uri GetBreachesForAccountUri(BreachMode breachMode) { return(UriFactory.GetBreachesForAccountUri(Account, breachMode)); }
/// <summary> /// Get the breaches for an account /// </summary> /// <param name="account"> /// The account to get the breaches for /// </param> /// <param name="modes"> /// The <see cref="BreachMode"/> flags to specify extra breaches to get /// </param> /// <param name="cancellationToken"> /// The <see cref="CancellationToken"/> for this operation /// </param> /// <returns> /// An awaitable <see cref="Task{TResult}"/> with the collection of every /// <see cref="Breach"/> the account was found in /// </returns> private async Task <IEnumerable <Breach> > GetBreachesInternalAsync(string account, BreachMode modes, CancellationToken cancellationToken) { Throw.ArgumentNull.WhenNullOrWhiteSpace(account, nameof(account)); this.ThrowIfDisposed(); var uri = UriFactory.GetBreachesForAccountUri(account, modes); var results = await this.GetAuthenticatedAsync <IEnumerable <Breach> >(uri, cancellationToken) .ConfigureAwait(false); return(results); }
/// <inheritdoc /> public async Task <IEnumerable <Breach> > GetBreachesAsync(string account, BreachMode modes, CancellationToken cancellationToken) => await this.GetBreachesInternalAsync(account, modes, cancellationToken) .ConfigureAwait(false);
public void GetBreachesForAccountUri_WithBreachModeOtherThanDefault_ReturnsCorrectUri(BreachMode breachMode, string expectedQueryStringPart) { const string account = "TESTACCOUNT"; var result = UriFactory.GetBreachesForAccountUri(account, breachMode); Assert.Contains(expectedQueryStringPart, result.Query); }