Skip to content

Update subscription client to 2021-01-01 #15351

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

Merged
merged 4 commits into from
Jul 1, 2021
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
22 changes: 11 additions & 11 deletions src/Accounts/Accounts.Test/AzureRMProfileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using Microsoft.Azure.Commands.Profile.Models;
using Microsoft.Azure.Commands.Profile.Test;
using Microsoft.Azure.Commands.ScenarioTest;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01.Models;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01.Models;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.Rest;
using Microsoft.Rest.Azure;
Expand Down Expand Up @@ -62,7 +62,7 @@ private static RMProfileClient SetupTestEnvironment(List<string> tenants, params
var clientFactory = new MockSubscriptionClientFactory(tenants, subscriptionList);
var mock = new MockClientFactory(new List<object>
{
clientFactory.GetSubscriptionClientVer2019(),
clientFactory.GetSubscriptionClientVerLatest(),
clientFactory.GetSubscriptionClientVer2016()
}, true);
mock.MoqClients = true;
Expand Down Expand Up @@ -90,7 +90,7 @@ private static AzureRmProfile SetupLogin(List<string> tenants, params List<strin
var clientFactory = new MockSubscriptionClientFactory(tenants, subscriptionList);
var mock = new MockClientFactory(new List<object>
{
clientFactory.GetSubscriptionClientVer2019(),
clientFactory.GetSubscriptionClientVerLatest(),
clientFactory.GetSubscriptionClientVer2016()
}, true);
mock.MoqClients = true;
Expand Down Expand Up @@ -144,7 +144,7 @@ public void SpecifyTenantAndSubscriptionIdSucceed()
null,
false,
null);
Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
}

[Fact]
Expand All @@ -164,8 +164,8 @@ public void SubscriptionIdNotExist()
TenantId = DefaultTenant.ToString()
};

MockSubscriptionClientFactory.SubGetQueueVer2019 = new Queue<Func<AzureOperationResponse<Subscription>>>();
MockSubscriptionClientFactory.SubGetQueueVer2019.Enqueue(() =>
MockSubscriptionClientFactory.SubGetQueueVerLatest = new Queue<Func<AzureOperationResponse<Subscription>>>();
MockSubscriptionClientFactory.SubGetQueueVerLatest.Enqueue(() =>
{
throw new CloudException("InvalidAuthenticationTokenTenant: The access token is from the wrong issuer");
});
Expand All @@ -179,7 +179,7 @@ public void SubscriptionIdNotExist()
null,
false,
null));
Assert.Equal("2019-06-01", client.SubscriptionAndTenantClient.ApiVersion);
Assert.Equal("2021-01-01", client.SubscriptionAndTenantClient.ApiVersion);
}

[Fact]
Expand Down Expand Up @@ -230,8 +230,8 @@ public void SubscriptionIdNotInFirstTenant()
TenantId = DefaultTenant.ToString()
};

MockSubscriptionClientFactory.SubGetQueueVer2019 = new Queue<Func<AzureOperationResponse<Subscription>>>();
MockSubscriptionClientFactory.SubGetQueueVer2019.Enqueue(() =>
MockSubscriptionClientFactory.SubGetQueueVerLatest = new Queue<Func<AzureOperationResponse<Subscription>>>();
MockSubscriptionClientFactory.SubGetQueueVerLatest.Enqueue(() =>
{
throw new CloudException("InvalidAuthenticationTokenTenant: The access token is from the wrong issuer");
});
Expand Down Expand Up @@ -266,8 +266,8 @@ public void SubscriptionNameNotInFirstTenant()
TenantId = DefaultTenant.ToString()
};

MockSubscriptionClientFactory.SubListQueueVer2019 = new Queue<Func<AzureOperationResponse<IPage<Subscription>>>>();
MockSubscriptionClientFactory.SubListQueueVer2019.Enqueue(() =>
MockSubscriptionClientFactory.SubListQueueVerLatest = new Queue<Func<AzureOperationResponse<IPage<Subscription>>>>();
MockSubscriptionClientFactory.SubListQueueVerLatest.Enqueue(() =>
{
var sub1 = new Subscription(
id: DefaultSubscription.ToString(),
Expand Down
54 changes: 30 additions & 24 deletions src/Accounts/Accounts.Test/AzureRMProfileTestsForMultitenant.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.ResourceManager.Version2019_06_01;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01.Models;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01.Models;
using Microsoft.Rest.Azure;
using Moq;
using System;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Management.ResourceManager.Version2019_06_01;
using Microsoft.Azure.Management.ResourceManager.Version2019_06_01.Models;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01;
using Microsoft.Azure.Management.ResourceManager.Version2021_01_01.Models;
using Microsoft.Rest.Azure;
using Moq;
using System;
Expand All @@ -29,24 +29,24 @@ namespace Microsoft.Azure.Commands.ResourceManager.Common.Test
{
public partial class MockSubscriptionClientFactory
{
public static Queue<Func<AzureOperationResponse<Subscription>>> SubGetQueueVer2019 { get; set; } = null;
public static Queue<Func<AzureOperationResponse<IPage<Subscription>>>> SubListQueueVer2019 { get; set; } = null;
public static Queue<Func<AzureOperationResponse<IPage<TenantIdDescription>>>> TenantListQueueVer2019 { get; set; } = null;
public static Queue<Func<AzureOperationResponse<Subscription>>> SubGetQueueVerLatest { get; set; } = null;
public static Queue<Func<AzureOperationResponse<IPage<Subscription>>>> SubListQueueVerLatest { get; set; } = null;
public static Queue<Func<AzureOperationResponse<IPage<TenantIdDescription>>>> TenantListQueueVerLatest { get; set; } = null;

public DeGetAsyncQueue<Subscription> GetSubQueueDequeueVer2019 = () => Task.FromResult(SubGetQueueVer2019.Dequeue().Invoke());
public DeListAsyncQueue<Subscription> ListSubQueueDequeueVer2019 = () => Task.FromResult(SubListQueueVer2019.Dequeue().Invoke());
public DeListAsyncQueue<TenantIdDescription> ListTenantQueueDequeueVer2019 = () => Task.FromResult(TenantListQueueVer2019.Dequeue().Invoke());
public DeGetAsyncQueue<Subscription> GetSubQueueDequeueVerLatest = () => Task.FromResult(SubGetQueueVerLatest.Dequeue().Invoke());
public DeListAsyncQueue<Subscription> ListSubQueueDequeueVerLatest = () => Task.FromResult(SubListQueueVerLatest.Dequeue().Invoke());
public DeListAsyncQueue<TenantIdDescription> ListTenantQueueDequeueVerLatest = () => Task.FromResult(TenantListQueueVerLatest.Dequeue().Invoke());

public SubscriptionClient GetSubscriptionClientVer2019()
public SubscriptionClient GetSubscriptionClientVerLatest()
{
var tenantMock = new Mock<ITenantsOperations>();
tenantMock.Setup(t => t.ListWithHttpMessagesAsync(It.IsAny<Dictionary<string, List<string>>>(), It.IsAny<CancellationToken>()))
.Returns(
(Dictionary<string, List<string>> ch, CancellationToken token) =>
{
if(TenantListQueueVer2019 != null && TenantListQueueVer2019.Any())
if(TenantListQueueVerLatest != null && TenantListQueueVerLatest.Any())
{
return ListTenantQueueDequeueVer2019();
return ListTenantQueueDequeueVerLatest();
}
var tenants = _tenants.Select((k) => new TenantIdDescription(id: k, tenantId: k));
var mockPage = new MockPage<TenantIdDescription>(tenants.ToList());
Expand All @@ -64,9 +64,9 @@ public SubscriptionClient GetSubscriptionClientVer2019()
s => s.GetWithHttpMessagesAsync(It.IsAny<string>(), It.IsAny<Dictionary<string, List<string>>>(), It.IsAny<CancellationToken>())).Returns(
(string subId, Dictionary<string, List<string>> ch, CancellationToken token) =>
{
if (SubGetQueueVer2019 != null && SubGetQueueVer2019.Any())
if (SubGetQueueVerLatest != null && SubGetQueueVerLatest.Any())
{
return GetSubQueueDequeueVer2019();
return GetSubQueueDequeueVerLatest();
}
AzureOperationResponse<Subscription> result = new AzureOperationResponse<Subscription>
{
Expand All @@ -91,9 +91,9 @@ public SubscriptionClient GetSubscriptionClientVer2019()
(s) => s.ListWithHttpMessagesAsync(null, It.IsAny<CancellationToken>())).Returns(
(Dictionary<string, List<string>> ch, CancellationToken token) =>
{
if (SubListQueueVer2019 != null && SubListQueueVer2019.Any())
if (SubListQueueVerLatest != null && SubListQueueVerLatest.Any())
{
return ListSubQueueDequeueVer2019();
return ListSubQueueDequeueVerLatest();
}

AzureOperationResponse<IPage<Subscription>> result = null;
Expand Down Expand Up @@ -160,9 +160,9 @@ private ITenantsOperations GetTenantMock(List<TenantIdDescription> tenants)
.Returns(
(Dictionary<string, List<string>> ch, CancellationToken token) =>
{
if (TenantListQueueVer2019 != null && TenantListQueueVer2019.Any())
if (TenantListQueueVerLatest != null && TenantListQueueVerLatest.Any())
{
return ListTenantQueueDequeueVer2019();
return ListTenantQueueDequeueVerLatest();
}
var mockPage = new MockPage<TenantIdDescription>(tenants);

Expand Down Expand Up @@ -190,9 +190,9 @@ private ISubscriptionsOperations GetSubscriptionMock(List<Subscription> subscrip
s => s.GetWithHttpMessagesAsync(It.IsAny<string>(), It.IsAny<Dictionary<string, List<string>>>(), It.IsAny<CancellationToken>())).Returns(
(string subId, Dictionary<string, List<string>> ch, CancellationToken token) =>
{
if (SubGetQueueVer2019 != null && SubGetQueueVer2019.Any())
if (SubGetQueueVerLatest != null && SubGetQueueVerLatest.Any())
{
return GetSubQueueDequeueVer2019();
return GetSubQueueDequeueVerLatest();
}
AzureOperationResponse<Subscription> result = new AzureOperationResponse<Subscription>()
{
Expand All @@ -210,9 +210,9 @@ private ISubscriptionsOperations GetSubscriptionMock(List<Subscription> subscrip
(s) => s.ListWithHttpMessagesAsync(null, It.IsAny<CancellationToken>())).Returns(
(Dictionary<string, List<string>> ch, CancellationToken token) =>
{
if (SubListQueueVer2019 != null && SubListQueueVer2019.Any())
if (SubListQueueVerLatest != null && SubListQueueVerLatest.Any())
{
return ListSubQueueDequeueVer2019();
return ListSubQueueDequeueVerLatest();
}

AzureOperationResponse<IPage<Subscription>> result = null;
Expand Down Expand Up @@ -249,7 +249,7 @@ private ISubscriptionsOperations GetSubscriptionMock(List<Subscription> subscrip
return subscriptionMock.Object;
}

public SubscriptionClient GetSubscriptionClientVer2019(List<TenantIdDescription> tenants, List<Subscription> subscriptionGetList, List<List<Subscription>> subscriptionListLists, List<bool> HasNextPage = null)
public SubscriptionClient GetSubscriptionClientVerLatest(List<TenantIdDescription> tenants, List<Subscription> subscriptionGetList, List<List<Subscription>> subscriptionListLists, List<bool> HasNextPage = null)
{
var client = new Mock<SubscriptionClient>() { CallBase = true };
if (subscriptionGetList != null || subscriptionListLists != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"Entries": [
{
"RequestUri": "/tenants?api-version=2021-01-01",
"EncodedRequestUri": "L3RlbmFudHM/YXBpLXZlcnNpb249MjAyMS0wMS0wMQ==",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"27447c0a-62f3-4ec5-a2ee-46d57196a6c5"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.30015.01",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.19043.",
"Microsoft.Azure.Management.ResourceManager.Version2021.01.01.SubscriptionClient/1.0.0.0"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"x-ms-ratelimit-remaining-tenant-reads": [
"11999"
],
"x-ms-request-id": [
"aa195b95-77d4-41fe-81ae-041fde762974"
],
"x-ms-correlation-request-id": [
"aa195b95-77d4-41fe-81ae-041fde762974"
],
"x-ms-routing-request-id": [
"SOUTHEASTASIA:20210628T075523Z:aa195b95-77d4-41fe-81ae-041fde762974"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Mon, 28 Jun 2021 07:55:23 GMT"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Content-Length": [
"140"
]
},
"ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"id\": \"/tenants/54826b22-38d6-4fb2-bad9-b7b93a3e9c5a\",\r\n \"tenantId\": \"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a\",\r\n \"tenantCategory\": \"Home\"\r\n }\r\n ]\r\n}",
"StatusCode": 200
},
{
"RequestUri": "/subscriptions?api-version=2021-01-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnM/YXBpLXZlcnNpb249MjAyMS0wMS0wMQ==",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"27447c0a-62f3-4ec5-a2ee-46d57196a6c5"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.30015.01",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.19043.",
"Microsoft.Azure.Management.ResourceManager.Version2021.01.01.SubscriptionClient/1.0.0.0"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"x-ms-ratelimit-remaining-tenant-reads": [
"11999"
],
"x-ms-request-id": [
"c8cf462f-f2c0-4ef4-8dc3-aee3d36d3293"
],
"x-ms-correlation-request-id": [
"c8cf462f-f2c0-4ef4-8dc3-aee3d36d3293"
],
"x-ms-routing-request-id": [
"SOUTHEASTASIA:20210628T075524Z:c8cf462f-f2c0-4ef4-8dc3-aee3d36d3293"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Mon, 28 Jun 2021 07:55:23 GMT"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Content-Length": [
"522"
]
},
"ResponseBody": "{\r\n \"value\": [\r\n {\r\n \"id\": \"/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590\",\r\n \"authorizationSource\": \"RoleBased\",\r\n \"managedByTenants\": [\r\n {\r\n \"tenantId\": \"2f4a9838-26b7-47ee-be60-ccc1fdec5953\"\r\n }\r\n ],\r\n \"tags\": {\r\n \"testTags\": \"testValue\"\r\n },\r\n \"subscriptionId\": \"0b1f6471-1bf0-4dda-aec3-cb9272f09590\",\r\n \"tenantId\": \"54826b22-38d6-4fb2-bad9-b7b93a3e9c5a\",\r\n \"displayName\": \"AzureSDKTest\",\r\n \"state\": \"Enabled\",\r\n \"subscriptionPolicies\": {\r\n \"locationPlacementId\": \"Internal_2014-09-01\",\r\n \"quotaId\": \"Internal_2014-09-01\",\r\n \"spendingLimit\": \"Off\"\r\n }\r\n }\r\n ],\r\n \"count\": {\r\n \"type\": \"Total\",\r\n \"value\": 1\r\n }\r\n}",
"StatusCode": 200
}
],
"Names": {},
"Variables": {
"SubscriptionId": "0b1f6471-1bf0-4dda-aec3-cb9272f09590"
}
}
Loading