From d9a3a79bd71c27c95a7e5a4892600c894cab831f Mon Sep 17 00:00:00 2001 From: nisha-bhatia Date: Thu, 4 Mar 2021 13:16:44 -0800 Subject: [PATCH 1/3] add tests for ArmBuilder --- .../src/ArmBuilder.cs | 16 +++++++ .../src/SubscriptionContainer.cs | 2 +- .../tests/ArmBuilderTests.cs | 42 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/tests/ArmBuilderTests.cs diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmBuilder.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmBuilder.cs index 353a316d5b792..7a1f39ac9152e 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 c4bb2ca123434..e34f6065b00f5 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs @@ -72,7 +72,7 @@ public AsyncPageable ListAsync(CancellationToken cancellationToken protected override void Validate(ResourceIdentifier identifier) { if (identifier != null) - throw new ArgumentException("Invalid parent for subscription container"); + 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 0000000000000..f71d959a7a44b --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/ArmBuilderTests.cs @@ -0,0 +1,42 @@ +using NUnit.Framework; +using System; +using System.Text; +using System.Threading.Tasks; + +namespace Azure.ResourceManager.Core.Tests +{ + 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); }); + } + } +} From 96a62d7b0f94bde121fb807064e527d26622202e Mon Sep 17 00:00:00 2001 From: nisha-bhatia Date: Thu, 4 Mar 2021 13:44:17 -0800 Subject: [PATCH 2/3] Update ArmBuilderTests.cs --- .../Azure.ResourceManager.Core/tests/ArmBuilderTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/ArmBuilderTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/ArmBuilderTests.cs index f71d959a7a44b..a7a2965b07a80 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/ArmBuilderTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/ArmBuilderTests.cs @@ -5,6 +5,7 @@ namespace Azure.ResourceManager.Core.Tests { + [Ignore("Waiting on ADO item: 5122")] public class ArmBuilderTests { [TestCase(null)] From 6e3cbc806a5fe2fe94215e57011f75a615ab4f79 Mon Sep 17 00:00:00 2001 From: nisha-bhatia Date: Thu, 4 Mar 2021 14:16:07 -0800 Subject: [PATCH 3/3] Update SubscriptionContainer.cs --- .../Azure.ResourceManager.Core/src/SubscriptionContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs index e34f6065b00f5..388fdfa3a4a8c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs @@ -71,7 +71,7 @@ public AsyncPageable ListAsync(CancellationToken cancellationToken /// The identifier of the resource. protected override void Validate(ResourceIdentifier identifier) { - if (identifier != null) + if (!(identifier is null)) throw new ArgumentException("Invalid parent for subscription container", nameof(identifier)); }