Skip to content

Commit 88ba4e4

Browse files
Validate URI is not null (Azure#19433)
1 parent 3733b8d commit 88ba4e4

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

sdk/eventgrid/Azure.Messaging.EventGrid/src/Customization/EventGridPublisherClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public EventGridPublisherClient(Uri endpoint, AzureKeyCredential credential)
4141
/// <param name="options">The set of options to use for configuring the client.</param>
4242
public EventGridPublisherClient(Uri endpoint, AzureKeyCredential credential, EventGridPublisherClientOptions options)
4343
{
44+
Argument.AssertNotNull(endpoint, nameof(endpoint));
4445
Argument.AssertNotNull(credential, nameof(credential));
4546
options ??= new EventGridPublisherClientOptions();
4647
_uriBuilder = new RequestUriBuilder();
@@ -59,6 +60,7 @@ public EventGridPublisherClient(Uri endpoint, AzureKeyCredential credential, Eve
5960
/// <param name="options">The set of options to use for configuring the client.</param>
6061
public EventGridPublisherClient(Uri endpoint, AzureSasCredential credential, EventGridPublisherClientOptions options = default)
6162
{
63+
Argument.AssertNotNull(endpoint, nameof(endpoint));
6264
Argument.AssertNotNull(credential, nameof(credential));
6365
options ??= new EventGridPublisherClientOptions();
6466
_uriBuilder = new RequestUriBuilder();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using NUnit.Framework;
6+
7+
namespace Azure.Messaging.EventGrid.Tests
8+
{
9+
public class EventGridClientTests
10+
{
11+
[Test]
12+
public void ConstructorValidatesUriNotNull()
13+
{
14+
Assert.That(
15+
() => new EventGridPublisherClient(null, new AzureKeyCredential("credential")),
16+
Throws.InstanceOf<ArgumentNullException>());
17+
Assert.That(
18+
() => new EventGridPublisherClient(null, new AzureSasCredential("credential")),
19+
Throws.InstanceOf<ArgumentNullException>());
20+
}
21+
22+
[Test]
23+
public void ConstructorValidatesKeyNotNull()
24+
{
25+
Assert.That(
26+
() => new EventGridPublisherClient(new Uri("http://localHost"), (AzureKeyCredential)null),
27+
Throws.InstanceOf<ArgumentNullException>());
28+
Assert.That(
29+
() => new EventGridPublisherClient(new Uri("http://localHost"), (AzureSasCredential)null),
30+
Throws.InstanceOf<ArgumentNullException>());
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)