Skip to content

Commit a8bfd65

Browse files
ogailogail
authored andcommitted
Remove ExecuteCmdlet from production code
1 parent 0d26df4 commit a8bfd65

File tree

23 files changed

+63
-93
lines changed

23 files changed

+63
-93
lines changed

src/Common/Commands.ScenarioTests.Common/Commands.ScenarioTests.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
</Reference>
131131
</ItemGroup>
132132
<ItemGroup>
133+
<Compile Include="PSCmdletExtensions.cs" />
133134
<Compile Include="Constants.cs" />
134135
<Compile Include="EnvironmentSetupHelper.cs" />
135136
<Compile Include="Mocks\MockAccessToken.cs" />
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+
using System;
16+
using System.Diagnostics;
17+
using System.Management.Automation;
18+
using System.Reflection;
19+
20+
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
21+
{
22+
public static class PSCmdletExtensions
23+
{
24+
private static MethodInfo GetProtectedMethod(string name)
25+
{
26+
MethodInfo m = typeof(PSCmdlet).GetMethod(
27+
name,
28+
BindingFlags.Instance | BindingFlags.NonPublic,
29+
Type.DefaultBinder,
30+
new Type[] { },
31+
null);
32+
33+
return m;
34+
}
35+
36+
public static void ExecuteCmdlet(this PSCmdlet cmdlet)
37+
{
38+
try
39+
{
40+
GetProtectedMethod("ProcessRecord").Invoke(cmdlet, new object[] { });
41+
}
42+
catch (TargetInvocationException e)
43+
{
44+
throw e.InnerException;
45+
}
46+
}
47+
}
48+
}

src/ResourceManager/AzureBatch/Commands.Batch/BatchCmdletBase.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,5 @@ private void HandleBatchException(BatchException ex)
179179
}
180180
}
181181
}
182-
183-
/// <summary>
184-
/// This is added for tests only, should move out from this pattern and rely of ProcessRecord.
185-
/// </summary>
186-
public void ExecuteCmdlet()
187-
{
188-
ProcessRecord();
189-
}
190182
}
191183
}

src/ResourceManager/DataFactories/Commands.DataFactories.Test/ScenarioTests/DataFactoryGatewayTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Microsoft.Azure.Commands.DataFactories.Test
1919
{
2020
public class DataFactoryGatewayTests : DataFactoriesScenarioTestsBase
2121
{
22-
[Fact]
22+
[Fact(Skip = "test takes too long (more than 5 sec)")]
2323
[Trait(Category.AcceptanceType, Category.CheckIn)]
2424
public void TestGetNonExistingDataFactoryGateway()
2525
{
@@ -32,7 +32,7 @@ public void TestCreateDataFactoryGateway()
3232
RunPowerShellTest("Test-DataFactoryGateway");
3333
}
3434

35-
[Fact]
35+
[Fact(Skip = "test takes too long (more than 5 sec)")]
3636
[Trait(Category.AcceptanceType, Category.CheckIn)]
3737
public void TestCreateDataFactoryGatewayWithDataFactoryParameter()
3838
{

src/ResourceManager/DataFactories/Commands.DataFactories/DataFactoryBaseCmdlet.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,5 @@ protected string ResolveResourceName(string rawJsonContent, string nameFromCmdle
8989

9090
return resolvedResourceName;
9191
}
92-
93-
/// <summary>
94-
/// This is added for tests purpose only, should step down in the future.
95-
/// </summary>
96-
public void ExecuteCmdlet()
97-
{
98-
ProcessRecord();
99-
}
10092
}
10193
}

src/ResourceManager/Dns/Commands.Dns.Test/UnitTests/GetAzureDnsRecordSetTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ namespace Microsoft.Azure.Commands.Dns.Test.UnitTests
1616
{
1717
using System.Management.Automation;
1818
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using WindowsAzure.Commands.Test.Utilities.Common;
1920
using Xunit;
2021

21-
public class GetAzureDnsRecordSetTests
22+
public class GetAzureDnsRecordSetTests : RMTestBase
2223
{
2324
[Fact]
2425
[Trait(Category.AcceptanceType, Category.CheckIn)]

src/ResourceManager/Dns/Commands.Dns.Test/UnitTests/GetAzureDnsZoneTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ namespace Microsoft.Azure.Commands.Dns.Test.UnitTests
1616
{
1717
using System.Management.Automation;
1818
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using WindowsAzure.Commands.Test.Utilities.Common;
1920
using Xunit;
2021

21-
public class GetAzureDnsZoneTests
22+
public class GetAzureDnsZoneTests : RMTestBase
2223
{
2324
[Fact]
2425
[Trait(Category.AcceptanceType, Category.CheckIn)]

src/ResourceManager/Dns/Commands.Dns/Models/DnsBaseCmdlet.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,5 @@ public DnsClient DnsClient
3434

3535
set { dnsClient = value; }
3636
}
37-
38-
/// <summary>
39-
/// Added for tests only, should be removed in the future.
40-
/// </summary>
41-
public void ExecuteCmdlet()
42-
{
43-
ProcessRecord();
44-
}
4537
}
4638
}

src/ResourceManager/HDInsight/Commands.HDInsight.Test/HDInsightTestBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
using Microsoft.Azure.Commands.HDInsight.Models;
1818
using Microsoft.Azure.Management.HDInsight.Models;
1919
using Microsoft.WindowsAzure.Commands.Common;
20+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
2021
using Moq;
2122

2223
namespace Microsoft.Azure.Commands.HDInsight.Test
2324
{
24-
public class HDInsightTestBase
25+
public class HDInsightTestBase : RMTestBase
2526
{
2627
protected const string ClusterName = "hdicluster";
2728
protected const string ResourceGroupName = "hdi-rg1";

src/ResourceManager/HDInsight/Commands.HDInsight/HDInsightCmdletBase.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,5 @@ protected string GetClusterConnection(string resourceGroupName, string clusterNa
8383
}
8484
return httpEndpoint;
8585
}
86-
87-
/// <summary>
88-
/// Added for test code only, should be removed in the future.
89-
/// </summary>
90-
public void ExecuteCmdlet()
91-
{
92-
ProcessRecord();
93-
}
9486
}
9587
}

src/ResourceManager/Insights/Commands.Insights.Test/Utilities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Microsoft.Azure.Management.Insights.Models;
2525
using Moq;
2626
using Xunit;
27+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2728

2829
namespace Microsoft.Azure.Commands.Insights.Test
2930
{

src/ResourceManager/Insights/Commands.Insights/Autoscale/NewAutoscaleProfileCommand.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,5 @@ private RecurrentSchedule CreateRecurrentSchedule()
197197
TimeZone = this.ScheduleTimeZone,
198198
};
199199
}
200-
201-
/// <summary>
202-
/// Added for tests only, should be removed in the future.
203-
/// </summary>
204-
public void ExecuteCmdlet()
205-
{
206-
ProcessRecord();
207-
}
208200
}
209201
}

src/ResourceManager/Insights/Commands.Insights/Autoscale/NewAutoscaleRuleCommand.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,5 @@ public ScaleRule CreateSettingRule()
162162
ScaleAction = action,
163163
};
164164
}
165-
166-
/// <summary>
167-
/// Added for tests only, should be removed in the future.
168-
/// </summary>
169-
public void ExecuteCmdlet()
170-
{
171-
ProcessRecord();
172-
}
173165
}
174166
}

src/ResourceManager/Insights/Commands.Insights/InsightsCmdletBase.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,5 @@ protected override void ProcessRecord()
4242
throw ex.Flatten().InnerException;
4343
}
4444
}
45-
46-
/// <summary>
47-
/// Added for tests only, should be removed in the future.
48-
/// </summary>
49-
public void ExecuteCmdlet()
50-
{
51-
ProcessRecord();
52-
}
5345
}
5446
}

src/ResourceManager/KeyVault/Commands.KeyVault/Models/KeyVaultCmdletBase.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ public KeyVaultCmdletBase()
2727
{
2828
}
2929

30-
/// <summary>
31-
/// Shim method for backward compatibility. All cmdlets should implement ProcessRecord directly
32-
/// </summary>
33-
public void ExecuteCmdlet()
34-
{
35-
ProcessRecord();
36-
}
37-
3830
internal IKeyVaultDataServiceClient DataServiceClient
3931
{
4032
get

src/ResourceManager/KeyVault/Commands.KeyVault/Models/KeyVaultManagementCmdletBase.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ public KeyVaultManagementCmdletBase()
3737

3838
}
3939

40-
/// <summary>
41-
/// Shim method for backward compatibility. All cmdlets should implement ProcessRecord directly
42-
/// </summary>
43-
public void ExecuteCmdlet()
44-
{
45-
ProcessRecord();
46-
}
47-
4840
private PSKeyVaultModels.VaultManagementClient _keyVaultManagementClient;
4941
public PSKeyVaultModels.VaultManagementClient KeyVaultManagementClient
5042
{

src/ResourceManager/Resources/Commands.Resources.Test/ResourceGroupDeployments/RemoveAzureResourceGroupDeploymentCommandTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Azure.Commands.Resources.ResourceGroups;
1818
using Moq;
1919
using Xunit;
20+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2021

2122
namespace Microsoft.Azure.Commands.Resources.Test.Resources
2223
{

src/ResourceManager/Resources/Commands.Resources.Test/ResourceGroupDeployments/StopAzureResourceGroupDeploymentCommandTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.Azure.Commands.Resources.ResourceGroups;
1818
using Moq;
1919
using Xunit;
20+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2021

2122
namespace Microsoft.Azure.Commands.Resources.Test.Resources
2223
{

src/ResourceManager/Resources/Commands.Resources.Test/Templates/GetAzureResourceGroupGalleryTemplateCommandTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Microsoft.Azure.Commands.Resources.Templates;
2020
using Moq;
2121
using Xunit;
22+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2223

2324
namespace Microsoft.Azure.Commands.Resources.Test.Resources
2425
{

src/ResourceManager/Resources/Commands.Resources.Test/Templates/SaveAzureResourceGroupGalleryTemplateCommandTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Microsoft.Azure.Commands.Resources.Templates;
2020
using Moq;
2121
using Xunit;
22+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2223

2324
namespace Microsoft.Azure.Commands.Resources.Test.Resources
2425
{

src/ResourceManager/Resources/Commands.Resources.Test/Templates/TestAzureResourceGroupTemplateCommandTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Microsoft.Azure.Management.Resources.Models;
2020
using Moq;
2121
using Xunit;
22+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2223

2324
namespace Microsoft.Azure.Commands.Resources.Test.Resources
2425
{

src/ResourceManager/Resources/Commands.Resources/Models.ResourceGroups/ResourcesBaseCmdlet.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,5 @@ public virtual string DetermineParameterSetName()
108108
{
109109
return this.ParameterSetName;
110110
}
111-
112-
/// <summary>
113-
/// This is present for making tests compile, ideally this pattern should go away.
114-
/// </summary>
115-
public void ExecuteCmdlet()
116-
{
117-
ProcessRecord();
118-
}
119111
}
120112
}

src/ResourceManager/Resources/Commands.Resources/ProviderFeatures/AzureProviderFeatureCmdletsBase.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,5 @@ public virtual string DetermineParameterSetName()
5353
{
5454
return this.ParameterSetName;
5555
}
56-
57-
/// <summary>
58-
/// This is present for making tests compile, ideally this pattern should go away.
59-
/// </summary>
60-
public void ExecuteCmdlet()
61-
{
62-
ProcessRecord();
63-
}
6456
}
6557
}

0 commit comments

Comments
 (0)