diff --git a/src/Monitor/Monitor.Test/ScenarioTests/ActionGroupsTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/ActionGroupsTests.cs index 87fdd7054135..224749f588ae 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/ActionGroupsTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/ActionGroupsTests.cs @@ -12,29 +12,22 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; -using Microsoft.Azure.ServiceManagement.Common.Models; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class ActionGroupsTests : RMTestBase + public class ActionGroupsTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public ActionGroupsTests(Xunit.Abstractions.ITestOutputHelper output) + public ActionGroupsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddGetListSetRemoveActionGroup() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddGetListSetRemoveActionGroup"); + TestRunner.RunTestScript("Test-AddGetListSetRemoveActionGroup"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/ActivityLogAlertsTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/ActivityLogAlertsTests.cs index a453024ba162..d30adaf85fde 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/ActivityLogAlertsTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/ActivityLogAlertsTests.cs @@ -12,28 +12,22 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class ActivityLogAlertsTests : RMTestBase + public class ActivityLogAlertsTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public ActivityLogAlertsTests(Xunit.Abstractions.ITestOutputHelper output) + public ActivityLogAlertsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetGetListUpdateRemoveActivityLogAlert() { - TestsController.NewInstance.RunPsTest(_logger, "Test-SetGetListUpdateRemoveActivityLogAlert"); + TestRunner.RunTestScript("Test-SetGetListUpdateRemoveActivityLogAlert"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/ActivityLogsTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/ActivityLogsTests.cs index e49ca5b97f0a..262013ec7683 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/ActivityLogsTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/ActivityLogsTests.cs @@ -12,42 +12,36 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class ActivityLogsTests : RMTestBase + public class ActivityLogsTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public ActivityLogsTests(Xunit.Abstractions.ITestOutputHelper output) + public ActivityLogsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureLogAllParameters() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureLogAllParameters"); + TestRunner.RunTestScript("Test-GetAzureLogAllParameters"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureSubscriptionIdLogMaxEvents() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureSubscriptionIdLogMaxEvents"); + TestRunner.RunTestScript("Test-GetAzureSubscriptionIdLogMaxEvents"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureSubscriptionIdLogPaged() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureSubscriptionIdLogPaged"); + TestRunner.RunTestScript("Test-GetAzureSubscriptionIdLogPaged"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/AlertsTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/AlertsTests.cs index a1dc15b63025..eacd4eb3c923 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/AlertsTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/AlertsTests.cs @@ -12,147 +12,141 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class AlertsTests : RMTestBase + public class AlertsTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public AlertsTests(Xunit.Abstractions.ITestOutputHelper output) + public AlertsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewAzureRmAlertRuleWebhook() { - TestsController.NewInstance.RunPsTest(_logger, "Test-NewAzureRmAlertRuleWebhook"); + TestRunner.RunTestScript("Test-NewAzureRmAlertRuleWebhook"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewAzureRmAlertRuleEmail() { - TestsController.NewInstance.RunPsTest(_logger, "Test-NewAzureRmAlertRuleEmail"); + TestRunner.RunTestScript("Test-NewAzureRmAlertRuleEmail"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmMetricAlertRule() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRule"); + TestRunner.RunTestScript("Test-AddAzureRmMetricAlertRule"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmWebtestAlertRule() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmWebtestAlertRule"); + TestRunner.RunTestScript("Test-AddAzureRmWebtestAlertRule"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureRmAlertRule() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureRmAlertRule"); + TestRunner.RunTestScript("Test-GetAzureRmAlertRule"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureRmAlertRuleByName() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureRmAlertRuleByName"); + TestRunner.RunTestScript("Test-GetAzureRmAlertRuleByName"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveAzureRmAlertRule() { - TestsController.NewInstance.RunPsTest(_logger, "Test-RemoveAzureRmAlertRule"); + TestRunner.RunTestScript("Test-RemoveAzureRmAlertRule"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureRmAlertHistory() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureRmAlertHistory"); + TestRunner.RunTestScript("Test-GetAzureRmAlertHistory"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureRmMetricAlertRuleV2() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureRmMetricAlertRuleV2"); + TestRunner.RunTestScript("Test-GetAzureRmMetricAlertRuleV2"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveAzureRmMetricAlertRuleV2() { - TestsController.NewInstance.RunPsTest(_logger, "Test-RemoveAzureRmAlertRuleV2"); + TestRunner.RunTestScript("Test-RemoveAzureRmAlertRuleV2"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmMetricAlertRuleV2() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRuleV2"); + TestRunner.RunTestScript("Test-AddAzureRmMetricAlertRuleV2"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmMetricAlertRuleV2WithoutActionGroup() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRuleV2-NoActionGroup"); + TestRunner.RunTestScript("Test-AddAzureRmMetricAlertRuleV2-NoActionGroup"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmMetricAlertRuleV2WithActionGroupId() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRuleV2-ActionGroupId"); + TestRunner.RunTestScript("Test-AddAzureRmMetricAlertRuleV2-ActionGroupId"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmMetricAlertRuleV2WithSkipMetricValidation() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRuleV2-SkipMetricValidation"); + TestRunner.RunTestScript("Test-AddAzureRmMetricAlertRuleV2-SkipMetricValidation"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmMetricAlertRuleV2WithAutoMitigate() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRuleV2-autoMitigate"); + TestRunner.RunTestScript("Test-AddAzureRmMetricAlertRuleV2-autoMitigate"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestDisableAzureRmMetricAlertRuleV2WithActionGroups() { - TestsController.NewInstance.RunPsTest(_logger, "Test-DisableAzureRmMetricAlertRuleV2WithActionGroups"); + TestRunner.RunTestScript("Test-DisableAzureRmMetricAlertRuleV2WithActionGroups"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmDynamicMetricAlertRuleV2() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRuleV2-DynamicThreshold"); + TestRunner.RunTestScript("Test-AddAzureRmMetricAlertRuleV2-DynamicThreshold"); } [Fact] [Trait(Category.AcceptanceType, Category.LiveOnly)] public void TestAddAzureRmWebtestAlertRuleV2() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmMetricAlertRuleV2-Webtest"); + TestRunner.RunTestScript("Test-AddAzureRmMetricAlertRuleV2-Webtest"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/AutoscaleTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/AutoscaleTests.cs index 53b7efb8fe10..d7b54afa3cab 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/AutoscaleTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/AutoscaleTests.cs @@ -12,70 +12,64 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class AutoscaleTests : RMTestBase + public class AutoscaleTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public AutoscaleTests(Xunit.Abstractions.ITestOutputHelper output) + public AutoscaleTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmAutoscaleSetting() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmAutoscaleSetting"); + TestRunner.RunTestScript("Test-AddAzureRmAutoscaleSetting"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureRmAutoscaleSetting() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureRmAutoscaleSetting"); + TestRunner.RunTestScript("Test-GetAzureRmAutoscaleSetting"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureRmAutoscaleSettingByName() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureRmAutoscaleSettingByName"); + TestRunner.RunTestScript("Test-GetAzureRmAutoscaleSettingByName"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestRemoveAzureRmAutoscaleSetting() { - TestsController.NewInstance.RunPsTest(_logger, "Test-RemoveAzureRmAutoscaleSetting"); + TestRunner.RunTestScript("Test-RemoveAzureRmAutoscaleSetting"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureRmAutoscaleHistory() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureRmAutoscaleHistory"); + TestRunner.RunTestScript("Test-GetAzureRmAutoscaleHistory"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewAzureRmAutoscaleNotification() { - TestsController.NewInstance.RunPsTest(_logger, "Test-NewAzureRmAutoscaleNotification"); + TestRunner.RunTestScript("Test-NewAzureRmAutoscaleNotification"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestNewAzureRmAutoscaleWebhook() { - TestsController.NewInstance.RunPsTest(_logger, "Test-NewAzureRmAutoscaleWebhook"); + TestRunner.RunTestScript("Test-NewAzureRmAutoscaleWebhook"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.cs index 646172711337..c172f2c1d9c8 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/AzureRmDiagnosticSettingTests.cs @@ -12,91 +12,85 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class AzureRmDiagnosticSettingTests : RMTestBase + public class AzureRmDiagnosticSettingTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public AzureRmDiagnosticSettingTests(Xunit.Abstractions.ITestOutputHelper output) + public AzureRmDiagnosticSettingTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureRmDiagnosticSetting() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureRmDiagnosticSetting"); + TestRunner.RunTestScript("Test-GetAzureRmDiagnosticSetting"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetAzureRmDiagnosticSettingCreate() { - TestsController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmDiagnosticSettingCreate"); + TestRunner.RunTestScript("Test-SetAzureRmDiagnosticSettingCreate"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetAzureRmDiagnosticSettingUpdate() { - TestsController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmDiagnosticSettingUpdate"); + TestRunner.RunTestScript("Test-SetAzureRmDiagnosticSettingUpdate"); } [Fact] //(Skip = "TODO: fixing this test after introducing Swagger specs")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetAzureRmDiagnosticSettingWithRetention() { - TestsController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmDiagnosticSettingWithRetention"); + TestRunner.RunTestScript("Test-SetAzureRmDiagnosticSettingWithRetention"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetAzureRmDiagnosticSettingCategoriesOnly() { - TestsController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmDiagnosticSetting-CategoriesOnly"); + TestRunner.RunTestScript("Test-SetAzureRmDiagnosticSetting-CategoriesOnly"); } [Fact] //(Skip = "TODO: fixing this test after introducing Swagger specs")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetAzureRmDiagnosticSettingTimeGrainsOnly() { - TestsController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmDiagnosticSetting-TimegrainsOnly"); + TestRunner.RunTestScript("Test-SetAzureRmDiagnosticSetting-TimegrainsOnly"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetAzureRmDiagnosticSettingEventHub() { - TestsController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmDiagnosticSetting-EventHub"); + TestRunner.RunTestScript("Test-SetAzureRmDiagnosticSetting-EventHub"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestSetAzureRmDiagnosticSettingLogAnalytics() { - TestsController.NewInstance.RunPsTest(_logger, "Test-SetAzureRmDiagnosticSetting-LogAnalytics"); + TestRunner.RunTestScript("Test-SetAzureRmDiagnosticSetting-LogAnalytics"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzDiagnosticSettingCategory() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzDiagnosticSettingCategory"); + TestRunner.RunTestScript("Test-GetAzDiagnosticSettingCategory"); } [Fact] [Trait(Category.AcceptanceType, Category.LiveOnly)] public void TestSubscriptionDiagnosticSetting() { - TestsController.NewInstance.RunPsTest(_logger, "Test-SubscriptionDiagnosticSetting"); + TestRunner.RunTestScript("Test-SubscriptionDiagnosticSetting"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/AzureRmLogProfileTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/AzureRmLogProfileTests.cs index 119700dbee88..4e188a094c77 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/AzureRmLogProfileTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/AzureRmLogProfileTests.cs @@ -12,42 +12,36 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class AzureRmLogProfileTests : RMTestBase + public class AzureRmLogProfileTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public AzureRmLogProfileTests(Xunit.Abstractions.ITestOutputHelper output) + public AzureRmLogProfileTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] //(Skip = "TODO: fixing this test after introducing Swagger specs")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetAzureRmLogProfile() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetAzureRmLogProfile"); + TestRunner.RunTestScript("Test-GetAzureRmLogProfile"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmLogProfile() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmLogProfile"); + TestRunner.RunTestScript("Test-AddAzureRmLogProfile"); } [Fact] //(Skip = "TODO: fixing this test after introducing Swagger specs")] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestAddAzureRmLogProfileWithRetention() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddAzureRmLogProfileWithRetention"); + TestRunner.RunTestScript("Test-AddAzureRmLogProfileWithRetention"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/DataCollectionRulesTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/DataCollectionRulesTests.cs index 3a5ed0b3b25f..c50dc408d019 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/DataCollectionRulesTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/DataCollectionRulesTests.cs @@ -12,29 +12,22 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; -using Microsoft.Azure.ServiceManagement.Common.Models; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class DataCollectionRulesTests : RMTestBase + public class DataCollectionRulesTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public DataCollectionRulesTests(Xunit.Abstractions.ITestOutputHelper output) + public DataCollectionRulesTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void AddGetListSetRemoveDataCollectionRulesAndAssociations() { - TestsController.NewInstance.RunPsTest(_logger, "Test-AddGetListSetRemoveDataCollectionRulesAndAssociations"); + TestRunner.RunTestScript("Test-AddGetListSetRemoveDataCollectionRulesAndAssociations"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/MetricsTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/MetricsTests.cs index 4b4578207cdc..6cd25d4c578c 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/MetricsTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/MetricsTests.cs @@ -12,35 +12,29 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class MetricsTests : RMTestBase + public class MetricsTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public MetricsTests(Xunit.Abstractions.ITestOutputHelper output) + public MetricsTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetMetrics() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetMetrics"); + TestRunner.RunTestScript("Test-GetMetrics"); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestGetMetricDefinitions() { - TestsController.NewInstance.RunPsTest(_logger, "Test-GetMetricDefinitions"); + TestRunner.RunTestScript("Test-GetMetricDefinitions"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/MonitorTestRunner.cs b/src/Monitor/Monitor.Test/ScenarioTests/MonitorTestRunner.cs new file mode 100644 index 000000000000..96ca37d6bfcc --- /dev/null +++ b/src/Monitor/Monitor.Test/ScenarioTests/MonitorTestRunner.cs @@ -0,0 +1,59 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Collections.Generic; +using Microsoft.Azure.Commands.TestFx; +using Xunit.Abstractions; + +namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests +{ + public class MonitorTestRunner + { + protected readonly ITestRunner TestRunner; + + protected MonitorTestRunner(ITestOutputHelper output) + { + TestRunner = TestManager.CreateInstance(output) + .WithNewPsScriptFilename($"{GetType().Name}.ps1") + .WithProjectSubfolderForTests("ScenarioTests") + .WithCommonPsScripts(new[] + { + @"Common.ps1", + @"../AzureRM.Storage.ps1", + @"../AzureRM.Resources.ps1" + }) + .WithNewRmModules(helper => new[] + { + helper.RMProfileModule, + helper.GetRMModulePath("Az.Monitor.psd1"), + helper.GetRMModulePath("Az.ApplicationInsights.psd1"), + helper.GetRMModulePath("Az.OperationalInsights.psd1"), + helper.GetRMModulePath("Az.Network.psd1") + }) + .WithNewRecordMatcherArguments( + userAgentsToIgnore: new Dictionary + { + {"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"} + }, + resourceProviders: new Dictionary + { + {"Microsoft.Insights", null}, + {"Microsoft.Network", null}, + {"Microsoft.OperationalInsights", null} + } + ) + .Build(); + } + } +} diff --git a/src/Monitor/Monitor.Test/ScenarioTests/PrivateLinkScopeTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/PrivateLinkScopeTests.cs index 3543fb67bda6..68dcea231a72 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/PrivateLinkScopeTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/PrivateLinkScopeTests.cs @@ -12,35 +12,29 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class PrivateLinkScopeTests : RMTestBase + public class PrivateLinkScopeTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public PrivateLinkScopeTests(Xunit.Abstractions.ITestOutputHelper output) + public PrivateLinkScopeTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.CheckIn)] public void TestPrivateLinkScopeCRUD() { - TestsController.NewInstance.RunPsTest(_logger, "Test-PrivateLinkScopeCRUD"); + TestRunner.RunTestScript("Test-PrivateLinkScopeCRUD"); } [Fact] [Trait(Category.AcceptanceType, Category.LiveOnly)] public void TestPrivateLinkScopedResourceCRUD() { - TestsController.NewInstance.RunPsTest(_logger, "Test-PrivateLinkScopedResourceCRUD"); + TestRunner.RunTestScript("Test-PrivateLinkScopedResourceCRUD"); } } } diff --git a/src/Monitor/Monitor.Test/ScenarioTests/ScheduledQueryRulesTests.cs b/src/Monitor/Monitor.Test/ScenarioTests/ScheduledQueryRulesTests.cs index 7f3fdee87d00..0798b40ec7ca 100644 --- a/src/Monitor/Monitor.Test/ScenarioTests/ScheduledQueryRulesTests.cs +++ b/src/Monitor/Monitor.Test/ScenarioTests/ScheduledQueryRulesTests.cs @@ -12,35 +12,29 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using Microsoft.Azure.ServiceManagement.Common.Models; using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; using Xunit; namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests { - public class ScheduledQueryRulesTests : RMTestBase + public class ScheduledQueryRulesTests : MonitorTestRunner { - public XunitTracingInterceptor _logger; - - public ScheduledQueryRulesTests(Xunit.Abstractions.ITestOutputHelper output) + public ScheduledQueryRulesTests(Xunit.Abstractions.ITestOutputHelper output) : base(output) { - _logger = new XunitTracingInterceptor(output); - XunitTracingInterceptor.AddToContext(_logger); } [Fact] [Trait(Category.AcceptanceType, Category.LiveOnly)] public void TestNewGetUpdateSetRemoveScheduledQueryRule() { - TestsController.NewInstance.RunPsTest(_logger, "Test-NewGetUpdateSetRemoveScheduledQueryRule"); + TestRunner.RunTestScript("Test-NewGetUpdateSetRemoveScheduledQueryRule"); } [Fact] [Trait(Category.AcceptanceType, Category.LiveOnly)] public void TestPipingRemoveSetUpdateScheduledQueryRule() { - TestsController.NewInstance.RunPsTest(_logger, "Test-PipingRemoveSetUpdateScheduledQueryRule"); + TestRunner.RunTestScript("Test-PipingRemoveSetUpdateScheduledQueryRule"); } } } \ No newline at end of file diff --git a/src/Monitor/Monitor.Test/ScenarioTests/TestsController.cs b/src/Monitor/Monitor.Test/ScenarioTests/TestsController.cs deleted file mode 100644 index 4ba81e785f8b..000000000000 --- a/src/Monitor/Monitor.Test/ScenarioTests/TestsController.cs +++ /dev/null @@ -1,219 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -using Microsoft.Azure.Commands.Common.Authentication; -using Microsoft.Azure.Management.Internal.Resources; -using Microsoft.Azure.Management.Monitor; -using Microsoft.Azure.Management.Storage.Version2017_10_01; -using Microsoft.Azure.Management.ApplicationInsights.Management; -using Microsoft.Azure.Management.Network; -using Microsoft.Azure.Management.OperationalInsights; -using Microsoft.Azure.Test.HttpRecorder; -using Microsoft.WindowsAzure.Commands.ScenarioTest; -using Microsoft.WindowsAzure.Commands.Test.Utilities.Common; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework; -using Microsoft.Azure.Internal.Common; - -namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests -{ - public sealed class TestsController : RMTestBase - { - private readonly EnvironmentSetupHelper _helper; - - public ResourceManagementClient ResourceManagementClient { get; private set; } - - public StorageManagementClient StorageManagementClient { get; private set; } - - public IMonitorManagementClient MonitorManagementClient { get; private set; } - - public ApplicationInsightsManagementClient ApplicationInsightsClient { get; private set; } - - public NetworkManagementClient NetworkManagementClient { get; private set; } - - public AzureRestClient AzureRestClient { get; private set; } - - public OperationalInsightsManagementClient OperationalInsightsManagementClient { get; private set; } - - public static TestsController NewInstance => new TestsController(); - - public TestsController() - { - _helper = new EnvironmentSetupHelper(); - } - - public void RunPsTest(ServiceManagement.Common.Models.XunitTracingInterceptor logger, params string[] scripts) - { - var sf = new StackTrace().GetFrame(1); - var callingClassType = sf.GetMethod().ReflectedType?.ToString(); - var mockName = sf.GetMethod().Name; - - _helper.TracingInterceptor = logger; - RunPsTestWorkflow( - () => scripts, - // no custom cleanup - null, - callingClassType, - mockName); - } - - public void RunPsTestWorkflow( - Func scriptBuilder, - Action cleanup, - string callingClassType, - string mockName) - { - var providers = new Dictionary() - { - { "Microsoft.Insights", null }, - { "Microsoft.Network", null }, - { "Microsoft.OperationalInsights", null} - }; - - var providersToIgnore = new Dictionary(); - providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"); - - HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(ignoreResourcesClient: true, providers: providers, userAgents: providersToIgnore); - HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords"); - - using (RestTestFramework.MockContext context = RestTestFramework.MockContext.Start(callingClassType, mockName)) - { - SetupManagementClients(context); - - _helper.SetupEnvironment(AzureModule.AzureResourceManager); - - var callingClassName = callingClassType - .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries) - .Last(); - _helper.SetupModules(AzureModule.AzureResourceManager, - _helper.RMProfileModule, - _helper.GetRMModulePath("AzureRM.Monitor.psd1"), - "ScenarioTests\\Common.ps1", - "ScenarioTests\\" + callingClassName + ".ps1", - "AzureRM.Storage.ps1", - "AzureRM.Resources.ps1", - _helper.GetRMModulePath("AzureRM.ApplicationInsights.psd1"), - _helper.GetRMModulePath("AzureRM.OperationalInsights.psd1"), - _helper.GetRMModulePath("AzureRM.Network.psd1")); - - try - { - if (scriptBuilder != null) - { - var psScripts = scriptBuilder(); - - if (psScripts != null) - { - _helper.RunPowerShellTest(psScripts); - } - } - } - finally - { - cleanup?.Invoke(); - } - } - } - - private void SetupManagementClients(RestTestFramework.MockContext context) - { - if (HttpMockServer.Mode == HttpRecorderMode.Record) - { - // This allows the use of a particular subscription if the user is associated to several - // "TEST_CSM_ORGID_AUTHENTICATION=SubscriptionId=" - string subId = Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION"); - RestTestFramework.TestEnvironment environment = new RestTestFramework.TestEnvironment(connectionString: subId); - this.MonitorManagementClient = this.GetInsightsManagementClient(context: context, env: environment); - this.ResourceManagementClient = this.GetResourceManagementClient(context: context, env: environment); - this.StorageManagementClient = this.GetStorageManagementClient(context: context, env: environment); - this.ApplicationInsightsClient = this.GetApplicationInsightsManagementClient(context: context, env: environment); - this.NetworkManagementClient = this.GetNetworkManagementClient(context: context, env: environment); - this.AzureRestClient = this.GetAzureRestClient(context: context, env: environment); - this.OperationalInsightsManagementClient = GetOperationalInsightsManagementClient(context: context, env: environment); - } - else if (HttpMockServer.Mode == HttpRecorderMode.Playback) - { - this.MonitorManagementClient = this.GetInsightsManagementClient(context: context, env: null); - ResourceManagementClient = this.GetResourceManagementClient(context: context, env: null); - StorageManagementClient = this.GetStorageManagementClient(context: context, env: null); - this.ApplicationInsightsClient = this.GetApplicationInsightsManagementClient(context: context, env: null); - this.NetworkManagementClient = this.GetNetworkManagementClient(context: context, env: null); - this.AzureRestClient = this.GetAzureRestClient(context: context, env: null); - this.OperationalInsightsManagementClient = GetOperationalInsightsManagementClient(context: context, env: null); - } - - _helper.SetupManagementClients( - ResourceManagementClient, - this.MonitorManagementClient, - StorageManagementClient, - this.ApplicationInsightsClient, - this.NetworkManagementClient, - this.AzureRestClient, - this.OperationalInsightsManagementClient); - } - - private ResourceManagementClient GetResourceManagementClient(RestTestFramework.MockContext context, RestTestFramework.TestEnvironment env) - { - return env != null - ? context.GetServiceClient(currentEnvironment:env) - : context.GetServiceClient(); - } - - private IMonitorManagementClient GetInsightsManagementClient(RestTestFramework.MockContext context, RestTestFramework.TestEnvironment env) - { - return env != null - ? context.GetServiceClient(currentEnvironment: env) - : context.GetServiceClient(); - } - - private StorageManagementClient GetStorageManagementClient(RestTestFramework.MockContext context, RestTestFramework.TestEnvironment env) - { - return env != null - ? context.GetServiceClient(currentEnvironment: env) - : context.GetServiceClient(); - } - - private ApplicationInsightsManagementClient GetApplicationInsightsManagementClient(RestTestFramework.MockContext context, RestTestFramework.TestEnvironment env) - { - return env != null - ? context.GetServiceClient(currentEnvironment: env) - : context.GetServiceClient(); - } - - private NetworkManagementClient GetNetworkManagementClient(RestTestFramework.MockContext context, RestTestFramework.TestEnvironment env) - { - return env != null - ? context.GetServiceClient(currentEnvironment: env) - : context.GetServiceClient(); - } - - private AzureRestClient GetAzureRestClient(RestTestFramework.MockContext context, RestTestFramework.TestEnvironment env) - { - return env != null - ? context.GetServiceClient(currentEnvironment: env) - : context.GetServiceClient(); - } - - private OperationalInsightsManagementClient GetOperationalInsightsManagementClient(RestTestFramework.MockContext context, RestTestFramework.TestEnvironment env) - { - return env != null - ? context.GetServiceClient(currentEnvironment: env) - : context.GetServiceClient(); - } - } -}