Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nibhati - 5142 - add tests for ArmBuilder.cs #19231

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ public TResource Build()
/// </summary>
/// <param name="name"> The name of the new resource to create. </param>
/// <returns> A response with the <see cref="ArmResponse{TOperations}"/> operation for this resource. </returns>
/// <exception cref="ArgumentException"> Name cannot be null or a whitespace. </exception>
public ArmResponse<TOperations> CreateOrUpdate(string name)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("Name cannot be null or whitespace.", nameof(name));

ResourceName = name;
Resource = Build();

Expand All @@ -75,10 +79,14 @@ public ArmResponse<TOperations> CreateOrUpdate(string name)
/// <param name="name"> The name of the new resource to create. </param>
/// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service. The default value is <see cref="CancellationToken.None" />. </param>
/// <returns> A <see cref="Task"/> that on completion returns a response with the <see cref="ArmResponse{TOperations}"/> operation for this resource. </returns>
/// <exception cref="ArgumentException"> Name cannot be null or a whitespace. </exception>
public async Task<ArmResponse<TOperations>> 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();

Expand All @@ -94,8 +102,12 @@ public async Task<ArmResponse<TOperations>> CreateOrUpdateAsync(
/// <remarks>
/// <see href="https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-longrunning">Details on long running operation object.</see>
/// </remarks>
/// <exception cref="ArgumentException"> Name cannot be null or a whitespace. </exception>
public ArmOperation<TOperations> 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();

Expand All @@ -111,10 +123,14 @@ public ArmOperation<TOperations> StartCreateOrUpdate(string name, CancellationTo
/// <remarks>
/// <see href="https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-longrunning">Details on long running operation object.</see>
/// </remarks>
/// <exception cref="ArgumentException"> Name cannot be null or a whitespace. </exception>
public async Task<ArmOperation<TOperations>> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public AsyncPageable<Subscription> ListAsync(CancellationToken cancellationToken
/// <param name="identifier"> The identifier of the resource. </param>
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));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ArgumentException>(delegate { armClient.DefaultSubscription.GetResourceGroupContainer().Construct(LocationData.WestUS2).CreateOrUpdate(value); });
}

[TestCase(null)]
[TestCase(" ")]
public void TestCreateOrUpdateAsync(string value)
{
var armClient = new AzureResourceManagerClient();
Assert.ThrowsAsync<ArgumentException>(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<ArgumentException>(delegate { armClient.DefaultSubscription.GetResourceGroupContainer().Construct(LocationData.WestUS2).StartCreateOrUpdate(value); });
}

[TestCase(null)]
[TestCase(" ")]
public void TestStartCreateOrUpdateAsync(string value)
{
var armClient = new AzureResourceManagerClient();
Assert.ThrowsAsync<ArgumentException>(async delegate { await armClient.DefaultSubscription.GetResourceGroupContainer().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(value); });
}
}
}