Skip to content

Commit

Permalink
Code changes to fix unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kundadebdatta committed Sep 27, 2023
1 parent f740c9d commit 237acc0
Showing 1 changed file with 6 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ public async Task CreateItemAsync_WithPreferredRegionsAndServiceUnavailable_Shou


[TestMethod]
[Timeout(10000)]
public async Task CreateItemAsync_WithNoPreferredRegionsAndServiceUnavailable_ShouldThrowServiceUnavailableException()
public void CreateItemAsync_WithNoPreferredRegionsAndServiceUnavailable_ShouldThrowArgumentException()
{
GlobalPartitionEndpointManagerTests.SetupAccountAndCacheOperations(
out string secondaryRegionNameForUri,
Expand Down Expand Up @@ -241,29 +240,14 @@ public async Task CreateItemAsync_WithNoPreferredRegionsAndServiceUnavailable_Sh
TransportClientHandlerFactory = (original) => mockTransport.Object,
};

using CosmosClient customClient = new CosmosClient(
ArgumentException exception = Assert.ThrowsException<ArgumentException>(() => new CosmosClient(
globalEndpoint,
Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())),
cosmosClientOptions);

Container container = customClient.GetContainer(databaseName, containerName);

ToDoActivity toDoActivity = new ToDoActivity()
{
Id = "TestItem",
Pk = "TestPk"
};
cosmosClientOptions));

// First create will fail because it is not certain if the payload was sent or not.
try
{
await container.CreateItemAsync(toDoActivity, new Cosmos.PartitionKey(toDoActivity.Pk));
Assert.Fail("Should throw an exception");
}
catch (CosmosException ce) when (ce.StatusCode == HttpStatusCode.ServiceUnavailable)
{
Assert.IsNotNull(ce);
}
Assert.AreEqual(
expected: "ApplicationPreferredRegions is required when EnablePartitionLevelFailover is enabled.",
actual: exception.Message);
}

[TestMethod]
Expand Down

0 comments on commit 237acc0

Please sign in to comment.