Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal] Binary Encoding: Adds emulator tests with binary encoding. #4921

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -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
Loading