Skip to content
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

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class ResourceListOperations
/// <param name="top"> The number of results to return. </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 collection of resource operations that may take multiple service requests to iterate over. </returns>
public static Pageable<GenericResource> ListAtContext(
public static Pageable<GenericResourceExpanded> ListAtContext(
ResourceGroupOperations resourceGroup,
ResourceFilterCollection resourceFilters = null,
int? top = null,
Expand All @@ -40,7 +40,7 @@ public static Pageable<GenericResource> ListAtContext(
/// <param name="top"> The number of results to return. </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>An async collection of resource operations that may take multiple service requests to iterate over. </returns>
public static AsyncPageable<GenericResource> ListAtContextAsync(
public static AsyncPageable<GenericResourceExpanded> ListAtContextAsync(
ResourceGroupOperations resourceGroup,
ResourceFilterCollection resourceFilters = null,
int? top = null,
Expand All @@ -62,7 +62,7 @@ public static AsyncPageable<GenericResource> ListAtContextAsync(
/// <param name="top"> The number of results to return. </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 collection of resource operations that may take multiple service requests to iterate over. </returns>
public static Pageable<GenericResource> ListAtContext(
public static Pageable<GenericResourceExpanded> ListAtContext(
SubscriptionOperations subscription,
ResourceFilterCollection resourceFilters = null,
int? top = null,
Expand All @@ -84,7 +84,7 @@ public static Pageable<GenericResource> ListAtContext(
/// <param name="top"> The number of results to return. </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> An async collection of resource operations that may take multiple service requests to iterate over. </returns>
public static AsyncPageable<GenericResource> ListAtContextAsync(
public static AsyncPageable<GenericResourceExpanded> ListAtContextAsync(
SubscriptionOperations subscription,
ResourceFilterCollection resourceFilters = null,
int? top = null,
Expand All @@ -104,49 +104,51 @@ private static GenericResourceContainer GetGenericResourceContainer(ResourceOper
return new GenericResourceContainer(new ClientContext(resourceOperations.ClientOptions, resourceOperations.Credential, resourceOperations.BaseUri, resourceOperations.Pipeline), subscription);
}

private static AsyncPageable<GenericResource> ListAtContextInternalAsync(
private static AsyncPageable<GenericResourceExpanded> ListAtContextInternalAsync(
ResourceOperationsBase resourceOperations,
string scopeFilter,
ResourceFilterCollection resourceFilters = null,
int? top = null,
CancellationToken cancellationToken = default)
{
var restClient = GetGenericResourceContainer(resourceOperations);
AsyncPageable<GenericResource> result;
AsyncPageable<GenericResourceExpanded> result;
if (scopeFilter == null)
{
result = restClient.ListAsync(resourceFilters?.ToString(), top, cancellationToken);
result = restClient.ListAsync(resourceFilters?.ToString(), null, top, cancellationToken);
}
else
{
result = restClient.ListByResourceGroupAsync(
scopeFilter,
resourceFilters?.ToString(),
null,
top,
cancellationToken);
}

return result;
}

private static Pageable<GenericResource> ListAtContextInternal(
private static Pageable<GenericResourceExpanded> ListAtContextInternal(
ResourceOperationsBase resourceOperations,
string scopeFilter = null,
ResourceFilterCollection resourceFilters = null,
int? top = null,
CancellationToken cancellationToken = default)
{
var restClient = GetGenericResourceContainer(resourceOperations);
Pageable<GenericResource> result;
Pageable<GenericResourceExpanded> result;
if (scopeFilter == null)
{
result = restClient.List(resourceFilters?.ToString(), top, cancellationToken);
result = restClient.List(resourceFilters?.ToString(), null, top, cancellationToken);
}
else
{
result = restClient.ListByResourceGroup(
scopeFilter,
resourceFilters?.ToString(),
null,
top,
cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Azure.Core.TestFramework;
using Azure.ResourceManager.Core.Extensions;
using NUnit.Framework;

namespace Azure.ResourceManager.Core.Tests
{
[Parallelizable]
public class GenericResourceExpandedOperationsTests : ResourceManagerTestBase
{
private const string GenericResourceExpandString = "createdTime,changedTime,provisioningState";

public GenericResourceExpandedOperationsTests(bool isAsync)
: base(isAsync)//, RecordedTestMode.Record)
{
}

[TestCase]
[RecordedTest]
public async Task Delete()
{
ResourceGroup rg = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
var aset = await CreateGenericAvailabilitySetAsync(rg.Id);

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
Assert.DoesNotThrowAsync(async () => await resExp.DeleteAsync());
}

[TestCase]
[RecordedTest]
public async Task StartDelete()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var createOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await createOp.WaitForCompletionAsync();

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
Assert.DoesNotThrowAsync(async () =>
{
var deleteOp = await resExp.StartDeleteAsync();
_ = await deleteOp.WaitForCompletionResponseAsync();
});
}

[TestCase]
[RecordedTest]
public async Task AddTag()
{
ResourceGroup rg = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
var aset = await CreateGenericAvailabilitySetAsync(rg.Id);

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
Assert.AreEqual(0, resExp.Data.Tags.Count);
aset = await resExp.AddTagAsync("key", "value");

Assert.IsTrue(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual("value", aset.Data.Tags["key"]);
}

[TestCase]
[RecordedTest]
public async Task StartAddTag()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var createOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await createOp.WaitForCompletionAsync();

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
Assert.AreEqual(0, resExp.Data.Tags.Count);
var addTagOp = await resExp.StartAddTagAsync("key", "value");
aset = await addTagOp.WaitForCompletionAsync();

Assert.IsTrue(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual("value", aset.Data.Tags["key"]);
}

[TestCase]
[RecordedTest]
public async Task SetTags()
{
ResourceGroup rg = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
var aset = await CreateGenericAvailabilitySetAsync(rg.Id);

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
Assert.AreEqual(0, resExp.Data.Tags.Count);

Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("key", "value");
aset = await resExp.SetTagsAsync(tags);

Assert.IsTrue(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual("value", aset.Data.Tags["key"]);
}

[TestCase]
[RecordedTest]
public async Task StartSetTags()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var createOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await createOp.WaitForCompletionAsync();

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("key", "value");
var setTagsOp = await resExp.StartSetTagsAsync(tags);
aset = await setTagsOp.WaitForCompletionAsync();

Assert.IsTrue(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual("value", aset.Data.Tags["key"]);
}

[TestCase]
[RecordedTest]
public async Task RemoveTag()
{
ResourceGroup rg = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
var aset = await CreateGenericAvailabilitySetAsync(rg.Id);

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("key", "value");
_ = await resExp.SetTagsAsync(tags);

aset = await resExp.RemoveTagAsync("key");

Assert.IsFalse(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual(0, aset.Data.Tags.Count);
}

[TestCase]
[RecordedTest]
public async Task StartRemoveTag()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var crateOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await crateOp.WaitForCompletionAsync();

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
Dictionary<string, string> tags = new Dictionary<string, string>();
tags.Add("key", "value");
var setTagsOp = await resExp.StartSetTagsAsync(tags);
_ = await setTagsOp.WaitForCompletionAsync();

var removeTagOp = await resExp.StartRemoveTagAsync("key");
aset = await removeTagOp.WaitForCompletionAsync();

Assert.IsFalse(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual(0, aset.Data.Tags.Count);
}

[TestCase]
[RecordedTest]
public async Task Update()
{
ResourceGroup rg = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).CreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
var aset = await CreateGenericAvailabilitySetAsync(rg.Id);

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
var data = ConstructGenericAvailabilitySet();
data.Tags.Add("key", "value");
aset = await resExp.UpdateAsync(data);

Assert.IsTrue(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual("value", aset.Data.Tags["key"]);

Assert.ThrowsAsync<ArgumentNullException>(async () => _ = await resExp.UpdateAsync(null));
}

[TestCase]
[RecordedTest]
public async Task StartUpdate()
{
var rgOp = await Client.DefaultSubscription.GetResourceGroups().Construct(LocationData.WestUS2).StartCreateOrUpdateAsync(Recording.GenerateAssetName("testrg"));
ResourceGroup rg = await rgOp.WaitForCompletionAsync();
var createOp = await StartCreateGenericAvailabilitySetAsync(rg.Id);
GenericResource aset = await createOp.WaitForCompletionAsync();

var resExp = await GetGenericResourceExpandedAsync(aset.Id, null, GenericResourceExpandString);
var data = ConstructGenericAvailabilitySet();
data.Tags.Add("key", "value");
var updateOp = await resExp.StartUpdateAsync(data);
aset = await updateOp.WaitForCompletionAsync();

Assert.IsTrue(aset.Data.Tags.ContainsKey("key"));
Assert.AreEqual("value", aset.Data.Tags["key"]);

Assert.ThrowsAsync<ArgumentNullException>(async () =>
{
var updateOp = await resExp.StartUpdateAsync(null);
_ = await updateOp.WaitForCompletionAsync();
});
}

private async Task<GenericResourceExpanded> GetGenericResourceExpandedAsync(
ResourceIdentifier resourceId,
string filter = default,
string expand = default)
{
var resExp = await (Client.DefaultSubscription.GetGenericResources()
.ListAsync(filter, expand)
.FirstOrDefaultAsync(r => r.Id.Equals(resourceId)));

Assert.NotNull(resExp);
Assert.NotNull(resExp.Data.CreatedTime);
Assert.NotNull(resExp.Data.ChangedTime);
Assert.IsFalse(string.IsNullOrWhiteSpace(resExp.Data.ProvisioningState));

return resExp;
}
}
}
Loading