Skip to content

Commit bb4301a

Browse files
author
Ziyue Zheng
authored
Add AdvisorTestRunner and replace TestController (#17961)
* Add AdvisorTestRunner and replace TestController * Add AdvisorTestRunner.cs to replace TestController.cs * Add license
1 parent a229858 commit bb4301a

File tree

7 files changed

+82
-173
lines changed

7 files changed

+82
-173
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.Collections.Generic;
16+
using Microsoft.Azure.Commands.TestFx;
17+
using Microsoft.Azure.Internal.Subscriptions;
18+
using Microsoft.Azure.Management.Advisor;
19+
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.Advisor.Test.ScenarioTests
23+
{
24+
public class AdvisorTestRunner
25+
{
26+
protected readonly ITestRunner TestRunner;
27+
28+
protected AdvisorTestRunner(ITestOutputHelper output)
29+
{
30+
TestRunner = TestManager.CreateInstance (output)
31+
.WithNewPsScriptFilename ($"{GetType().Name}.ps1")
32+
.WithProjectSubfolderForTests ("ScenarioTests")
33+
.WithCommonPsScripts (new[]
34+
{
35+
@"Common.ps1"
36+
})
37+
.WithNewRmModules (helper => new[]
38+
{
39+
helper.RMProfileModule,
40+
helper.GetRMModulePath("Az.Advisor.psd1")
41+
})
42+
.WithNewRecordMatcherArguments (
43+
userAgentsToIgnore: new Dictionary<string, string>(),
44+
resourceProviders: new Dictionary<string, string>
45+
{
46+
{"Microsoft.Resources", null},
47+
{"Microsoft.Features", null},
48+
{"Microsoft.Authorization", null}
49+
}
50+
)
51+
.Build();
52+
}
53+
}
54+
}

src/Advisor/Advisor.Test/ScenarioTests/DisableAzAdvisorRecommendation.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,44 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1916
using Xunit;
20-
using Xunit.Abstractions;
2117

2218

2319
namespace Microsoft.Azure.Commands.Advisor.Test.ScenarioTests
2420
{
25-
public class DisableAzAdvisorRecommendation
21+
public class DisableAzAdvisorRecommendation : AdvisorTestRunner
2622
{
27-
private readonly XunitTracingInterceptor _logger;
28-
29-
public DisableAzAdvisorRecommendation(Xunit.Abstractions.ITestOutputHelper output)
23+
public DisableAzAdvisorRecommendation(Xunit.Abstractions.ITestOutputHelper output) : base(output)
3024
{
31-
_logger = new XunitTracingInterceptor(output);
32-
XunitTracingInterceptor.AddToContext(_logger);
33-
TestExecutionHelpers.SetUpSessionAndProfile();
3425
}
3526

36-
3727
[Fact]
3828
[Trait(Category.AcceptanceType, Category.CheckIn)]
3929
public void DisableAzAdvisorRecommendationBadUserInput()
4030
{
41-
TestController.NewInstance.RunPowerShellTest(_logger, "Disable-AzAdvisorRecommendationBadUserInput-Negative");
31+
TestRunner.RunTestScript("Disable-AzAdvisorRecommendationBadUserInput-Negative");
4232
}
4333

4434
[Fact]
4535
[Trait(Category.AcceptanceType, Category.CheckIn)]
4636
public void DisableAzAdvisorRecommendationByNameParameter()
4737
{
48-
TestController.NewInstance.RunPowerShellTest(_logger, "Disable-AzAdvisorRecommendationByNameParameter");
38+
TestRunner.RunTestScript("Disable-AzAdvisorRecommendationByNameParameter");
4939
}
5040

5141
[Fact]
5242
[Trait(Category.AcceptanceType, Category.CheckIn)]
5343
public void DisableAzAdvisorRecommendationByIdParameter()
5444
{
55-
TestController.NewInstance.RunPowerShellTest(_logger, "Disable-AzAdvisorRecommendationByIdParameter");
45+
TestRunner.RunTestScript("Disable-AzAdvisorRecommendationByIdParameter");
5646
}
5747

5848
[Fact]
5949
[Trait(Category.AcceptanceType, Category.CheckIn)]
6050
public void DisableAzAdvisorRecommendationPipelineScenario()
6151
{
62-
TestController.NewInstance.RunPowerShellTest(_logger, "Disable-AzAdvisorRecommendationPipelineScenario");
52+
TestRunner.RunTestScript("Disable-AzAdvisorRecommendationPipelineScenario");
6353
}
6454
}
6555
}

src/Advisor/Advisor.Test/ScenarioTests/EnableAzAdvisorRecommendation.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,37 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1916
using Xunit;
20-
using Xunit.Abstractions;
2117

2218

2319
namespace Microsoft.Azure.Commands.Advisor.Test.ScenarioTests
2420
{
25-
public class EnableAzAdvisorRecommendation
21+
public class EnableAzAdvisorRecommendation : AdvisorTestRunner
2622
{
27-
private readonly XunitTracingInterceptor _logger;
28-
29-
public EnableAzAdvisorRecommendation(Xunit.Abstractions.ITestOutputHelper output)
23+
public EnableAzAdvisorRecommendation(Xunit.Abstractions.ITestOutputHelper output) : base(output)
3024
{
31-
_logger = new XunitTracingInterceptor(output);
32-
XunitTracingInterceptor.AddToContext(_logger);
33-
TestExecutionHelpers.SetUpSessionAndProfile();
3425
}
3526

3627
[Fact]
3728
[Trait(Category.AcceptanceType, Category.CheckIn)]
3829
public void EnableAzAdvisorRecommendationByNameParameterSet()
3930
{
40-
TestController.NewInstance.RunPowerShellTest(_logger, "Enable-AzAdvisorRecommendationByNameParameterSet");
31+
TestRunner.RunTestScript("Enable-AzAdvisorRecommendationByNameParameterSet");
4132
}
4233

4334
[Fact]
4435
[Trait(Category.AcceptanceType, Category.CheckIn)]
4536
public void EnableAzAdvisorRecommendationByIdParameterSet()
4637
{
47-
TestController.NewInstance.RunPowerShellTest(_logger, "Enable-AzAdvisorRecommendationByIdParameterSet");
38+
TestRunner.RunTestScript("Enable-AzAdvisorRecommendationByIdParameterSet");
4839
}
4940

5041
[Fact]
5142
[Trait(Category.AcceptanceType, Category.CheckIn)]
5243
public void EnableAzAdvisorRecommendationPipeline()
5344
{
54-
TestController.NewInstance.RunPowerShellTest(_logger, "Enable-AzAdvisorRecommendationPipeline");
45+
TestRunner.RunTestScript("Enable-AzAdvisorRecommendationPipeline");
5546
}
5647
}
5748
}

src/Advisor/Advisor.Test/ScenarioTests/GetAzAdvisorConfiguration.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,23 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1916
using Xunit;
20-
using Xunit.Abstractions;
2117

2218

2319
namespace Microsoft.Azure.Commands.Advisor.Test.ScenarioTests
2420
{
25-
public class GetAzAdvisorConfiguration
21+
public class GetAzAdvisorConfiguration : AdvisorTestRunner
2622
{
27-
private readonly XunitTracingInterceptor _logger;
28-
29-
public GetAzAdvisorConfiguration(Xunit.Abstractions.ITestOutputHelper output)
23+
public GetAzAdvisorConfiguration(Xunit.Abstractions.ITestOutputHelper output) : base(output)
3024
{
31-
_logger = new XunitTracingInterceptor(output);
32-
XunitTracingInterceptor.AddToContext(_logger);
33-
TestExecutionHelpers.SetUpSessionAndProfile();
3425
}
3526

3627
[Fact]
3728
[Trait(Category.AcceptanceType, Category.CheckIn)]
3829
public void GetConfigurationQuery()
3930
{
40-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzAdvisorConfigurationNoParameter");
31+
TestRunner.RunTestScript("Get-AzAdvisorConfigurationNoParameter");
4132
}
4233
}
4334
}

src/Advisor/Advisor.Test/ScenarioTests/GetAzAdvisorRecommendation.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,43 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1916
using Xunit;
20-
using Xunit.Abstractions;
2117

2218
namespace Microsoft.Azure.Commands.Advisor.Test.ScenarioTests
2319
{
24-
public class GetAzAdvisorRecommendation
20+
public class GetAzAdvisorRecommendation : AdvisorTestRunner
2521
{
26-
private readonly XunitTracingInterceptor _logger;
27-
28-
public GetAzAdvisorRecommendation(Xunit.Abstractions.ITestOutputHelper output)
22+
public GetAzAdvisorRecommendation(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2923
{
30-
_logger = new XunitTracingInterceptor(output);
31-
XunitTracingInterceptor.AddToContext(_logger);
32-
TestExecutionHelpers.SetUpSessionAndProfile();
3324
}
3425

3526
[Fact]
3627
[Trait(Category.AcceptanceType, Category.CheckIn)]
3728
public void GetAzAdvisorRecommendationNoParameter()
3829
{
39-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzAdvisorRecommendationNoParameter");
30+
TestRunner.RunTestScript("Get-AzAdvisorRecommendationNoParameter");
4031
}
4132

4233
[Fact]
4334
[Trait(Category.AcceptanceType, Category.CheckIn)]
4435
public void GetAzAdvisorRecommendationByCategory()
4536
{
46-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzAdvisorRecommendationByCategory");
37+
TestRunner.RunTestScript("Get-AzAdvisorRecommendationByCategory");
4738
}
4839

4940
[Fact]
5041
[Trait(Category.AcceptanceType, Category.CheckIn)]
5142
public void GetAzAdvisorRecommendationByNameParameterSet()
5243
{
53-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzAdvisorRecommendationByNameParameterSet");
44+
TestRunner.RunTestScript("Get-AzAdvisorRecommendationByNameParameterSet");
5445
}
5546

5647
[Fact]
5748
[Trait(Category.AcceptanceType, Category.CheckIn)]
5849
public void GetAzAdvisorRecommendationByIdParameterSet()
5950
{
60-
TestController.NewInstance.RunPowerShellTest(_logger, "Get-AzAdvisorRecommendationByIdParameterSet");
51+
TestRunner.RunTestScript("Get-AzAdvisorRecommendationByIdParameterSet");
6152
}
6253
}
6354
}

src/Advisor/Advisor.Test/ScenarioTests/SetAzAdvisorConfiguration.cs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,68 +12,59 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.ServiceManagement.Common.Models;
1715
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1916
using Xunit;
20-
using Xunit.Abstractions;
2117

2218

2319
namespace Microsoft.Azure.Commands.Advisor.Test.ScenarioTests
2420
{
25-
public class SetAzAdvisorConfiguration
21+
public class SetAzAdvisorConfiguration : AdvisorTestRunner
2622
{
27-
private readonly XunitTracingInterceptor _logger;
28-
29-
public SetAzAdvisorConfiguration(Xunit.Abstractions.ITestOutputHelper output)
23+
public SetAzAdvisorConfiguration(Xunit.Abstractions.ITestOutputHelper output) : base(output)
3024
{
31-
_logger = new XunitTracingInterceptor(output);
32-
XunitTracingInterceptor.AddToContext(_logger);
33-
TestExecutionHelpers.SetUpSessionAndProfile();
3425
}
3526

3627
[Fact]
3728
[Trait(Category.AcceptanceType, Category.CheckIn)]
3829
public void SetAzAdvisorConfigurationBadUserInputLowCpu()
3930
{
40-
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzAdvisorConfigurationBadUserInputLowCpu-Negative");
31+
TestRunner.RunTestScript("Set-AzAdvisorConfigurationBadUserInputLowCpu-Negative");
4132
}
4233

4334
[Fact]
4435
[Trait(Category.AcceptanceType, Category.CheckIn)]
4536
public void SetAzAdvisorConfigurationByLowCpu()
4637
{
47-
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzAdvisorConfigurationWithLowCpu");
38+
TestRunner.RunTestScript("Set-AzAdvisorConfigurationWithLowCpu");
4839
}
4940

5041
[Fact]
5142
[Trait(Category.AcceptanceType, Category.CheckIn)]
5243
public void SetAzAdvisorConfigurationByLowCpuExclude()
5344
{
54-
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzAdvisorConfigurationByLowCpuExclude");
45+
TestRunner.RunTestScript("Set-AzAdvisorConfigurationByLowCpuExclude");
5546
}
5647

5748
[Fact]
5849
[Trait(Category.AcceptanceType, Category.CheckIn)]
5950
public void SetAzAdvisorConfigurationPipelineByLowCpuExclude()
6051
{
61-
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzAdvisorConfigurationPipelineByLowCpuExclude");
52+
TestRunner.RunTestScript("Set-AzAdvisorConfigurationPipelineByLowCpuExclude");
6253
}
6354

6455
// ResourceGroupParameterSets
6556
[Fact]
6657
[Trait(Category.AcceptanceType, Category.CheckIn)]
6758
public void SetAzAdvisorConfigurationByRg()
6859
{
69-
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzAdvisorConfigurationWithRg");
60+
TestRunner.RunTestScript("Set-AzAdvisorConfigurationWithRg");
7061
}
7162

7263
[Fact]
7364
[Trait(Category.AcceptanceType, Category.CheckIn)]
7465
public void SetAzAdvisorConfigurationByRgExclude()
7566
{
76-
TestController.NewInstance.RunPowerShellTest(_logger, "Set-AzAdvisorConfigurationByRgExclude");
67+
TestRunner.RunTestScript("Set-AzAdvisorConfigurationByRgExclude");
7768
}
7869

7970
}

0 commit comments

Comments
 (0)