From 30a65bb0df012a9454b7deaac08609ae4dc649c5 Mon Sep 17 00:00:00 2001 From: abhinavminhas Date: Sun, 28 Jul 2024 16:20:04 +1000 Subject: [PATCH] ModifyMessage/ModifyMessages - Throw 'ArgumentNullException' instead of 'NullReferenceException' --- GmailAPIHelper.CORE.Tests/GmailTests.cs | 4 ++-- GmailAPIHelper.NET.Tests/GmailTests.cs | 4 ++-- GmailAPIHelper/GmailHelper.cs | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/GmailAPIHelper.CORE.Tests/GmailTests.cs b/GmailAPIHelper.CORE.Tests/GmailTests.cs index 3591935..265387f 100644 --- a/GmailAPIHelper.CORE.Tests/GmailTests.cs +++ b/GmailAPIHelper.CORE.Tests/GmailTests.cs @@ -1093,7 +1093,7 @@ public void Test_ModifyMessage_NoLabelsSupplied() Assert.Fail("No Exception Thrown."); } catch (AssertFailedException ex) { throw ex; } - catch (NullReferenceException ex) { Assert.AreEqual("Either 'Labels To Add' or 'Labels to Remove' required.", ex.Message); } + catch (ArgumentNullException ex) { Assert.AreEqual("Value cannot be null. (Parameter ' / required.')", ex.Message); } } [TestMethod] @@ -1148,7 +1148,7 @@ public void Test_ModifyMessages_NoLabelsSupplied() Assert.Fail("No Exception Thrown."); } catch (AssertFailedException ex) { throw ex; } - catch (NullReferenceException ex) { Assert.AreEqual("Either 'Labels To Add' or 'Labels to Remove' required.", ex.Message); } + catch (ArgumentNullException ex) { Assert.AreEqual("Value cannot be null. (Parameter ' / required.')", ex.Message); } } [TestMethod] diff --git a/GmailAPIHelper.NET.Tests/GmailTests.cs b/GmailAPIHelper.NET.Tests/GmailTests.cs index e081a90..e361447 100644 --- a/GmailAPIHelper.NET.Tests/GmailTests.cs +++ b/GmailAPIHelper.NET.Tests/GmailTests.cs @@ -882,7 +882,7 @@ public void Test_ModifyMessage_NoLabelsSupplied() Assert.Fail("No Exception Thrown."); } catch (AssertFailedException ex) { throw ex; } - catch (NullReferenceException ex) { Assert.AreEqual("Either 'Labels To Add' or 'Labels to Remove' required.", ex.Message); } + catch (ArgumentNullException ex) { Assert.AreEqual("Value cannot be null. (Parameter ' / required.')", ex.Message); } } [TestMethod] @@ -930,7 +930,7 @@ public void Test_ModifyMessages_NoLabelsSupplied() Assert.Fail("No Exception Thrown."); } catch (AssertFailedException ex) { throw ex; } - catch (NullReferenceException ex) { Assert.AreEqual("Either 'Labels To Add' or 'Labels to Remove' required.", ex.Message); } + catch (ArgumentNullException ex) { Assert.AreEqual("Value cannot be null. (Parameter ' / required.')", ex.Message); } } [TestMethod] diff --git a/GmailAPIHelper/GmailHelper.cs b/GmailAPIHelper/GmailHelper.cs index d58e957..12b4f44 100644 --- a/GmailAPIHelper/GmailHelper.cs +++ b/GmailAPIHelper/GmailHelper.cs @@ -1136,7 +1136,7 @@ public static int MarkMessagesAsUnread(this GmailService gmailService, string qu /// /// Modifies the labels on the latest message for a specified query criteria. - /// Requires - 'labelsToAdd' And/Or 'labelsToRemove' param value. Throws 'NullReferenceException' if none supplied. + /// Requires - 'labelsToAdd' And/Or 'labelsToRemove' param value. Throws 'ArgumentNullException' if none supplied. /// /// 'Gmail' service initializer value. /// 'Query' criteria for the email to search. @@ -1145,11 +1145,11 @@ public static int MarkMessagesAsUnread(this GmailService gmailService, string qu /// User's email address. 'User Id' for request to authenticate. Default - 'me (authenticated user)'. /// Boolean value to choose whether to dispose Gmail service instance used or not. Default - 'true'. /// Boolean value to confirm if the email message labels for the criteria were modified or not. - /// Throws 'NullReferenceException' if none of 'labelsToAdd' and 'labelsToRemove' value is supplied + /// Throws 'ArgumentNullException' if none of 'labelsToAdd' and 'labelsToRemove' value is supplied public static bool ModifyMessage(this GmailService gmailService, string query, List labelsToAdd = null, List labelsToRemove = null, string userId = "me", bool disposeGmailService = true) { if (labelsToAdd == null && labelsToRemove == null) - throw new NullReferenceException("Either 'Labels To Add' or 'Labels to Remove' required."); + throw new ArgumentNullException(" / required."); var mods = new ModifyMessageRequest(); if (labelsToAdd != null) mods.AddLabelIds = labelsToAdd; @@ -1195,7 +1195,7 @@ public static bool ModifyMessage(this GmailService gmailService, string query, L /// /// Modifies the labels on the messages for a specified query criteria. - /// Requires - 'labelsToAdd' And/Or 'labelsToRemove' param value. Throws 'NullReferenceException' if none supplied. + /// Requires - 'labelsToAdd' And/Or 'labelsToRemove' param value. Throws 'ArgumentNullException' if none supplied. /// /// 'Gmail' service initializer value. /// 'Query' criteria for the email to search. @@ -1204,11 +1204,11 @@ public static bool ModifyMessage(this GmailService gmailService, string query, L /// User's email address. 'User Id' for request to authenticate. Default - 'me (authenticated user)'. /// Boolean value to choose whether to dispose Gmail service instance used or not. Default - 'true'. /// Count of email messages with labels modified. - /// Throws 'NullReferenceException' if none of 'labelsToAdd' and 'labelsToRemove' value is supplied + /// Throws 'ArgumentNullException' if none of 'labelsToAdd' and 'labelsToRemove' value is supplied public static int ModifyMessages(this GmailService gmailService, string query, List labelsToAdd = null, List labelsToRemove = null, string userId = "me", bool disposeGmailService = true) { if (labelsToAdd == null && labelsToRemove == null) - throw new NullReferenceException("Either 'Labels To Add' or 'Labels to Remove' required."); + throw new ArgumentNullException(" / required."); var mods = new ModifyMessageRequest(); if (labelsToAdd != null) mods.AddLabelIds = labelsToAdd;