public async Task CreateDatabaseAsync_WhenUsingWithOffer_ThenDatabaseIsCreatedWithDbLevelScaling() { // Arrange var expectedThroughput = 10000; // Act await _cosmonautClient.CreateDatabaseAsync(new Database { Id = _scaleableDbId }, new RequestOptions { OfferThroughput = 10000 }); // Assert var offer = await _cosmonautClient.GetOfferV2ForDatabaseAsync(_scaleableDbId); offer.Content.OfferThroughput.Should().Be(expectedThroughput); }
public async Task <bool> EnsureCreatedAsync <TEntity>( string databaseId, string collectionId, int collectionThroughput, IndexingPolicy indexingPolicy = null, ThroughputBehaviour onDatabaseBehaviour = ThroughputBehaviour.UseDatabaseThroughput, UniqueKeyPolicy uniqueKeyPolicy = null) where TEntity : class { var collectionResource = await _cosmonautClient.GetCollectionAsync(databaseId, collectionId); var databaseHasOffer = (await _cosmonautClient.GetOfferV2ForDatabaseAsync(databaseId)) != null; if (collectionResource != null) { return(true); } var newCollection = new DocumentCollection { Id = collectionId, IndexingPolicy = indexingPolicy ?? CosmosConstants.DefaultIndexingPolicy, UniqueKeyPolicy = uniqueKeyPolicy ?? CosmosConstants.DefaultUniqueKeyPolicy }; SetPartitionKeyDefinitionForCollection(typeof(TEntity), newCollection); var finalCollectionThroughput = databaseHasOffer ? onDatabaseBehaviour == ThroughputBehaviour.DedicateCollectionThroughput ? (int?)collectionThroughput : null : collectionThroughput; newCollection = await _cosmonautClient.CreateCollectionAsync(databaseId, newCollection, new RequestOptions { OfferThroughput = finalCollectionThroughput }); return(newCollection != null); }
public async Task DatabaseCreator_CreatesDatabaseWithoutThroughput_WhenThroughputNull() { var databaseCreator = new CosmosDatabaseCreator(_cosmonautClient); var created = await databaseCreator.EnsureCreatedAsync(_databaseId); var offer = await _cosmonautClient.GetOfferV2ForDatabaseAsync(_databaseId); created.Should().BeTrue(); offer.Should().BeNull(); }