From 237acc02ea6b5a0d652f4cb4038a4f7b2dc45b54 Mon Sep 17 00:00:00 2001 From: Debdatta Kunda Date: Wed, 27 Sep 2023 12:33:47 -0700 Subject: [PATCH] Code changes to fix unit test. --- .../GlobalPartitionEndpointManagerTests.cs | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyRangeFailoverTests/GlobalPartitionEndpointManagerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyRangeFailoverTests/GlobalPartitionEndpointManagerTests.cs index bac068518c..d8e5fd2d53 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyRangeFailoverTests/GlobalPartitionEndpointManagerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/PartitionKeyRangeFailoverTests/GlobalPartitionEndpointManagerTests.cs @@ -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, @@ -241,29 +240,14 @@ public async Task CreateItemAsync_WithNoPreferredRegionsAndServiceUnavailable_Sh TransportClientHandlerFactory = (original) => mockTransport.Object, }; - using CosmosClient customClient = new CosmosClient( + ArgumentException exception = Assert.ThrowsException(() => 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]