Skip to content

Commit

Permalink
All ArgumentExceptions in NotificationHubClient use nameof() (#78)
Browse files Browse the repository at this point in the history
* All ArgumentExceptions in NotificationHubClient use `nameof()`

* Fixing up some previously neglected instances where nameof could be applied
  • Loading branch information
marstr authored Sep 18, 2019
1 parent d3aa5e7 commit 3d14ab0
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/Microsoft.Azure.NotificationHubs/NotificationHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public NotificationHubClient(string connectionString, string notificationHubPath
{
if (string.IsNullOrWhiteSpace(connectionString))
{
throw new ArgumentNullException("connectionString");
throw new ArgumentNullException(nameof(connectionString));
}

if (string.IsNullOrWhiteSpace(notificationHubPath))
{
throw new ArgumentNullException("notificationHubPath");
throw new ArgumentNullException(nameof(notificationHubPath));
}

_notificationHubPath = notificationHubPath;
Expand Down Expand Up @@ -250,12 +250,12 @@ public async Task<NotificationHubJob> SubmitNotificationHubJobAsync(Notification
{
if (job == null)
{
throw new ArgumentNullException("job");
throw new ArgumentNullException(nameof(job));
}

if (job.OutputContainerUri == null)
{
throw new ArgumentNullException("OutputContainerUri");
throw new ArgumentNullException($"{nameof(job)}.{nameof(job.OutputContainerUri)}");
}

var requestUri = GetGenericRequestUriBuilder();
Expand Down Expand Up @@ -562,7 +562,7 @@ public Task<NotificationOutcome> SendNotificationAsync(Notification notification
{
if (notification == null)
{
throw new ArgumentNullException("notification");
throw new ArgumentNullException(nameof(notification));
}

return SendNotificationImplAsync(notification, notification.tag, null, CancellationToken.None);
Expand All @@ -582,12 +582,12 @@ public Task<NotificationOutcome> SendNotificationAsync(Notification notification
{
if (notification == null)
{
throw new ArgumentNullException("notification");
throw new ArgumentNullException(nameof(notification));
}

if (notification.tag != null)
{
throw new ArgumentException("notification.Tag property should be null");
throw new ArgumentException($"{nameof(notification)}.{nameof(notification.tag)} property should be null");
}

return SendNotificationImplAsync(notification, tagExpression, null, CancellationToken.None);
Expand All @@ -613,22 +613,22 @@ public Task<NotificationOutcome> SendNotificationAsync(Notification notification
{
if (notification == null)
{
throw new ArgumentNullException("notification");
throw new ArgumentNullException(nameof(notification));
}

if (notification.tag != null)
{
throw new ArgumentException("notification.Tag property should be null");
throw new ArgumentException($"{nameof(notification)}.{nameof(notification.tag)} property should be null");
}

if (tags == null)
{
throw new ArgumentNullException("tags");
throw new ArgumentNullException(nameof(tags));
}

if (tags.Count() == 0)
{
throw new ArgumentException("tags argument should contain at least one tag");
throw new ArgumentException($"{nameof(tags)} argument should contain at least one value");
}

string tagExpression = string.Join("||", tags);
Expand Down Expand Up @@ -705,12 +705,12 @@ public async Task CreateOrUpdateInstallationAsync(Installation installation)
{
if (installation==null)
{
throw new ArgumentNullException("installation");
throw new ArgumentNullException(nameof(installation));
}

if (string.IsNullOrWhiteSpace(installation.InstallationId))
{
throw new InvalidOperationException("InstallationId must be specified");
throw new InvalidOperationException($"{nameof(installation)}.{nameof(installation.InstallationId)} must be specified");
}

var requestUri = GetGenericRequestUriBuilder();
Expand Down Expand Up @@ -755,12 +755,12 @@ public async Task PatchInstallationAsync(string installationId, IList<PartialUpd

if (operations == null)
{
throw new ArgumentNullException("operations");
throw new ArgumentNullException(nameof(operations));
}

if (operations.Count == 0)
{
throw new InvalidOperationException("Operations list is empty");
throw new InvalidOperationException($"{nameof(operations)} list is empty");
}

var requestUri = GetGenericRequestUriBuilder();
Expand Down Expand Up @@ -1301,12 +1301,12 @@ public Task<T> CreateRegistrationAsync<T>(T registration) where T : Registration
if (!string.IsNullOrWhiteSpace(registration.NotificationHubPath) &&
registration.NotificationHubPath != _notificationHubPath)
{
throw new ArgumentException("NotificationHubPath in RegistrationDescription is not valid.");
throw new ArgumentException($"{nameof(registration)}.{nameof(registration.NotificationHubPath)} in {nameof(RegistrationDescription)} is not valid.");
}

if (!string.IsNullOrWhiteSpace(registration.RegistrationId))
{
throw new ArgumentException("RegistrationId should be null or empty");
throw new ArgumentException($"{nameof(registration)}.{nameof(registration.RegistrationId)} should be null or empty");
}

return CreateOrUpdateRegistrationImplAsync(registration, EntityOperatonType.Create, CancellationToken.None);
Expand All @@ -1327,12 +1327,12 @@ public Task<T> UpdateRegistrationAsync<T>(T registration) where T : Registration
{
if (string.IsNullOrWhiteSpace(registration.RegistrationId))
{
throw new ArgumentNullException("RegistrationId");
throw new ArgumentNullException($"{nameof(registration)}.{nameof(registration.RegistrationId)}");
}

if (string.IsNullOrWhiteSpace(registration.ETag))
{
throw new ArgumentNullException("ETag");
throw new ArgumentNullException($"{nameof(registration)}.{nameof(registration.ETag)}");
}

return CreateOrUpdateRegistrationImplAsync(registration, EntityOperatonType.Update, CancellationToken.None);
Expand All @@ -1351,7 +1351,7 @@ public Task<T> CreateOrUpdateRegistrationAsync<T>(T registration) where T : Regi
{
if (string.IsNullOrWhiteSpace(registration.RegistrationId))
{
throw new ArgumentNullException("RegistrationId");
throw new ArgumentNullException($"{nameof(registration)}.{nameof(registration.RegistrationId)}");
}

return CreateOrUpdateRegistrationImplAsync(registration, EntityOperatonType.CreateOrUpdate, CancellationToken.None);
Expand All @@ -1370,7 +1370,7 @@ public Task<TRegistrationDescription> GetRegistrationAsync<TRegistrationDescript
{
if (string.IsNullOrWhiteSpace(registrationId))
{
throw new ArgumentNullException("registrationId");
throw new ArgumentNullException(nameof(registrationId));
}

return GetEntityImplAsync<TRegistrationDescription>("registrations", registrationId, CancellationToken.None);
Expand Down Expand Up @@ -1433,7 +1433,7 @@ public Task<CollectionQueryResult<RegistrationDescription>> GetRegistrationsByCh
{
if (string.IsNullOrWhiteSpace(pnsHandle))
{
throw new ArgumentNullException("pnsHandle");
throw new ArgumentNullException(nameof(pnsHandle));
}

return GetAllRegistrationsImplAsync(continuationToken, top, pnsHandle, null, CancellationToken.None);
Expand All @@ -1451,7 +1451,7 @@ public Task DeleteRegistrationAsync(RegistrationDescription registration)
{
if (registration == null)
{
throw new ArgumentNullException("registration");
throw new ArgumentNullException(nameof(registration));
}

return DeleteRegistrationAsync(registration.RegistrationId, registration.ETag);
Expand Down Expand Up @@ -1482,7 +1482,7 @@ public Task DeleteRegistrationAsync(string registrationId, string etag)
{
if (string.IsNullOrWhiteSpace(registrationId))
{
throw new ArgumentNullException("registrationId");
throw new ArgumentNullException(nameof(registrationId));
}

return DeleteRegistrationImplAsync(registrationId, etag, CancellationToken.None);
Expand All @@ -1500,7 +1500,7 @@ public async Task DeleteRegistrationsByChannelAsync(string pnsHandle)
{
if (string.IsNullOrWhiteSpace(pnsHandle))
{
throw new ArgumentNullException("pnsHandle");
throw new ArgumentNullException(nameof(pnsHandle));
}

var registrationsToDelete = await GetRegistrationsByChannelAsync(pnsHandle, EntitiesPerRequest).ConfigureAwait(false);
Expand Down Expand Up @@ -1539,7 +1539,7 @@ public Task<CollectionQueryResult<RegistrationDescription>> GetRegistrationsByTa
{
if (string.IsNullOrWhiteSpace(tag))
{
throw new ArgumentNullException("tag");
throw new ArgumentNullException(nameof(tag));
}

return GetAllRegistrationsImplAsync(null, top, null, tag, CancellationToken.None);
Expand All @@ -1559,7 +1559,7 @@ public Task<CollectionQueryResult<RegistrationDescription>> GetRegistrationsByTa
{
if (string.IsNullOrWhiteSpace(tag))
{
throw new ArgumentNullException("tag");
throw new ArgumentNullException(nameof(tag));
}

return GetAllRegistrationsImplAsync(continuationToken, top, null, tag, CancellationToken.None);
Expand Down Expand Up @@ -1599,12 +1599,12 @@ public Task<ScheduledNotification> ScheduleNotificationAsync(Notification notifi

if (tags == null)
{
throw new ArgumentNullException("tags");
throw new ArgumentNullException(nameof(tags));
}

if (tags.Count() == 0)
{
throw new ArgumentException("tags argument should contain at least one tag");
throw new ArgumentException(message: $"{nameof(tags)} argument should contain at least one value", paramName: nameof(tags));
}

string tagExpression = String.Join("||", tags);
Expand Down Expand Up @@ -1665,12 +1665,12 @@ public Task<NotificationOutcome> SendDirectNotificationAsync(Notification notifi
{
if (notification == null)
{
throw new ArgumentNullException("notification");
throw new ArgumentNullException(nameof(notification));
}

if (string.IsNullOrEmpty(deviceHandle))
{
throw new ArgumentNullException("deviceHandle");
throw new ArgumentNullException(nameof(deviceHandle));
}

return SendNotificationImplAsync(notification, null, deviceHandle, CancellationToken.None);
Expand All @@ -1692,17 +1692,17 @@ public async Task<NotificationOutcome> SendDirectNotificationAsync(Notification
{
if (notification == null)
{
throw new ArgumentNullException("notification");
throw new ArgumentNullException(nameof(notification));
}

if (deviceHandles==null)
{
throw new ArgumentNullException("deviceHandles");
throw new ArgumentNullException(nameof(deviceHandles));
}

if (deviceHandles.Count == 0)
{
throw new ArgumentException("deviceHandles");
throw new ArgumentException(message: $"{nameof(deviceHandles)} should contain at least one value", paramName: nameof(deviceHandles));
}

var requestUri = GetGenericRequestUriBuilder();
Expand Down

0 comments on commit 3d14ab0

Please sign in to comment.