Skip to content

Commit

Permalink
Update emulator tests for binary encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
aavasthy committed Dec 3, 2024
1 parent 292771d commit 22a5f8d
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,67 @@ public async Task NonPartitionKeyLookupCacheTest(bool binaryEncodingEnabledInCli
{
Environment.SetEnvironmentVariable(ConfigurationManager.BinaryEncodingEnabled, null);
}
}

[TestMethod]
[DataRow(true, DisplayName = "Container creation and deletion with binary encoding enabled.")]
[DataRow(false, DisplayName = "Container creation and deletion with binary encoding disabled.")]
public async Task ContainerCreationDeletionTest(bool binaryEncodingEnabledInClient)
{
string containerId = Guid.NewGuid().ToString();
try
{
if (binaryEncodingEnabledInClient)
{
Environment.SetEnvironmentVariable(ConfigurationManager.BinaryEncodingEnabled, "True");
}

// Create the container
string partitionKeyPath = "/pk";
ContainerProperties containerProperties = new ContainerProperties(containerId, partitionKeyPath);
ContainerResponse createResponse = await this.database.CreateContainerAsync(containerProperties);
Assert.AreEqual(HttpStatusCode.Created, createResponse.StatusCode);
Assert.IsNotNull(createResponse.Container);

// Perform a read operation to verify the container exists
Container readContainer = this.database.GetContainer(containerId);
ContainerResponse readResponse = await readContainer.ReadContainerAsync();
Assert.AreEqual(HttpStatusCode.OK, readResponse.StatusCode);
Assert.IsNotNull(readResponse.Resource);

ToDoActivity testItem = ToDoActivity.CreateRandomToDoActivity();
Cosmos.PartitionKey? partitionKey = testItem.pk != null ? new Cosmos.PartitionKey(testItem.pk) : (Cosmos.PartitionKey?)null;
ItemResponse<ToDoActivity> itemResponse = await readContainer.CreateItemAsync(testItem, partitionKey);
Assert.AreEqual(HttpStatusCode.Created, itemResponse.StatusCode);

// Delete the container
ContainerResponse deleteResponse = await readContainer.DeleteContainerAsync();
Assert.AreEqual(HttpStatusCode.NoContent, deleteResponse.StatusCode);

// Attempt to read the container again to ensure it was deleted
try
{
await readContainer.ReadContainerAsync();
Assert.Fail("Expected a NotFound exception after deleting the container.");
}
catch (CosmosException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
{
Assert.IsNotNull(ex);
}
}
finally
{
Environment.SetEnvironmentVariable(ConfigurationManager.BinaryEncodingEnabled, null);
try
{
Container container = this.database.GetContainer(containerId);
await container.DeleteContainerAsync();
}
catch
{
// Ignore exceptions in cleanup
}
}
}

[TestMethod]
Expand Down

0 comments on commit 22a5f8d

Please sign in to comment.