diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmBuilder.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmBuilder.cs index 353a316d5b79..7a1f39ac9152 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmBuilder.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmBuilder.cs @@ -61,8 +61,12 @@ public TResource Build() /// /// The name of the new resource to create. /// A response with the operation for this resource. + /// Name cannot be null or a whitespace. public ArmResponse CreateOrUpdate(string name) { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException("Name cannot be null or whitespace.", nameof(name)); + ResourceName = name; Resource = Build(); @@ -75,10 +79,14 @@ public ArmResponse CreateOrUpdate(string name) /// The name of the new resource to create. /// A token to allow the caller to cancel the call to the service. The default value is . /// A that on completion returns a response with the operation for this resource. + /// Name cannot be null or a whitespace. public async Task> CreateOrUpdateAsync( string name, CancellationToken cancellationToken = default) { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException("Name cannot be null or whitespace.", nameof(name)); + ResourceName = name; Resource = Build(); @@ -94,8 +102,12 @@ public async Task> CreateOrUpdateAsync( /// /// Details on long running operation object. /// + /// Name cannot be null or a whitespace. public ArmOperation StartCreateOrUpdate(string name, CancellationToken cancellationToken = default) { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException("Name cannot be null or whitespace.", nameof(name)); + ResourceName = name; Resource = Build(); @@ -111,10 +123,14 @@ public ArmOperation StartCreateOrUpdate(string name, CancellationTo /// /// Details on long running operation object. /// + /// Name cannot be null or a whitespace. public async Task> StartCreateOrUpdateAsync( string name, CancellationToken cancellationToken = default) { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException("Name cannot be null or whitespace.", nameof(name)); + ResourceName = name; Resource = Build(); diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs index c4bb2ca12343..388fdfa3a4a8 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs @@ -71,8 +71,8 @@ public AsyncPageable ListAsync(CancellationToken cancellationToken /// The identifier of the resource. protected override void Validate(ResourceIdentifier identifier) { - if (identifier != null) - throw new ArgumentException("Invalid parent for subscription container"); + if (!(identifier is null)) + throw new ArgumentException("Invalid parent for subscription container", nameof(identifier)); } /// diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/ArmBuilderTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/ArmBuilderTests.cs new file mode 100644 index 000000000000..a7a2965b07a8 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/ArmBuilderTests.cs @@ -0,0 +1,43 @@ +using NUnit.Framework; +using System; +using System.Text; +using System.Threading.Tasks; + +namespace Azure.ResourceManager.Core.Tests +{ + [Ignore("Waiting on ADO item: 5122")] + public class ArmBuilderTests + { + [TestCase(null)] + [TestCase(" ")] + public void TestCreateOrUpdate(string value) + { + var armClient = new AzureResourceManagerClient(); + Assert.Throws(delegate { armClient.DefaultSubscription.GetResourceGroupContainer().Construct(LocationData.WestUS2).CreateOrUpdate(value); }); + } + + [TestCase(null)] + [TestCase(" ")] + public void TestCreateOrUpdateAsync(string value) + { + var armClient = new AzureResourceManagerClient(); + Assert.ThrowsAsync(async delegate { await armClient.DefaultSubscription.GetResourceGroupContainer().Construct(LocationData.WestUS2).CreateOrUpdateAsync(value); }); + } + + [TestCase(null)] + [TestCase("")] + public void TestStartCreateOrUpdate(string value) + { + var armClient = new AzureResourceManagerClient(); + Assert.Throws(delegate { armClient.DefaultSubscription.GetResourceGroupContainer().Construct(LocationData.WestUS2).StartCreateOrUpdate(value); }); + } + + [TestCase(null)] + [TestCase(" ")] + public void TestStartCreateOrUpdateAsync(string value) + { + var armClient = new AzureResourceManagerClient(); + Assert.ThrowsAsync(async delegate { await armClient.DefaultSubscription.GetResourceGroupContainer().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(value); }); + } + } +}