Ejemplo n.º 1
0
        /// <summary>
        /// Delete a document based on its document ID.
        /// </summary>
        /// <param name="documentId"></param>
        /// <param name="query"></param>
        /// <param name="headers">The <see cref="DocumentHeaderProperties"/> values.</param>
        /// <returns></returns>
        public virtual async Task <DeleteDocumentResponse <T> > DeleteDocumentAsync <T>(
            string documentId,
            DeleteDocumentQuery query        = null,
            DocumentHeaderProperties headers = null)
        {
            ValidateDocumentId(documentId);
            string uri = _docApiPath + "/" + documentId;

            if (query != null)
            {
                uri += "?" + query.ToQueryString();
            }

            var headerCollection = GetHeaderCollection(headers);

            using (var response = await _client.DeleteAsync(uri, headerCollection).ConfigureAwait(false))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

                    var responseModel = DeserializeJsonFromStream <DeleteDocumentResponse <T> >(stream);
                    return(responseModel);
                }

                throw await GetApiErrorException(response).ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Delete a document based on its document ID.
 /// </summary>
 /// <remarks>
 /// This method overload is provided as a convenience when the client does not care about the type of <see cref="DeleteDocumentResponse{T}.Old"/>
 /// in the returned <see cref="DeleteDocumentResponse{T}"/>. Its value will be <c>null</c> when
 /// <see cref="DeleteDocumentQuery.ReturnOld"/> is either <c>false</c> or not set, so this overload is useful in the default case
 /// when deleting documents.
 /// </remarks>
 /// <param name="documentId"></param>
 /// <param name="query"></param>
 /// <param name="headers">The <see cref="DocumentHeaderProperties"/> values.</param>
 /// <returns></returns>
 public virtual async Task <DeleteDocumentResponse <object> > DeleteDocumentAsync(
     string documentId,
     DeleteDocumentQuery query        = null,
     DocumentHeaderProperties headers = null)
 {
     return(await DeleteDocumentAsync <object>(documentId, query, headers).ConfigureAwait(false));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Delete a document.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="collectionName"></param>
 /// <param name="documentKey"></param>
 /// <param name="query"></param>
 /// <returns></returns>
 public virtual async Task <DeleteDocumentResponse <T> > DeleteDocumentAsync <T>(
     string collectionName,
     string documentKey,
     DeleteDocumentQuery query = null)
 {
     return(await DeleteDocumentAsync <T>(
                $"{WebUtility.UrlEncode(collectionName)}/{WebUtility.UrlEncode(documentKey)}",
                query));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Delete a document.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="collectionName"></param>
 /// <param name="documentKey"></param>
 /// <param name="query"></param>
 /// <param name="headers">The <see cref="DocumentHeaderProperties"/> values.</param>
 /// <returns></returns>
 public virtual async Task <DeleteDocumentResponse <T> > DeleteDocumentAsync <T>(
     string collectionName,
     string documentKey,
     DeleteDocumentQuery query        = null,
     DocumentHeaderProperties headers = null)
 {
     return(await DeleteDocumentAsync <T>(
                $"{WebUtility.UrlEncode(collectionName)}/{WebUtility.UrlEncode(documentKey)}",
                query, headers).ConfigureAwait(false));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Delete a document based on its document ID.
 /// </summary>
 /// <remarks>
 /// This method overload is provided as a convenience when the client does not care about the type of <see cref="DeleteDocumentResponse{T}.Old"/>
 /// in the returned <see cref="DeleteDocumentResponse{T}"/>. Its value will be <c>null</c> when
 /// <see cref="DeleteDocumentQuery.ReturnOld"/> is either <c>false</c> or not set, so this overload is useful in the default case
 /// when deleting documents.
 /// </remarks>
 /// <param name="documentId"></param>
 /// <param name="query"></param>
 /// <returns></returns>
 public virtual async Task <DeleteDocumentResponse <object> > DeleteDocumentAsync(
     string documentId,
     DeleteDocumentQuery query = null)
 {
     return(await DeleteDocumentAsync <object>(documentId, query));
 }
Ejemplo n.º 6
0
 public async Task WhenNoDocumentIsSpecifiedAsync()
 {
     var query = new DeleteDocumentQuery <Person>(null);
     var ex    = await Assert.ThrowsAsync <ElasticClientQueryObjectException>(() => Fixture.Client.QueryAsync(query));
 }
Ejemplo n.º 7
0
 public void WhenNoDocumentIsSpecified()
 {
     var query = new DeleteDocumentQuery <Person>(null);
     var ex    = Assert.Throws <ElasticClientQueryObjectException>(() => Fixture.Client.Query(query));
 }