public async Task GetNotExistentDocumentByIdAndPartitionKey() { const string documentId = "-1"; const string partitionKey = "Carrero"; var cosmosDocumentResponse = await _queryCosmosDbRepository.GetByIdAsync(documentId, partitionKey).ConfigureAwait(false); Assert.IsTrue(cosmosDocumentResponse.HttpStatusCode == HttpStatusCode.NotFound); Assert.IsTrue(cosmosDocumentResponse.RequestCharge == 0); Assert.IsTrue(!cosmosDocumentResponse.Entities.Any()); }
private async Task <bool> DocumentExistsAsync(TDocument document) { var cosmosDbQueryRepository = new QueryCosmosDbRepository <TEntity, TDocument>(CosmosDbConfiguration, _mapper); var cosmosDocumentResponse = await cosmosDbQueryRepository.GetByIdAsync(document.DocumentId, document.PartitionKey).ConfigureAwait(false); var entity = cosmosDocumentResponse.Entities.FirstOrDefault(); return(!EqualityComparer <TEntity> .Default.Equals(entity, default)); }
public async Task GetDocumentByIdWhenDocumentAndEntityAreOfTheSameType() { const string documentId = "1"; const string partitionKey = "Carrero"; var cosmosDocumentResponse = await _querySameEntityAndDocumentCosmosDbRepository.GetByIdAsync(documentId, partitionKey).ConfigureAwait(false); Assert.IsTrue(cosmosDocumentResponse.HttpStatusCode == HttpStatusCode.OK); Assert.IsTrue(cosmosDocumentResponse.RequestCharge > 0); Assert.IsTrue(cosmosDocumentResponse.Entities.FirstOrDefault() != null); Assert.IsTrue(cosmosDocumentResponse.Entities.FirstOrDefault()?.FamilyName == "Carrero"); Assert.IsTrue(cosmosDocumentResponse.Entities.FirstOrDefault()?.FirstName == "Carlos"); Assert.IsTrue(cosmosDocumentResponse.Entities.FirstOrDefault()?.MiddleName == "Andres"); }