-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Add PSAzureSubscriptionPolicy for PSAzureSubScription. #12569
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
isra-fel
merged 6 commits into
Azure:master
from
BethanyZhou:bez/exposeSubscriptionPolicies
Aug 7, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
070f422
Add PSAzureSubscriptionPolicy for PSAzureSubScription.
BethanyZhou 98f37d3
Update ChangeLog.md
BethanyZhou c1b112d
Issue fix
BethanyZhou 4b865cc
Change constructor of PSAzureSubscriptionPolicy
BethanyZhou e6dc153
remove localfeed and and test cases
BethanyZhou 719a396
Update Common.Netcore.Dependencies.targets
BethanyZhou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
378 changes: 129 additions & 249 deletions
378
...icrosoft.Azure.Commands.Profile.Test.SubscriptionCmdletTests/AllParameterSetsSucceed.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Accounts/Accounts.Test/UnitTest/PSAzureSubscriptionTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| using Microsoft.Azure.Commands.Common.Authentication.Abstractions; | ||
| using Microsoft.Azure.Commands.Profile.Models; | ||
| using Microsoft.Azure.Internal.Subscriptions.Models; | ||
| using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
| using Newtonsoft.Json; | ||
| using System; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Azure.Commands.Profile.Test.UnitTest | ||
| { | ||
| public class PSAzureSubscriptionTest | ||
| { | ||
|
|
||
| [Fact] | ||
| [Trait(Category.AcceptanceType, Category.CheckIn)] | ||
| public void NewPSAzureSubscription() | ||
| { | ||
| string locationPlacementId = "Internal_2014-09-01"; | ||
| string quotaId= "Internal_2014-09-01"; | ||
| SpendingLimit spendingLimit = SpendingLimit.Off; | ||
| var subscriptionPolicies = new SubscriptionPolicies(locationPlacementId, quotaId, spendingLimit); | ||
|
|
||
| // test PSAzureSubscriptionPolicies' constructors | ||
| var psAzureSubscriptionPolicies = new PSAzureSubscriptionPolicy(subscriptionPolicies); | ||
| Assert.Equal(psAzureSubscriptionPolicies.LocationPlacementId, locationPlacementId); | ||
| Assert.Equal(psAzureSubscriptionPolicies.QuotaId, quotaId); | ||
| Assert.Equal(psAzureSubscriptionPolicies.SpendingLimit, spendingLimit.ToString()); | ||
|
|
||
| var psAzureSubscriptionPolicies2 = new PSAzureSubscriptionPolicy(JsonConvert.SerializeObject(subscriptionPolicies)); | ||
| Assert.Equal(psAzureSubscriptionPolicies2.LocationPlacementId, locationPlacementId); | ||
| Assert.Equal(psAzureSubscriptionPolicies2.QuotaId, quotaId); | ||
| Assert.Equal(psAzureSubscriptionPolicies2.SpendingLimit, spendingLimit.ToString()); | ||
|
|
||
| var sub = new AzureSubscription | ||
| { | ||
| Id = new Guid().ToString(), | ||
| Name = "Contoso Test Subscription", | ||
| State = "Enabled", | ||
| }; | ||
| sub.SetAccount("me@contoso.com"); | ||
| sub.SetEnvironment("testCloud"); | ||
| sub.SetTenant(new Guid("3c0ff8a7-e8bb-40e8-ae66-271343379af6").ToString()); | ||
| sub.SetSubscriptionPolicies(JsonConvert.SerializeObject(subscriptionPolicies)); | ||
|
|
||
| // test PSAzureSubscription's constructor | ||
| var psAzureSubscription = new PSAzureSubscription(sub); | ||
| Assert.NotNull(psAzureSubscription.SubscriptionPolicies); | ||
| Assert.Equal(psAzureSubscription.SubscriptionPolicies.LocationPlacementId, locationPlacementId); | ||
| Assert.Equal(psAzureSubscription.SubscriptionPolicies.QuotaId, quotaId); | ||
| Assert.Equal(psAzureSubscription.SubscriptionPolicies.SpendingLimit, spendingLimit.ToString()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/Accounts/Authentication.ResourceManager/Models/PSAzureSubscriptionPolicy.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using Newtonsoft.Json; | ||
| using Microsoft.Azure.Internal.Subscriptions.Models; | ||
|
|
||
| namespace Microsoft.Azure.Commands.Profile.Models | ||
| { | ||
| public class PSAzureSubscriptionPolicy | ||
| { | ||
| /// <summary> | ||
| /// Default constructor | ||
| /// </summary> | ||
| public PSAzureSubscriptionPolicy() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| /// <summary> | ||
| /// object constructor | ||
| /// </summary> | ||
| /// <param name="azureSubscriptionPolicies">Json string to convert</param> | ||
| public PSAzureSubscriptionPolicy(SubscriptionPolicies subscriptionPolicies) | ||
| { | ||
| if (subscriptionPolicies != null) | ||
| { | ||
| this.LocationPlacementId = subscriptionPolicies.LocationPlacementId; | ||
| this.QuotaId = subscriptionPolicies.QuotaId; | ||
| this.SpendingLimit = subscriptionPolicies.SpendingLimit.ToString(); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// string constructor | ||
| /// </summary> | ||
| /// <param name="azureSubscriptionPolicies">Json string to convert</param> | ||
| public PSAzureSubscriptionPolicy(string azureSubscriptionPolicies) : this(string.IsNullOrEmpty(azureSubscriptionPolicies)?null:JsonConvert.DeserializeObject<SubscriptionPolicies>(azureSubscriptionPolicies)) { } | ||
|
|
||
| public string LocationPlacementId { get; private set; } | ||
|
|
||
| public string QuotaId { get; private set; } | ||
|
|
||
| public string SpendingLimit { get; private set; } | ||
|
|
||
| public override string ToString() | ||
| { | ||
| return JsonConvert.SerializeObject(this, Formatting.Indented, | ||
| new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.