public async Task <IEnumerable <CosmosDatabase> > GetDatabases([FromQuery] bool withCollections = false, [FromQuery] bool withOffers = false) { var databases = await _cosmonautClient.QueryDatabasesAsync(); var cosmosDatabases = _mapper.Map <List <CosmosDatabase> >(databases); if (withCollections) { foreach (var database in databases) { var collections = await _cosmonautClient.QueryCollectionsAsync(database.Id); var cosmosCollections = _mapper.Map <IEnumerable <CosmosCollection> >(collections).ToList(); cosmosDatabases.Single(x => x.Id == database.Id).Collections = cosmosCollections; if (withOffers) { foreach (var collection in cosmosCollections) { var offer = await _cosmonautClient.GetOfferV2ForCollectionAsync(database.Id, collection.Id); collection.Offer = new CosmosOffer { Id = offer.Id, Throughput = offer.Content.OfferThroughput }; } } } } return(cosmosDatabases); }
public async Task UpdateOfferAsync_WhenOfferIsUpdated_ThenRUsCorrespondToTheUpdate() { // Arrange var offer = await _cosmonautClient.GetOfferV2ForCollectionAsync(_databaseId, _collectionName); // Act var newOffer = new OfferV2(offer, 600); var updated = await _cosmonautClient.UpdateOfferAsync(newOffer); var queried = await _cosmonautClient.GetOfferV2ForCollectionAsync(_databaseId, _collectionName); // Assert offer.Content.OfferThroughput.Should().Be(400); updated.StatusCode.Should().Be(HttpStatusCode.OK); queried.Content.OfferThroughput.Should().Be(600); updated.Resource.Should().BeEquivalentTo(queried); }
public async Task GetOfferV2ForCollectionAsync_WhenDatabaseIsDbLevelScaleable_ThenCollectionOfferShouldNotExist() { // Arrange await _cosmonautClient.CreateDatabaseAsync(new Database { Id = _scaleableDbId }, new RequestOptions { OfferThroughput = 10000 }); await _cosmonautClient.CreateCollectionAsync(_scaleableDbId, new DocumentCollection { Id = _collectionName, PartitionKey = new PartitionKeyDefinition() { Paths = new Collection <string>(new List <string> { "/id" }) } }); // Act var collectionOffer = await _cosmonautClient.GetOfferV2ForCollectionAsync(_scaleableDbId, _collectionName); // Assert collectionOffer.Should().BeNull(); }
public async Task CollectionCreator_CreatesCollectionWithThroughput_WhenThroughputIsPresent() { var databaseCreator = new CosmosDatabaseCreator(_cosmonautClient); var collectionCreator = new CosmosCollectionCreator(_cosmonautClient); await databaseCreator.EnsureCreatedAsync(_databaseId); await collectionCreator.EnsureCreatedAsync <object>(_databaseId, _collectionName, 10000, new JsonSerializerSettings()); var offer = await _cosmonautClient.GetOfferV2ForCollectionAsync(_databaseId, _collectionName); offer.Content.OfferThroughput.Should().Be(10000); }