Skip to content

Commit 4bb1d37

Browse files
authored
Merge pull request #5790 from wilcobmsft/wilcob/enrollmentAccounts
[Billing RP] Get-AzureRmEnrollmentAccount
2 parents 75708aa + b41dd04 commit 4bb1d37

29 files changed

+2460
-246
lines changed

src/ResourceManager/Billing/AzureRM.Billing.Netcore.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ NestedModules = @('.\Microsoft.Azure.Commands.Billing.dll')
7272
FunctionsToExport = @()
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
75-
CmdletsToExport = 'Get-AzureRmBillingInvoice', 'Get-AzureRmBillingPeriod'
75+
CmdletsToExport = 'Get-AzureRmBillingInvoice', 'Get-AzureRmBillingPeriod', 'Get-AzureRmEnrollmentAccount'
7676

7777
# Variables to export from this module
7878
# VariablesToExport = @()

src/ResourceManager/Billing/AzureRM.Billing.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ NestedModules = @('.\Microsoft.Azure.Commands.Billing.dll')
7272
FunctionsToExport = @()
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
75-
CmdletsToExport = 'Get-AzureRmBillingInvoice', 'Get-AzureRmBillingPeriod'
75+
CmdletsToExport = 'Get-AzureRmBillingInvoice', 'Get-AzureRmBillingPeriod', 'Get-AzureRmEnrollmentAccount'
7676

7777
# Variables to export from this module
7878
# VariablesToExport = @()

src/ResourceManager/Billing/ChangeLog.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* New Cmdlet Get-AzureRmEnrollmentAccount
22+
- cmdlet to retrieve enrollment accounts
2123
* Updated to the latest version of the Azure ClientRuntime
2224

2325
## Version 0.14.0
@@ -44,8 +46,8 @@
4446
* New Cmdlet Get-AzureRmBillingPeriod
4547
- cmdlet to retrieve azure billing periods of the subscription.
4648
* Update Cmdlet Get-AzureRmBillingInvoice
47-
- new property BillingPeriodNames
48-
- output in list view
49+
- new property BillingPeriodNames
50+
- output in list view
4951

5052
## Version 0.11.0
5153

src/ResourceManager/Billing/Commands.Billing.Test/Commands.Billing.Test.csproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<Private>True</Private>
6464
</Reference>
6565
<Reference Include="Microsoft.Azure.Management.Billing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Billing.2.0.0-preview\lib\net452\Microsoft.Azure.Management.Billing.dll</HintPath>
66+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Billing.2.1.0-preview\lib\net452\Microsoft.Azure.Management.Billing.dll</HintPath>
6767
</Reference>
6868
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
6969
<SpecificVersion>False</SpecificVersion>
@@ -86,12 +86,12 @@
8686
</Reference>
8787
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
8888
<SpecificVersion>False</SpecificVersion>
89-
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.2.9-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
89+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.3.1\lib\net452\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
9090
<Private>True</Private>
9191
</Reference>
92-
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework, Version=1.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
92+
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
9393
<SpecificVersion>False</SpecificVersion>
94-
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.TestFramework.1.5.1-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.TestFramework.dll</HintPath>
94+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.TestFramework.1.7.2\lib\net452\Microsoft.Rest.ClientRuntime.Azure.TestFramework.dll</HintPath>
9595
<Private>True</Private>
9696
</Reference>
9797
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
@@ -131,13 +131,17 @@
131131
</ItemGroup>
132132
<ItemGroup>
133133
<Compile Include="Properties\AssemblyInfo.cs" />
134+
<Compile Include="ScenarioTests\EnrollmentAccountTests.cs" />
134135
<Compile Include="ScenarioTests\BillingPeriodsTests.cs" />
135136
<Compile Include="ScenarioTests\InvoicesTests.cs" />
136137
<Compile Include="ScenarioTests\TestController.cs" />
137138
</ItemGroup>
138139
<ItemGroup>
139140
<None Include="MSSharedLibKey.snk" />
140141
<None Include="packages.config" />
142+
<None Include="ScenarioTests\EnrollmentAccountTests.ps1">
143+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
144+
</None>
141145
<None Include="ScenarioTests\BillingPeriodsTests.ps1">
142146
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
143147
</None>
@@ -174,6 +178,12 @@
174178
<None Include="SessionRecords\Microsoft.Azure.Commands.Billing.Test.ScenarioTests.InvoicesTests\TestListInvoicesWithMaxCount.json">
175179
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
176180
</None>
181+
<None Include="SessionRecords\Microsoft.Azure.Commands.Billing.Test.ScenarioTests.EnrollmentAccountTests\TestGetEnrollmentAccountWithName.json">
182+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
183+
</None>
184+
<None Include="SessionRecords\Microsoft.Azure.Commands.Billing.Test.ScenarioTests.EnrollmentAccountTests\TestListEnrollmentAccounts.json">
185+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
186+
</None>
177187
</ItemGroup>
178188
<ItemGroup>
179189
<ProjectReference Include="..\..\..\Common\Commands.Common.Authentication.Abstractions\Commands.Common.Authentication.Abstractions.csproj">

src/ResourceManager/Billing/Commands.Billing.Test/ScenarioTests/BillingPeriodsTests.ps1

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ List billing periods
1818
#>
1919
function Test-ListBillingPeriods
2020
{
21-
$billingBillingPeriods = Get-AzureRmBillingPeriod
21+
$billingPeriods = Get-AzureRmBillingPeriod
2222

23-
Assert-True {$billingBillingPeriods.Count -ge 1}
24-
Assert-NotNull $billingBillingPeriods[0].Name
25-
Assert-NotNull $billingBillingPeriods[0].Id
26-
Assert-NotNull $billingBillingPeriods[0].Type
27-
Assert-NotNull $billingBillingPeriods[0].BillingPeriodStartDate
28-
Assert-NotNull $billingBillingPeriods[0].BillingPeriodEndDate
23+
Assert-True {$billingPeriods.Count -ge 1}
24+
Assert-NotNull $billingPeriods[0].Name
25+
Assert-NotNull $billingPeriods[0].Id
26+
Assert-NotNull $billingPeriods[0].Type
27+
Assert-NotNull $billingPeriods[0].BillingPeriodStartDate
28+
Assert-NotNull $billingPeriods[0].BillingPeriodEndDate
2929
}
3030

3131
<#
@@ -34,14 +34,14 @@ List billing periods with MaxCount
3434
#>
3535
function Test-ListBillingPeriodsWithMaxCount
3636
{
37-
$billingBillingPeriods = Get-AzureRmBillingPeriod -MaxCount 1
37+
$billingPeriods = Get-AzureRmBillingPeriod -MaxCount 1
3838

39-
Assert-True {$billingBillingPeriods.Count -eq 1}
40-
Assert-NotNull $billingBillingPeriods[0].Name
41-
Assert-NotNull $billingBillingPeriods[0].Id
42-
Assert-NotNull $billingBillingPeriods[0].Type
43-
Assert-NotNull $billingBillingPeriods[0].BillingPeriodStartDate
44-
Assert-NotNull $billingBillingPeriods[0].BillingPeriodEndDate
39+
Assert-True {$billingPeriods.Count -eq 1}
40+
Assert-NotNull $billingPeriods[0].Name
41+
Assert-NotNull $billingPeriods[0].Id
42+
Assert-NotNull $billingPeriods[0].Type
43+
Assert-NotNull $billingPeriods[0].BillingPeriodStartDate
44+
Assert-NotNull $billingPeriods[0].BillingPeriodEndDate
4545
}
4646

4747
<#
@@ -50,7 +50,12 @@ Get billing period with specified name
5050
#>
5151
function Test-GetBillingPeriodWithName
5252
{
53-
$billingPeriodName = "201705-1"
53+
$billingPeriods = Get-AzureRmBillingPeriod | where { $_.InvoiceNames.Count -eq 1 }
54+
Assert-True {$billingPeriods.Count -ge 1}
55+
56+
$billingPeriodName = $billingPeriods[0].Name
57+
$billingInvoiceName = $billingPeriods[0].InvoiceNames[0]
58+
5459
$billingPeriod = Get-AzureRmBillingPeriod -Name $billingPeriodName
5560

5661
Assert-AreEqual $billingPeriodName $billingPeriod.Name
@@ -60,7 +65,7 @@ function Test-GetBillingPeriodWithName
6065
Assert-NotNull $billingPeriod.BillingPeriodEndDate
6166
Assert-NotNull $billingPeriod.InvoiceNames
6267
Assert-AreEqual 1 $billingPeriod.InvoiceNames.Count
63-
Assert-AreEqual "201705-217994100075389" $billingPeriod.InvoiceNames
68+
Assert-AreEqual $billingInvoiceName $billingPeriod.InvoiceNames
6469
}
6570

6671
<#
@@ -69,17 +74,18 @@ Get billing period with specified names
6974
#>
7075
function Test-GetBillingPeriodWithNames
7176
{
72-
$billingPeriodNames = "201705-1", "201704-1", "201703-1"
73-
$billingBillingPeriods = Get-AzureRmBillingPeriod -Name $billingPeriodNames
77+
$sampleBillingPeriods = Get-AzureRmBillingPeriod
78+
Assert-True {$sampleBillingPeriods.Count -gt 1}
79+
80+
$billingPeriodNames = $sampleBillingPeriods | %{ $_.Name }
81+
$billingPeriods = Get-AzureRmBillingPeriod -Name $billingPeriodNames
7482

75-
Assert-True {$billingBillingPeriods.Count -eq 3}
76-
Foreach($billingPeriod in $billingBillingPeriods)
83+
Assert-AreEqual $sampleBillingPeriods.Count $billingPeriods.Count
84+
Foreach($billingPeriod in $billingPeriods)
7785
{
7886
Assert-NotNull $billingPeriod.Id
7987
Assert-NotNull $billingPeriod.Type
8088
Assert-NotNull $billingPeriod.BillingPeriodStartDate
8189
Assert-NotNull $billingPeriod.BillingPeriodEndDate
82-
Assert-NotNull $billingPeriod.InvoiceNames
83-
Assert-AreEqual 1 $billingPeriod.InvoiceNames.Count
8490
}
8591
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Billing.Test.ScenarioTests.ScenarioTest;
16+
using Microsoft.Azure.Commands.ScenarioTest;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Xunit;
19+
20+
namespace Microsoft.Azure.Commands.Billing.Test.ScenarioTests
21+
{
22+
public class EnrollmentAccountTests
23+
{
24+
private ServiceManagemenet.Common.Models.XunitTracingInterceptor _logger;
25+
26+
public EnrollmentAccountTests(Xunit.Abstractions.ITestOutputHelper output)
27+
{
28+
_logger = new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output);
29+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
30+
TestExecutionHelpers.SetUpSessionAndProfile();
31+
}
32+
33+
[Fact]
34+
[Trait(Category.AcceptanceType, Category.CheckIn)]
35+
public void TestListEnrollmentAccounts()
36+
{
37+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListEnrollmentAccounts");
38+
}
39+
40+
[Fact]
41+
[Trait(Category.AcceptanceType, Category.CheckIn)]
42+
public void TestGetEnrollmentAccountWithName()
43+
{
44+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetEnrollmentAccountWithName");
45+
}
46+
}
47+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
# NOTE: This test requires manual setup in your current environment. The following is required:
16+
# 1. An enrollment account in EA. Please go to http://ea.azure.com/ to add and manage enrollment accounts.
17+
# 2. Run your test as either a user with an enrollment in EA.
18+
# 2b. Alternatively, you can grant a service principal access to your enrollment account using RBAC by running the following:
19+
# New-AzureRmRoleAssignment -Scope /providers/Microsoft.Billing/enrollmentAccounts/<object id of the user with an enrollment in EA> -RoleDefinitionName Contributor -ServicePrincipalName <SPN>
20+
# You can then run the tests below using this service principal.
21+
22+
<#
23+
.SYNOPSIS
24+
List billing periods
25+
#>
26+
function Test-ListEnrollmentAccounts
27+
{
28+
$enrollmentAccounts = Get-AzureRmEnrollmentAccount
29+
30+
Assert-True {$enrollmentAccounts.Count -ge 1}
31+
Assert-NotNull $enrollmentAccounts[0].ObjectId
32+
Assert-NotNull $enrollmentAccounts[0].PrincipalName
33+
}
34+
35+
<#
36+
.SYNOPSIS
37+
Get billing period with specified name
38+
#>
39+
function Test-GetEnrollmentAccountWithName
40+
{
41+
$enrollmentAccounts = @(Get-AzureRmEnrollmentAccount)
42+
43+
$enrollmentAccountObjectId = $enrollmentAccounts[0].ObjectId
44+
$enrollmentAccount = Get-AzureRmEnrollmentAccount -ObjectId $enrollmentAccountObjectId
45+
46+
Assert-AreEqual $enrollmentAccountObjectId $enrollmentAccount.ObjectId
47+
Assert-NotNull $enrollmentAccount.PrincipalName
48+
}

src/ResourceManager/Billing/Commands.Billing.Test/ScenarioTests/InvoicesTests.ps1

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,12 @@ Get invoice with specified name
8989
#>
9090
function Test-GetInvoiceWithName
9191
{
92-
$invoiceName = "201705-217994100075389"
93-
$invoice = Get-AzureRmBillingInvoice -Name $invoiceName
92+
$sampleInvoices = Get-AzureRmBillingInvoice
93+
Assert-True { $sampleInvoices.Count -ge 1 }
9494

95-
Assert-AreEqual $invoiceName $invoice.Name
96-
Assert-NotNull $invoice.Id
97-
Assert-NotNull $invoice.Type
98-
Assert-NotNull $invoice.InvoicePeriodStartDate
99-
Assert-NotNull $invoice.InvoicePeriodEndDate
100-
Assert-NotNull $invoice.DownloadUrl
101-
Assert-NotNull $invoice.DownloadUrlExpiry
102-
Assert-NotNull $invoice.BillingPeriodNames
103-
Assert-AreEqual 1 $invoice.BillingPeriodNames.Count
104-
Assert-AreEqual "201705-1" $invoice.BillingPeriodNames
95+
$invoice = Get-AzureRmBillingInvoice -Name $sampleInvoices[0].Name
96+
97+
Assert-AreEqual $invoice.Id $sampleInvoices[0].Id
10598
}
10699

107100
<#
@@ -110,19 +103,10 @@ Get invoice with specified names
110103
#>
111104
function Test-GetInvoiceWithNames
112105
{
113-
$invoiceNames = "201705-217994100075389", "201704-117049130068772", "201703-117646100066812"
114-
$billingInvoices = Get-AzureRmBillingInvoice -Name $invoiceNames
106+
$sampleInvoices = Get-AzureRmBillingInvoice
107+
Assert-True { $sampleInvoices.Count -gt 1 }
108+
109+
$billingInvoices = Get-AzureRmBillingInvoice -Name $sampleInvoices.Name
115110

116-
Assert-True {$billingInvoices.Count -eq 3}
117-
Foreach($invoice in $billingInvoices)
118-
{
119-
Assert-NotNull $invoice.Id
120-
Assert-NotNull $invoice.Type
121-
Assert-NotNull $invoice.InvoicePeriodStartDate
122-
Assert-NotNull $invoice.InvoicePeriodEndDate
123-
Assert-NotNull $invoice.DownloadUrl
124-
Assert-NotNull $invoice.DownloadUrlExpiry
125-
Assert-NotNull $invoice.BillingPeriodNames
126-
Assert-AreEqual 1 $invoice.BillingPeriodNames.Count
127-
}
111+
Assert-AreEqual $sampleInvoices.Count $billingInvoices.Count
128112
}

0 commit comments

Comments
 (0)