Skip to content

Remove -all parameter from Get-AzureRMSubscription and Set-AzureRMContext #1194

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 5 commits into from
Oct 29, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
<Compile Include="Generated\TagOperationsExtensions.cs" />
<Compile Include="Generated\TenantOperations.cs" />
<Compile Include="Generated\TenantOperationsExtensions.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
//
// To add a suppression to this file, right-click the message in the
// Code Analysis results, point to "Suppress Message", and click
// "In Suppression File".
// You do not need to add suppressions to this file manually.

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "type", Target = "Microsoft.Azure.Management.Internal.Resources.AuthorizationClient")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "type", Target = "Microsoft.Azure.Management.Internal.Resources.FeatureClient")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "type", Target = "Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly", Scope = "type", Target = "Microsoft.Azure.Internal.Subscriptions.SubscriptionClient")]
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ private static RMProfileClient SetupTestEnvironment(List<string> tenants, params
mock.MoqClients = true;
AzureSession.ClientFactory = mock;
var context = new AzureContext(new AzureSubscription()
{
Account = DefaultAccount,
Environment = EnvironmentName.AzureCloud,
Id = DefaultSubscription,
Name = DefaultSubscriptionName
},
{
Account = DefaultAccount,
Environment = EnvironmentName.AzureCloud,
Id = DefaultSubscription,
Name = DefaultSubscriptionName
},
new AzureAccount() { Id = DefaultAccount, Type = AzureAccount.AccountType.User },
AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud],
new AzureTenant() { Domain = DefaultDomain, Id = DefaultTenant });
Expand All @@ -65,17 +65,24 @@ private static RMProfileClient SetupTestEnvironment(List<string> tenants, params
public void MultipleTenantsAndSubscriptionsSucceed()
{
var tenants = new List<string> {Guid.NewGuid().ToString(), DefaultTenant.ToString()};
var firstList = new List<string> { DefaultSubscription.ToString(), Guid.NewGuid().ToString() };
var secondsubscriptionInTheFirstTenant = Guid.NewGuid().ToString();
var firstList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant};
var secondList = new List<string> { Guid.NewGuid().ToString()};
var client = SetupTestEnvironment(tenants, firstList, secondList);
var thirdList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
var fourthList = new List<string> { DefaultSubscription.ToString(), secondsubscriptionInTheFirstTenant };
var client = SetupTestEnvironment(tenants, firstList, secondList, thirdList, fourthList);
var subResults = new List<AzureSubscription>(client.ListSubscriptions());
Assert.Equal(3, subResults.Count);
var tenantResults = client.ListTenants();
Assert.Equal(2, tenantResults.Count());
tenantResults = client.ListTenants(DefaultTenant.ToString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also cover GetSUbscriptionByName in this test method, or add another unit test for this?

Assert.Equal(1, tenantResults.Count());
AzureSubscription subValue;
Assert.True(client.TryGetSubscription(DefaultTenant.ToString(), DefaultSubscription.ToString(), out subValue));
Assert.True(client.TryGetSubscriptionById(DefaultTenant.ToString(), DefaultSubscription.ToString(), out subValue));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Assert.Equal(DefaultSubscription.ToString(), subValue.Id.ToString());
Assert.True(client.TryGetSubscriptionByName(DefaultTenant.ToString(),
MockSubscriptionClientFactory.GetSubscriptionNameFromId(DefaultSubscription.ToString()),
out subValue));
Assert.Equal(DefaultSubscription.ToString(), subValue.Id.ToString());
}

Expand All @@ -84,16 +91,22 @@ public void MultipleTenantsAndSubscriptionsSucceed()
public void SingleTenantAndSubscriptionSucceeds()
{
var tenants = new List<string> {DefaultTenant.ToString()};
var subscriptions = new List<string> {DefaultSubscription.ToString()};
var client = SetupTestEnvironment(tenants, subscriptions);
var firstList = new List<string> {DefaultSubscription.ToString()};
var secondList = firstList;
var thirdList = firstList;
var client = SetupTestEnvironment(tenants, firstList, secondList, thirdList);
var subResults = new List<AzureSubscription>(client.ListSubscriptions());
Assert.Equal(1, subResults.Count);
var tenantResults = client.ListTenants();
Assert.Equal(1, tenantResults.Count());
tenantResults = client.ListTenants(DefaultTenant.ToString());
Assert.Equal(1, tenantResults.Count());
AzureSubscription subValue;
Assert.True(client.TryGetSubscription(DefaultTenant.ToString(), DefaultSubscription.ToString(), out subValue));
Assert.True(client.TryGetSubscriptionById(DefaultTenant.ToString(), DefaultSubscription.ToString(), out subValue));
Assert.Equal(DefaultSubscription.ToString(), subValue.Id.ToString());
Assert.True(client.TryGetSubscriptionByName(DefaultTenant.ToString(),
MockSubscriptionClientFactory.GetSubscriptionNameFromId(DefaultSubscription.ToString()),
out subValue));
Assert.Equal(DefaultSubscription.ToString(), subValue.Id.ToString());
}

Expand All @@ -102,12 +115,15 @@ public void SingleTenantAndSubscriptionSucceeds()
public void SubscriptionNotFoundDoesNotThrow()
{
var tenants = new List<string> { DefaultTenant.ToString() };
var subscriptions = new List<string> { Guid.NewGuid().ToString() };
var client = SetupTestEnvironment(tenants, subscriptions);
string randomSubscriptionId = Guid.NewGuid().ToString();
var firstList = new List<string> { randomSubscriptionId };
var secondList = firstList;
var client = SetupTestEnvironment(tenants, firstList, secondList);
var subResults = new List<AzureSubscription>(client.ListSubscriptions());
Assert.Equal(1, subResults.Count);
AzureSubscription subValue;
Assert.True(client.TryGetSubscription(DefaultTenant.ToString(), DefaultSubscription.ToString(), out subValue));
Assert.False(client.TryGetSubscriptionById(DefaultTenant.ToString(), DefaultSubscription.ToString(), out subValue));
Assert.False(client.TryGetSubscriptionByName("random-tenant", "random-subscription", out subValue));
}

[Fact]
Expand All @@ -127,10 +143,11 @@ public void NoSubscriptionsInListDoesNotThrow()
{
var tenants = new List<string> { DefaultTenant.ToString() };
var subscriptions = new List<string> () ;
var client = SetupTestEnvironment(tenants, subscriptions);
var client = SetupTestEnvironment(tenants, subscriptions, subscriptions);
Assert.Equal(0, client.ListSubscriptions().Count());
AzureSubscription subValue;
Assert.True(client.TryGetSubscription(DefaultTenant.ToString(), DefaultSubscription.ToString(), out subValue));
Assert.False(client.TryGetSubscriptionById(DefaultTenant.ToString(), DefaultSubscription.ToString(), out subValue));
Assert.False(client.TryGetSubscriptionByName(DefaultTenant.ToString(), "random-name", out subValue));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public MockSubscriptionClientFactory(List<string> tenants, Queue<List<string>> s
}
}

public static string GetSubscriptionNameFromId(string id)
{
return "Sub-" + id;
}

public SubscriptionClient GetSubscriptionClient()
{
var tenantMock = new Mock<ITenantOperations>();
Expand Down Expand Up @@ -72,7 +77,7 @@ public SubscriptionClient GetSubscriptionClient()
result.Subscription =
new Subscription
{
DisplayName = "Returned Subscription",
DisplayName = GetSubscriptionNameFromId(subId),
Id = subId,
State = "Active",
SubscriptionId = subId
Expand Down Expand Up @@ -100,7 +105,7 @@ public SubscriptionClient GetSubscriptionClient()
sub =>
new Subscription
{
DisplayName = "Contoso Subscription",
DisplayName = GetSubscriptionNameFromId(sub),
Id = sub,
State = "Active",
SubscriptionId = sub
Expand Down
Loading