From 176f916e61dde89ce974f1af0a72b527224ba055 Mon Sep 17 00:00:00 2001 From: Matias Quaranta Date: Mon, 13 Mar 2023 12:31:39 -0700 Subject: [PATCH] CosmosNullReferenceException: Refactors CosmosNullReferenceException to pass along InnerException property on parent NullReferenceException (#3713) (#3760) * Passed inner exception details to NullReferenceException ctor when instantiating CosmosNullReferenceException. * Added unit tests. * Addressed PR feedback. Co-authored-by: Abhijeet Mohanty --- .../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); + } } }