public async Task Test_Insert_First_Update_Delete() { var creating = DocumentClientTest.NewDocument(); var created = await _documentClient.InsertAsync(creating, CancellationToken.None); DocumentClientTest.Test(creating, created); var received = await _documentClient.FirstOrDefaultAsync <TestDocument>( created.Id, created.PartitionId, CancellationToken.None); DocumentClientTest.Test(created, received); DocumentClientTest.Update(created); var updated = await _documentClient.UpdateAsync(created, CancellationToken.None); DocumentClientTest.Test(created, updated); await _documentClient.DeleteAsync(updated.Id, updated.PartitionId, CancellationToken.None); var deleted = await _documentClient.FirstOrDefaultAsync <TestDocument>( updated.Id, updated.PartitionId, CancellationToken.None); Assert.IsNull(deleted); }
/// <summary>Receives a document from its persistence.</summary> /// <typeparam name="TDocument">A type of a document.</typeparam> /// <param name="documentClient">An object that provides a simple API to persistence of documents that inherits the <see cref="AzureFunctionsCustomBindingSample.CosmosDb.DocumentBase"/> class.</param> /// <param name="query">An object that represents conditions to query a document.</param> /// <param name="cancellationToken">A value that propagates notification that operations should be canceled.</param> /// <returns>An object that represents an async operation.</returns> public static Task <TDocument> FirstOrDefaultAsync <TDocument>( this IDocumentClient documentClient, IDocumentQuery query, CancellationToken cancellationToken) where TDocument : DocumentBase { if (documentClient == null) { throw new ArgumentNullException(nameof(documentClient)); } if (query == null) { throw new ArgumentNullException(nameof(query)); } return(documentClient.FirstOrDefaultAsync <TDocument>( query.Id, query.PartitionId, cancellationToken)); }