Skip to content

Commit

Permalink
ModifyMessage/ModifyMessages - Throw 'ArgumentNullException' instead …
Browse files Browse the repository at this point in the history
…of 'NullReferenceException'
  • Loading branch information
abhinavminhas committed Jul 28, 2024
1 parent aecce27 commit 30a65bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions GmailAPIHelper.CORE.Tests/GmailTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<labelsToAdd> / <labelsToRemove> required.')", ex.Message); }
}

[TestMethod]
Expand Down Expand Up @@ -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 '<labelsToAdd> / <labelsToRemove> required.')", ex.Message); }
}

[TestMethod]
Expand Down
4 changes: 2 additions & 2 deletions GmailAPIHelper.NET.Tests/GmailTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<labelsToAdd> / <labelsToRemove> required.')", ex.Message); }
}

[TestMethod]
Expand Down Expand Up @@ -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 '<labelsToAdd> / <labelsToRemove> required.')", ex.Message); }
}

[TestMethod]
Expand Down
12 changes: 6 additions & 6 deletions GmailAPIHelper/GmailHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ public static int MarkMessagesAsUnread(this GmailService gmailService, string qu

/// <summary>
/// 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.
/// </summary>
/// <param name="gmailService">'Gmail' service initializer value.</param>
/// <param name="query">'Query' criteria for the email to search.</param>
Expand All @@ -1145,11 +1145,11 @@ public static int MarkMessagesAsUnread(this GmailService gmailService, string qu
/// <param name="userId">User's email address. 'User Id' for request to authenticate. Default - 'me (authenticated user)'.</param>
/// <param name="disposeGmailService">Boolean value to choose whether to dispose Gmail service instance used or not. Default - 'true'.</param>
/// <returns>Boolean value to confirm if the email message labels for the criteria were modified or not.</returns>
/// <exception cref="NullReferenceException">Throws 'NullReferenceException' if none of 'labelsToAdd' and 'labelsToRemove' value is supplied</exception>
/// <exception cref="ArgumentNullException">Throws 'ArgumentNullException' if none of 'labelsToAdd' and 'labelsToRemove' value is supplied</exception>
public static bool ModifyMessage(this GmailService gmailService, string query, List<string> labelsToAdd = null, List<string> 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("<labelsToAdd> / <labelsToRemove> required.");
var mods = new ModifyMessageRequest();
if (labelsToAdd != null)
mods.AddLabelIds = labelsToAdd;
Expand Down Expand Up @@ -1195,7 +1195,7 @@ public static bool ModifyMessage(this GmailService gmailService, string query, L

/// <summary>
/// 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.
/// </summary>
/// <param name="gmailService">'Gmail' service initializer value.</param>
/// <param name="query">'Query' criteria for the email to search.</param>
Expand All @@ -1204,11 +1204,11 @@ public static bool ModifyMessage(this GmailService gmailService, string query, L
/// <param name="userId">User's email address. 'User Id' for request to authenticate. Default - 'me (authenticated user)'.</param>
/// <param name="disposeGmailService">Boolean value to choose whether to dispose Gmail service instance used or not. Default - 'true'.</param>
/// <returns>Count of email messages with labels modified.</returns>
/// <exception cref="NullReferenceException">Throws 'NullReferenceException' if none of 'labelsToAdd' and 'labelsToRemove' value is supplied</exception>
/// <exception cref="ArgumentNullException">Throws 'ArgumentNullException' if none of 'labelsToAdd' and 'labelsToRemove' value is supplied</exception>
public static int ModifyMessages(this GmailService gmailService, string query, List<string> labelsToAdd = null, List<string> 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("<labelsToAdd> / <labelsToRemove> required.");
var mods = new ModifyMessageRequest();
if (labelsToAdd != null)
mods.AddLabelIds = labelsToAdd;
Expand Down

0 comments on commit 30a65bb

Please sign in to comment.