public async Task TryReadByIdPartitionedAsync_SuccessCall_CallsContainerReadItemAsync() { CosmosDbTestIdentifiable item = new CosmosDbTestIdentifiable { Id = _id }; Mock <ItemResponse <CosmosDbTestIdentifiable> > itemResponse = new Mock <ItemResponse <CosmosDbTestIdentifiable> >(); itemResponse.Setup(_ => _.Resource).Returns(item); _container .Setup(_ => _.ReadItemAsync <CosmosDbTestIdentifiable>( _id, It.Is <PartitionKey>(p => p == new PartitionKey(_partitionKey)), It.IsAny <ItemRequestOptions>(), It.IsAny <CancellationToken>())) .ReturnsAsync(itemResponse.Object); CosmosDbTestIdentifiable response = await _cosmosRepository.TryReadByIdPartitionedAsync <CosmosDbTestIdentifiable>(_id, _partitionKey); response.Should().NotBeNull(); response.Id.Should().Be(_id); }
public async Task TryReadByIdPartitionedAsync_ThrowsCosmosException_ReturnsDefaultValue() { CosmosException cosmosException = new CosmosException( NewRandomString(), HttpStatusCode.NotFound, NewRandomInteger(), NewRandomString(), NewRandomInteger()); _container .Setup(_ => _.ReadItemAsync <CosmosDbTestIdentifiable>( _id, It.Is <PartitionKey>(p => p == new PartitionKey(_partitionKey)), It.IsAny <ItemRequestOptions>(), It.IsAny <CancellationToken>())) .Throws(cosmosException); CosmosDbTestIdentifiable response = await _cosmosRepository.TryReadByIdPartitionedAsync <CosmosDbTestIdentifiable>(_id, _partitionKey); response.Should().BeNull(); }