From 8295f855564b46eb3af9f168ea462c38a808da46 Mon Sep 17 00:00:00 2001 From: Abhijeet Mohanty Date: Fri, 17 Feb 2023 14:46:38 -0500 Subject: [PATCH] CosmosNullReferenceException: Refactors CosmosNullReferenceException to pass along InnerException property on parent NullReferenceException (#3713) * Passed inner exception details to NullReferenceException ctor when instantiating CosmosNullReferenceException. * Added unit tests. * Addressed PR feedback. --- .../CosmosExceptions/CosmosNullReferenceException.cs | 5 +++-- .../CosmosNullReferenceExceptionTests.cs | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Resource/CosmosExceptions/CosmosNullReferenceException.cs b/Microsoft.Azure.Cosmos/src/Resource/CosmosExceptions/CosmosNullReferenceException.cs index 03e4cb21e8..4e7aa73f54 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/CosmosExceptions/CosmosNullReferenceException.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/CosmosExceptions/CosmosNullReferenceException.cs @@ -25,9 +25,10 @@ internal class CosmosNullReferenceException : NullReferenceException /// internal CosmosNullReferenceException( NullReferenceException originalException, - ITrace trace) + ITrace trace) + : base(originalException?.Message ?? throw new ArgumentNullException(nameof(originalException)), originalException ?? throw new ArgumentNullException(nameof(originalException))) { - this.originalException = originalException ?? throw new ArgumentNullException(nameof(originalException)); + this.originalException = originalException; if (trace == null) { diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosNullReferenceExceptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosNullReferenceExceptionTests.cs index a97b56189b..072b63a660 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosNullReferenceExceptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosNullReferenceExceptionTests.cs @@ -37,9 +37,10 @@ public void CosmosNullRefWrapingTest() trace); Assert.AreEqual(nullReferenceException.StackTrace, cosmosNullReferenceException.StackTrace); - Assert.AreEqual(nullReferenceException.InnerException, cosmosNullReferenceException.InnerException); + Assert.AreEqual(nullReferenceException, cosmosNullReferenceException.InnerException); Assert.AreEqual(nullReferenceException.Data, cosmosNullReferenceException.Data); + Assert.IsTrue(cosmosNullReferenceException.Message.Contains(message)); Assert.IsTrue(cosmosNullReferenceException.Message.Contains(rootTraceName)); Assert.AreNotEqual(nullReferenceException.Message, cosmosNullReferenceException.Message); @@ -48,5 +49,12 @@ public void CosmosNullRefWrapingTest() Assert.IsTrue(cosmosToString.Contains(message)); Assert.IsTrue(cosmosToString.Contains(rootTraceName)); } + + [TestMethod] + [ExpectedException(typeof(ArgumentNullException))] + public void ExpectArgumentNullExceptionTest() + { + _ = new CosmosNullReferenceException(null, NoOpTrace.Singleton); + } } }