Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,15 @@ private async Task CreateFromFile(DbContext context)
{
if (await EnsureCreatedAsync(context).ConfigureAwait(false))
{
await context.Database.EnsureCreatedAsync().ConfigureAwait(false);
if (!TestEnvironment.UseTokenCredential)
{
await context.Database.EnsureCreatedAsync().ConfigureAwait(false);
}
else
{
await CreateContainersAsync(context).ConfigureAwait(false);
}

var cosmosClient = context.GetService<ICosmosClientWrapper>();
var serializer = CosmosClientWrapper.Serializer;
using var fs = new FileStream(_dataFilePath!, FileMode.Open, FileAccess.Read);
Expand Down Expand Up @@ -253,17 +261,36 @@ public async Task<bool> EnsureCreatedAsync(DbContext context, CancellationToken

var databaseAccount = await GetDBAccount(cancellationToken).ConfigureAwait(false);
var collection = databaseAccount.Value.GetCosmosDBSqlDatabases();
var sqlDatabaseCreateUpdateOptions = new CosmosDBSqlDatabaseCreateOrUpdateContent(
var sqlDatabaseCreateUpdateContent = new CosmosDBSqlDatabaseCreateOrUpdateContent(
TestEnvironment.AzureLocation,
new CosmosDBSqlDatabaseResourceInfo(Name));
if (await collection.ExistsAsync(Name, cancellationToken))
{
return false;
}

var databaseResponse = (await collection.CreateOrUpdateAsync(
WaitUntil.Completed, Name, sqlDatabaseCreateUpdateOptions, cancellationToken).ConfigureAwait(false)).GetRawResponse();
return databaseResponse.Status == (int)HttpStatusCode.OK;
var model = context.GetService<IDesignTimeModel>().Model;

var modelThrouput = model.GetThroughput();
if (modelThrouput == null
&& GetContainersToCreate(model).All(c => c.Throughput == null))
{
modelThrouput = ThroughputProperties.CreateManualThroughput(400);
}

if (modelThrouput != null)
{
sqlDatabaseCreateUpdateContent.Options = new CosmosDBCreateUpdateConfig
{
Throughput = modelThrouput.Throughput,
AutoscaleMaxThroughput = modelThrouput.AutoscaleMaxThroughput
};
}

var databaseResponse = await collection.CreateOrUpdateAsync(
WaitUntil.Completed, Name, sqlDatabaseCreateUpdateContent, cancellationToken).ConfigureAwait(false);

return databaseResponse.GetRawResponse().Status == (int)HttpStatusCode.OK;
}

private async Task<bool> EnsureDeletedAsync(DbContext context, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -362,8 +389,11 @@ private async Task CreateContainersAsync(DbContext context)
var content = new CosmosDBSqlContainerCreateOrUpdateContent(TestEnvironment.AzureLocation, resource);
if (container.Throughput != null)
{
content.Options.AutoscaleMaxThroughput = container.Throughput.AutoscaleMaxThroughput;
content.Options.Throughput = container.Throughput.Throughput;
content.Options = new CosmosDBCreateUpdateConfig
{
AutoscaleMaxThroughput = container.Throughput.AutoscaleMaxThroughput,
Throughput = container.Throughput.Throughput
};
}

await database.Value.GetCosmosDBSqlContainers().CreateOrUpdateAsync(
Expand Down