Skip to content

Commit

Permalink
changing test setup to async
Browse files Browse the repository at this point in the history
  • Loading branch information
timbussmann committed Dec 1, 2024
1 parent efba8ab commit b9be422
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Annoy-o-Bot.CosmosDB.Tests/CosmosWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

namespace Annoy_o_Bot.CosmosDB.Tests;

public class CosmosWrapperTests : IClassFixture<CosmosFixture>
public class CosmosWrapperTests(CosmosFixture cosmosFixture) : IClassFixture<CosmosFixture>, IAsyncLifetime

Check warning on line 8 in Annoy-o-Bot.CosmosDB.Tests/CosmosWrapperTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'DocumentClient' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in Annoy-o-Bot.CosmosDB.Tests/CosmosWrapperTests.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'CosmosWrapper' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
Container DocumentClient;

CosmosClientWrapper CosmosWrapper;

ReminderDefinition reminderDefinition = new()
Expand All @@ -20,19 +21,28 @@ public class CosmosWrapperTests : IClassFixture<CosmosFixture>
Title = "demo title"
};

public CosmosWrapperTests(CosmosFixture cosmosFixture)
public async Task InitializeAsync()
{
DocumentClient = cosmosFixture.CreateDocumentClient();

CosmosWrapper = new CosmosClientWrapper(DocumentClient);

await DocumentClient.Database.Client.CreateDatabaseIfNotExistsAsync(CosmosClientWrapper.dbName);
try
{
DocumentClient.DeleteContainerAsync().GetAwaiter().GetResult();
await DocumentClient.DeleteContainerAsync();
}
catch (CosmosException e) when (e.StatusCode == HttpStatusCode.NotFound)
{
}

DocumentClient.Database.CreateContainerAsync(new ContainerProperties(CosmosClientWrapper.collectionId, "/id")).GetAwaiter().GetResult();
await DocumentClient.Database.CreateContainerIfNotExistsAsync(
new ContainerProperties(CosmosClientWrapper.collectionId, "/id"));
}

public Task DisposeAsync()
{
return Task.CompletedTask;
}

[Fact]
Expand Down

0 comments on commit b9be422

Please sign in to comment.