Skip to content

Commit 3510359

Browse files
CaptainFanZzzZiyue Zheng
andauthored
Add AlertsManagementTestRunner and replace TestController (Azure#18039)
* Add AlertsManagementTestRunner and replace TestController * Add AlertsManagementTestRunner and replace TestController Co-authored-by: Ziyue Zheng <v-ziyzhe@microsoft.com>
1 parent 8d08472 commit 3510359

File tree

5 files changed

+66
-162
lines changed

5 files changed

+66
-162
lines changed

src/AlertsManagement/AlertsManagement.Test/ScenarioTests/AlertPRuleTests.cs

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

15-
using System;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1816
using Xunit;
19-
using Microsoft.Azure.ServiceManagement.Common.Models;
20-
using Xunit.Abstractions;
2117

2218
namespace Microsoft.Azure.Commands.AlertsManagement.Test.ScenarioTests
2319
{
24-
public class AlertPRuleTests : RMTestBase
20+
public class AlertPRuleTests : AlertsManagementTestRunner
2521
{
26-
public XunitTracingInterceptor _logger;
27-
28-
public AlertPRuleTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public AlertPRuleTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2923
{
30-
_logger = new XunitTracingInterceptor(output);
31-
XunitTracingInterceptor.AddToContext(_logger);
3224
}
3325

3426
[Fact]
3527
[Trait(Category.AcceptanceType, Category.CheckIn)]
3628
public void TestGetAlertProcessingRulesByResourceGroupName()
3729
{
38-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetAlertProcessingRulesByResourceGroupName");
30+
TestRunner.RunTestScript("Test-GetAlertProcessingRulesByResourceGroupName");
3931
}
4032

4133
[Fact]
4234
[Trait(Category.AcceptanceType, Category.CheckIn)]
4335
public void TestCreateUpdateAndDeleteSuppressionRule()
4436
{
45-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateUpdateAndDeleteSuppressionRule");
37+
TestRunner.RunTestScript("Test-CreateUpdateAndDeleteSuppressionRule");
4638
}
4739

4840
[Fact]
4941
[Trait(Category.AcceptanceType, Category.CheckIn)]
5042
public void TestCreateUpdateAndDeleteActionGroupRule()
5143
{
52-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateUpdateAndDeleteActionGroupRule");
44+
TestRunner.RunTestScript("Test-CreateUpdateAndDeleteActionGroupRule");
5345
}
54-
5546
}
5647
}

src/AlertsManagement/AlertsManagement.Test/ScenarioTests/AlertTests.cs

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

15-
using System;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1816
using Xunit;
19-
using Microsoft.Azure.ServiceManagement.Common.Models;
2017

2118
namespace Microsoft.Azure.Commands.AlertsManagement.Test.ScenarioTests
2219
{
23-
public class AlertTests : RMTestBase
20+
public class AlertTests : AlertsManagementTestRunner
2421
{
25-
public XunitTracingInterceptor _logger;
26-
27-
public AlertTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public AlertTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2823
{
29-
_logger = new XunitTracingInterceptor(output);
30-
XunitTracingInterceptor.AddToContext(_logger);
3124
}
3225

3326
[Fact]
3427
[Trait(Category.AcceptanceType, Category.CheckIn)]
3528
public void TestAlertChangeState()
3629
{
37-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AlertChangeState");
30+
TestRunner.RunTestScript("Test-AlertChangeState");
3831
}
3932

4033
[Fact]
4134
[Trait(Category.AcceptanceType, Category.CheckIn)]
4235
public void TestGetAlertsFilteredByParameters()
4336
{
44-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-GetAlertsFilteredByParameters");
37+
TestRunner.RunTestScript("Test-GetAlertsFilteredByParameters");
4538
}
4639

4740
[Fact]
4841
[Trait(Category.AcceptanceType, Category.CheckIn)]
4942
public void TestAlertsSummary()
5043
{
51-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-AlertsSummary");
44+
TestRunner.RunTestScript("Test-AlertsSummary");
5245
}
5346
}
5447
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 Xunit.Abstractions;
18+
19+
namespace Microsoft.Azure.Commands.AlertsManagement.Test.ScenarioTests
20+
{
21+
public class AlertsManagementTestRunner
22+
{
23+
protected readonly ITestRunner TestRunner;
24+
25+
protected AlertsManagementTestRunner(ITestOutputHelper output)
26+
{
27+
TestRunner = TestManager.CreateInstance(output)
28+
.WithNewPsScriptFilename($"{GetType().Name}.ps1")
29+
.WithProjectSubfolderForTests("ScenarioTests")
30+
.WithCommonPsScripts(new[]
31+
{
32+
@"Common.ps1",
33+
@"../AzureRM.Resources.ps1",
34+
})
35+
.WithNewRmModules(helper => new[]
36+
{
37+
helper.RMProfileModule,
38+
helper.GetRMModulePath("Az.AlertsManagement.psd1")
39+
})
40+
.WithNewRecordMatcherArguments(
41+
userAgentsToIgnore: new Dictionary<string, string>
42+
{
43+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"},
44+
},
45+
resourceProviders: new Dictionary<string, string>
46+
{
47+
{"Microsoft.AlertsManagement", null}
48+
}
49+
)
50+
.Build();
51+
}
52+
}
53+
}

src/AlertsManagement/AlertsManagement.Test/ScenarioTests/SmartGroupTests.cs

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

15-
using System;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1816
using Xunit;
19-
using Microsoft.Azure.ServiceManagement.Common.Models;
2017

2118
namespace Microsoft.Azure.Commands.AlertsManagement.Test.ScenarioTests
2219
{
23-
public class SmartGroupTests : RMTestBase
20+
public class SmartGroupTests : AlertsManagementTestRunner
2421
{
25-
public XunitTracingInterceptor _logger;
26-
27-
public SmartGroupTests(Xunit.Abstractions.ITestOutputHelper output)
22+
public SmartGroupTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
2823
{
29-
_logger = new XunitTracingInterceptor(output);
30-
XunitTracingInterceptor.AddToContext(_logger);
3124
}
3225

3326
[Fact]
3427
[Trait(Category.AcceptanceType, Category.CheckIn)]
3528
public void TestSmartGroupChangeState()
3629
{
37-
TestController.NewInstance.RunPowerShellTest(_logger, "Test-SmartGroupChangeState");
30+
TestRunner.RunTestScript("Test-SmartGroupChangeState");
3831
}
3932
}
4033
}

src/AlertsManagement/AlertsManagement.Test/ScenarioTests/TestController.cs

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)