Skip to content

Commit 8efe523

Browse files
committed
Merge branch 'preview' of https://github.com/Azure/azure-powershell into preview
2 parents 6c98abc + 26156e3 commit 8efe523

File tree

37 files changed

+936
-953
lines changed

37 files changed

+936
-953
lines changed

documentation/development-docs/azure-powershell-design-guidelines.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ $job | Wait-Job
269269
$subcriptions = $job | Receive-Job
270270
````
271271

272+
To set a custom job name, please use [SetBackgroupJobDescription(string name)](https://github.com/Azure/azure-powershell/blob/preview/src/Common/Commands.Common/AzurePSCmdlet.cs#L761). The default job description is: "Long Running Operation for '{cmdlet name}' on resource '{resource name}'"
273+
272274
## Argument Completers
273275

274276
PowerShell uses Argument Completers to provide tab completion for users. At the moment, Azure PowerShell has two specific argument completers that should be applied to relevant parameters, and one generic argument completer that can be used to tab complete with a given list of values.
@@ -307,4 +309,4 @@ using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
307309
[Parameter(Mandatory = false, HelpMessage = "The tiers of the plan")]
308310
[PSArgumentCompleter("Basic", "Premium", "Elite")]
309311
public string Tier { get; set; }
310-
```
312+
```

src/Common/Commands.Common/AzurePSCmdlet.cs

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
1919
using Microsoft.Azure.ServiceManagemenet.Common.Models;
2020
using Microsoft.WindowsAzure.Commands.Common;
21+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2122
using System;
2223
using System.Collections.Concurrent;
2324
using System.Diagnostics;
@@ -688,22 +689,78 @@ protected override void ProcessRecord()
688689
}
689690
}
690691

692+
private string _implementationBackgroundJobDescription;
693+
691694
/// <summary>
692695
/// Job Name paroperty iof this cmdlet is run as a job
693696
/// </summary>
694697
public virtual string ImplementationBackgroundJobDescription
695698
{
696699
get
697700
{
698-
string name = "Long Running Azure Operation";
699-
string commandName = MyInvocation?.MyCommand?.Name;
700-
if (!string.IsNullOrWhiteSpace(commandName))
701+
if (_implementationBackgroundJobDescription != null)
701702
{
702-
name = string.Format("Long Running Operation for '{0}'", commandName);
703+
return _implementationBackgroundJobDescription;
703704
}
705+
else
706+
{
707+
string name = "Long Running Azure Operation";
708+
string commandName = MyInvocation?.MyCommand?.Name;
709+
string objectName = null;
710+
if (this.IsBound("Name"))
711+
{
712+
objectName = MyInvocation.BoundParameters["Name"].ToString();
713+
}
714+
else if (this.IsBound("InputObject") == true)
715+
{
716+
var type = MyInvocation.BoundParameters["InputObject"].GetType();
717+
var inputObject = Convert.ChangeType(MyInvocation.BoundParameters["InputObject"], type);
718+
if (type.GetProperty("Name") != null)
719+
{
720+
objectName = inputObject.GetType().GetProperty("Name").GetValue(inputObject).ToString();
721+
}
722+
else if (type.GetProperty("ResourceId") != null)
723+
{
724+
string[] tokens = inputObject.GetType().GetProperty("ResourceId").GetValue(inputObject).ToString().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
725+
if (tokens.Length >= 8)
726+
{
727+
objectName = tokens[tokens.Length - 1];
728+
}
729+
}
730+
}
731+
else if (this.IsBound("ResourceId") == true)
732+
{
733+
string[] tokens = MyInvocation.BoundParameters["ResourceId"].ToString().Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
734+
if (tokens.Length >= 8)
735+
{
736+
objectName = tokens[tokens.Length - 1];
737+
}
738+
}
739+
740+
if (!string.IsNullOrWhiteSpace(commandName))
741+
{
742+
if (!string.IsNullOrWhiteSpace(objectName))
743+
{
744+
name = string.Format("Long Running Operation for '{0}' on resource '{1}'", commandName, objectName);
745+
}
746+
else
747+
{
748+
name = string.Format("Long Running Operation for '{0}'", commandName);
749+
}
750+
}
704751

705-
return name;
752+
return name;
753+
}
706754
}
755+
set
756+
{
757+
_implementationBackgroundJobDescription = value;
758+
}
759+
}
760+
761+
public void SetBackgroundJobDescription(string jobName)
762+
{
763+
ImplementationBackgroundJobDescription = jobName;
707764
}
708765

709766
protected virtual void Dispose(bool disposing)

src/ResourceManager/Common/Commands.Common.Authentication.ResourceManager/AzureRmProfile.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ bool SafeDeserializeObject<T>(string serialization, out T result, JsonConverter
164164
private void Initialize(AzureRmProfile profile)
165165
{
166166
EnvironmentTable.Clear();
167+
// Adding predefined environments
168+
foreach (var env in AzureEnvironment.PublicEnvironments)
169+
{
170+
EnvironmentTable[env.Key] = env.Value;
171+
}
172+
167173
Contexts.Clear();
168174
DefaultContextKey = "Default";
169175
if (profile != null)

src/ResourceManager/Consumption/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Add new parameters Expand, ResourceGroup, InstanceName, InstanceId, Tags, and Top on Cmdlet Get-AzureRmConsumptionUsageDetail
2122

2223
## Version 0.3.2
2324
* Set minimum dependency of module to PowerShell 5.0

src/ResourceManager/Consumption/Commands.Consumption.Test/Commands.Consumption.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
6363
<Private>True</Private>
6464
</Reference>
65-
<Reference Include="Microsoft.Azure.Management.Consumption, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Consumption.1.1.0-preview\lib\net452\Microsoft.Azure.Management.Consumption.dll</HintPath>
65+
<Reference Include="Microsoft.Azure.Management.Consumption, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Consumption.3.0.0\lib\net452\Microsoft.Azure.Management.Consumption.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>

src/ResourceManager/Consumption/Commands.Consumption.Test/ScenarioTests/TestController.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
using Microsoft.Azure.Subscriptions;
2525
using Microsoft.Azure.Test;
2626
using Microsoft.Azure.Test.HttpRecorder;
27-
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
2827
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2928
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
3029
using TestBase = Microsoft.Azure.Test.TestBase;
31-
using TestEnvironmentFactory = Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestEnvironmentFactory;
3230
using TestUtilities = Microsoft.Azure.Test.TestUtilities;
31+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
3332

3433
namespace Microsoft.Azure.Commands.Consumption.Test.ScenarioTests.ScenarioTest
3534
{
@@ -78,12 +77,11 @@ protected void SetupManagementClients(MockContext context)
7877
ConsumptionManagementClient);
7978
}
8079

81-
public void RunPowerShellTest(ServiceManagemenet.Common.Models.XunitTracingInterceptor logger, params string[] scripts)
80+
public void RunPowerShellTest(params string[] scripts)
8281
{
8382
var callingClassType = TestUtilities.GetCallingClass(2);
8483
var mockName = TestUtilities.GetCurrentMethodName(2);
8584

86-
_helper.TracingInterceptor = logger;
8785
RunPsTestWorkflow(
8886
() => scripts,
8987
// no custom initializer
@@ -179,7 +177,10 @@ private GalleryClient GetGalleryClient()
179177

180178
private ConsumptionManagementClient GetConsumptionManagementClient(MockContext context)
181179
{
182-
return context.GetServiceClient<ConsumptionManagementClient>(TestEnvironmentFactory.GetTestEnvironment());
180+
return
181+
context.GetServiceClient<ConsumptionManagementClient>(
182+
new Rest.ClientRuntime.Azure.TestFramework.TestEnvironment(
183+
Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION")));
183184
}
184185
}
185186
}

src/ResourceManager/Consumption/Commands.Consumption.Test/ScenarioTests/UsageDetailsTests.cs

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,81 +16,60 @@
1616
using Microsoft.Azure.Commands.ScenarioTest;
1717
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1818
using Xunit;
19+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
20+
using Xunit.Abstractions;
21+
using Microsoft.Azure.ServiceManagemenet.Common.Models;
1922

2023
namespace Microsoft.Azure.Commands.Consumption.Test.ScenarioTests
2124
{
22-
public class UsageDetailsTests
25+
public class UsageDetailsTests : RMTestBase
2326
{
24-
private ServiceManagemenet.Common.Models.XunitTracingInterceptor _logger;
25-
26-
public UsageDetailsTests(Xunit.Abstractions.ITestOutputHelper output)
27+
public UsageDetailsTests(ITestOutputHelper output)
2728
{
28-
_logger = new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output);
29-
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(_logger);
29+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
3030
TestExecutionHelpers.SetUpSessionAndProfile();
3131
}
3232

3333
[Fact]
3434
[Trait(Category.AcceptanceType, Category.CheckIn)]
3535
public void TestListUsageDetails()
3636
{
37-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListUsageDetails");
38-
}
39-
40-
[Fact]
41-
[Trait(Category.AcceptanceType, Category.CheckIn)]
42-
public void TestListUsageDetailsWithExpand()
43-
{
44-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListUsageDetailsWithExpand");
45-
}
46-
47-
[Fact]
48-
[Trait(Category.AcceptanceType, Category.CheckIn)]
49-
public void TestListUsageDetailsWithFilter()
50-
{
51-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListUsageDetailsWithFilter");
52-
}
53-
54-
[Fact]
55-
[Trait(Category.AcceptanceType, Category.CheckIn)]
56-
public void TestListInvoiceUsageDetails()
57-
{
58-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListInvoiceUsageDetails");
37+
TestController.NewInstance.RunPowerShellTest("Test-ListUsageDetails");
5938
}
6039

6140
[Fact]
6241
[Trait(Category.AcceptanceType, Category.CheckIn)]
63-
public void TestListInvoiceUsageDetailsWithExpand()
42+
public void TestListUsageDetailsWithMeterDetailsExpand()
6443
{
65-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListInvoiceUsageDetailsWithExpand");
44+
TestController.NewInstance.RunPowerShellTest("Test-ListUsageDetailsWithMeterDetailsExpand");
6645
}
6746

6847
[Fact]
6948
[Trait(Category.AcceptanceType, Category.CheckIn)]
70-
public void TestListInvoiceUsageDetailsWithFilter()
49+
public void TestListUsageDetailsWithDateFilter()
7150
{
72-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListInvoiceUsageDetailsWithFilter");
51+
TestController.NewInstance.RunPowerShellTest("Test-ListUsageDetailsWithDateFilter");
7352
}
7453

7554
[Fact]
7655
[Trait(Category.AcceptanceType, Category.CheckIn)]
7756
public void TestListBillingPeriodUsageDetails()
7857
{
79-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListBillingPeriodUsageDetails");
58+
TestController.NewInstance.RunPowerShellTest("Test-ListBillingPeriodUsageDetails");
8059
}
8160

8261
[Fact]
8362
[Trait(Category.AcceptanceType, Category.CheckIn)]
84-
public void TestListBillingPeriodUsageDetailsWithExpand()
63+
public void TestListBillingPeriodUsageDetailsWithFilterOnInstanceName()
8564
{
86-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListBillingPeriodUsageDetailsWithExpand");
65+
TestController.NewInstance.RunPowerShellTest("Test-ListBillingPeriodUsageDetailsWithFilterOnInstanceName");
8766
}
8867

8968
[Fact]
9069
[Trait(Category.AcceptanceType, Category.CheckIn)]
91-
public void TestListBillingPeriodUsageDetailsWithFilter()
70+
public void TestListBillingPeriodUsageDetailsWithDateFilter()
9271
{
93-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ListBillingPeriodUsageDetailsWithFilter");
72+
TestController.NewInstance.RunPowerShellTest("Test-ListBillingPeriodUsageDetailsWithDateFilter");
9473
}
9574

9675
}

0 commit comments

Comments
 (0)