Skip to content

Commit

Permalink
Added HeadDocumentHeader parameter to the missed out DELETE api call.
Browse files Browse the repository at this point in the history
  • Loading branch information
DiscJockeyDJ committed Jun 8, 2021
1 parent 2480fa9 commit ba4ef23
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public async Task DeleteDocument_ShouldUseQueryParameters_WhenProvided()

string requestUri = null;

mockTransport.Setup(x => x.DeleteAsync(It.IsAny<string>()))
.Returns((string uri) =>
mockTransport.Setup(x => x.DeleteAsync(It.IsAny<string>(), It.IsAny<WebHeaderCollection>()))
.Returns((string uri, WebHeaderCollection webHeaderCollection) =>
{
requestUri = uri;
return Task.FromResult(mockResponse.Object);
Expand Down
19 changes: 14 additions & 5 deletions arangodb-net-standard/DocumentApi/DocumentApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,13 @@ public virtual async Task<List<T>> GetDocumentsAsync<T>(
/// <param name="collectionName"></param>
/// <param name="documentKey"></param>
/// <param name="query"></param>
/// <param name="headers">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
public virtual async Task<DeleteDocumentResponse<object>> DeleteDocumentAsync(
string collectionName,
string documentKey,
DeleteDocumentQuery query = null)
DeleteDocumentQuery query = null,
HeadDocumentHeader headers = null)
{
return await DeleteDocumentAsync<object>(
$"{WebUtility.UrlEncode(collectionName)}/{WebUtility.UrlEncode(documentKey)}",
Expand All @@ -364,10 +366,12 @@ public virtual async Task<DeleteDocumentResponse<object>> DeleteDocumentAsync(
/// </remarks>
/// <param name="documentId"></param>
/// <param name="query"></param>
/// <param name="headers">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
public virtual async Task<DeleteDocumentResponse<object>> DeleteDocumentAsync(
string documentId,
DeleteDocumentQuery query = null)
DeleteDocumentQuery query = null,
HeadDocumentHeader headers = null)
{
return await DeleteDocumentAsync<object>(documentId, query);
}
Expand All @@ -379,11 +383,13 @@ public virtual async Task<DeleteDocumentResponse<object>> DeleteDocumentAsync(
/// <param name="collectionName"></param>
/// <param name="documentKey"></param>
/// <param name="query"></param>
/// <param name="headers">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
public virtual async Task<DeleteDocumentResponse<T>> DeleteDocumentAsync<T>(
string collectionName,
string documentKey,
DeleteDocumentQuery query = null)
DeleteDocumentQuery query = null,
HeadDocumentHeader headers = null)
{
return await DeleteDocumentAsync<T>(
$"{WebUtility.UrlEncode(collectionName)}/{WebUtility.UrlEncode(documentKey)}",
Expand All @@ -395,10 +401,12 @@ public virtual async Task<DeleteDocumentResponse<T>> DeleteDocumentAsync<T>(
/// </summary>
/// <param name="documentId"></param>
/// <param name="query"></param>
/// <param name="headers">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
public virtual async Task<DeleteDocumentResponse<T>> DeleteDocumentAsync<T>(
string documentId,
DeleteDocumentQuery query = null)
DeleteDocumentQuery query = null,
HeadDocumentHeader headers = null)
{
ValidateDocumentId(documentId);
string uri = _docApiPath + "/" + documentId;
Expand All @@ -407,7 +415,8 @@ public virtual async Task<DeleteDocumentResponse<T>> DeleteDocumentAsync<T>(
uri += "?" + query.ToQueryString();
}

using (var response = await _client.DeleteAsync(uri))
var headerCollection = GetHeaderCollection(headers);
using (var response = await _client.DeleteAsync(uri, headerCollection))
{
if (response.IsSuccessStatusCode)
{
Expand Down
16 changes: 12 additions & 4 deletions arangodb-net-standard/DocumentApi/IDocumentApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ Task<List<T>> GetDocumentsAsync<T>(
/// <param name="collectionName"></param>
/// <param name="documentKey"></param>
/// <param name="query"></param>
/// <param name="headers">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
Task<DeleteDocumentResponse<object>> DeleteDocumentAsync(
string collectionName,
string documentKey,
DeleteDocumentQuery query = null);
DeleteDocumentQuery query = null,
HeadDocumentHeader headers = null);

/// <summary>
/// Delete a document based on its document ID.
Expand All @@ -184,10 +186,12 @@ Task<DeleteDocumentResponse<object>> DeleteDocumentAsync(
/// </remarks>
/// <param name="documentId"></param>
/// <param name="query"></param>
/// <param name="headers">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
Task<DeleteDocumentResponse<object>> DeleteDocumentAsync(
string documentId,
DeleteDocumentQuery query = null);
DeleteDocumentQuery query = null,
HeadDocumentHeader headers = null);

/// <summary>
/// Delete a document.
Expand All @@ -196,21 +200,25 @@ Task<DeleteDocumentResponse<object>> DeleteDocumentAsync(
/// <param name="collectionName"></param>
/// <param name="documentKey"></param>
/// <param name="query"></param>
/// <param name="headers">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
Task<DeleteDocumentResponse<T>> DeleteDocumentAsync<T>(
string collectionName,
string documentKey,
DeleteDocumentQuery query = null);
DeleteDocumentQuery query = null,
HeadDocumentHeader headers = null);

/// <summary>
/// Delete a document based on its document ID.
/// </summary>
/// <param name="documentId"></param>
/// <param name="query"></param>
/// <param name="headers">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
Task<DeleteDocumentResponse<T>> DeleteDocumentAsync<T>(
string documentId,
DeleteDocumentQuery query = null);
DeleteDocumentQuery query = null,
HeadDocumentHeader headers = null);

/// <summary>
/// Delete multiple documents based on the passed document selectors.
Expand Down
8 changes: 6 additions & 2 deletions arangodb-net-standard/Transport/Http/HttpApiTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ public void SetJwtToken(string jwt)
/// Sends a DELETE request using <see cref="HttpClient"/>.
/// </summary>
/// <param name="requestUri"></param>
/// <param name="webHeaderCollection">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
public async Task<IApiClientResponse> DeleteAsync(string requestUri)
public async Task<IApiClientResponse> DeleteAsync(
string requestUri, WebHeaderCollection webHeaderCollection = null)
{
var response = await _client.DeleteAsync(requestUri);
var request = new HttpRequestMessage(HttpMethod.Delete, requestUri);
ApplyHeaders(webHeaderCollection, request.Headers);
var response = await _client.SendAsync(request);
return new HttpApiClientResponse(response);
}

Expand Down
3 changes: 2 additions & 1 deletion arangodb-net-standard/Transport/IApiClientTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ Task<IApiClientResponse> PostAsync(
/// Send a DELETE request.
/// </summary>
/// <param name="requestUri"></param>
/// <param name="webHeaderCollection">Object containing a dictionary of Header keys and values.</param>
/// <returns></returns>
Task<IApiClientResponse> DeleteAsync(string requestUri);
Task<IApiClientResponse> DeleteAsync(string requestUri, WebHeaderCollection webHeaderCollection = null);

/// <summary>
/// Send a DELETE request with body content.
Expand Down

0 comments on commit ba4ef23

Please sign in to comment.