Skip to content

Commit b191834

Browse files
authored
[Internal] DocumentClient: Adds TryGetAccountProperties (#4167)
* add api * tests * Update test * Rename
1 parent f7a4c56 commit b191834

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

Microsoft.Azure.Cosmos/src/DocumentClient.cs

+17
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,23 @@ public virtual Documents.ConsistencyLevel ConsistencyLevel
12351235
}
12361236
}
12371237

1238+
/// <summary>
1239+
/// Returns the account properties available in the service configuration if the client was initialized.
1240+
/// </summary>
1241+
public bool TryGetCachedAccountProperties(out AccountProperties properties)
1242+
{
1243+
if (this.isSuccessfullyInitialized
1244+
&& this.accountServiceConfiguration != null
1245+
&& this.accountServiceConfiguration.AccountProperties != null)
1246+
{
1247+
properties = this.accountServiceConfiguration.AccountProperties;
1248+
return true;
1249+
}
1250+
1251+
properties = null;
1252+
return false;
1253+
}
1254+
12381255
/// <summary>
12391256
/// Disposes the client for the Azure Cosmos DB service.
12401257
/// </summary>

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/ClientTests.cs

+18
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,24 @@ public async Task ValidateAzureKeyCredentialDirectModeUpdateAsync()
290290
}
291291
}
292292

293+
[TestMethod]
294+
public async Task ValidateTryGetAccountProperties()
295+
{
296+
using CosmosClient cosmosClient = new CosmosClient(
297+
ConfigurationManager.AppSettings["GatewayEndpoint"],
298+
ConfigurationManager.AppSettings["MasterKey"]
299+
);
300+
301+
Assert.IsFalse(cosmosClient.DocumentClient.TryGetCachedAccountProperties(out AccountProperties propertiesFromMethod));
302+
303+
AccountProperties accountProperties = await cosmosClient.ReadAccountAsync();
304+
305+
Assert.IsTrue(cosmosClient.DocumentClient.TryGetCachedAccountProperties(out propertiesFromMethod));
306+
307+
Assert.AreEqual(accountProperties.Consistency.DefaultConsistencyLevel, propertiesFromMethod.Consistency.DefaultConsistencyLevel);
308+
Assert.AreEqual(accountProperties.Id, propertiesFromMethod.Id);
309+
}
310+
293311
private int TaskStartedCount = 0;
294312

295313
private async Task<Exception> ReadNotFound(Container container)

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/InterfaceParityTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void TestAllPublicMethodsExistInIDocumentClient()
2424
string[] excludedMethods = new string[]
2525
{
2626
"OpenAsync", // exposed public methods.
27+
"TryGetCachedAccountProperties", // currently only internal
2728
"get_PartitionResolvers", "get_ResourceTokens", // Obsolete getters.
2829
"ToString", "Equals", "GetHashCode", "GetType", "get_httpClient"
2930
};

0 commit comments

Comments
 (0)