Skip to content

Commit 3938a0d

Browse files
author
Ziyue Zheng
authored
Add IotHubTestRunner to replace IotHubController (#18200)
1 parent 7d8e998 commit 3938a0d

File tree

8 files changed

+79
-212
lines changed

8 files changed

+79
-212
lines changed

src/IotHub/IotHub.Test/ScenarioTests/IotHubController.cs

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

src/IotHub/IotHub.Test/ScenarioTests/IotHubDPConfigurationTests.cs

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

15-
using Microsoft.Azure.ServiceManagement.Common.Models;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1816
using Xunit;
1917
using Xunit.Abstractions;
2018

2119
namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
2220
{
23-
public class IotHubDPConfigurationTests : RMTestBase
21+
public class IotHubDPConfigurationTests : IotHubTestRunner
2422
{
25-
public XunitTracingInterceptor _logger;
26-
27-
public IotHubDPConfigurationTests(ITestOutputHelper output)
23+
public IotHubDPConfigurationTests(ITestOutputHelper output) : base(output)
2824
{
29-
_logger = new XunitTracingInterceptor(output);
30-
XunitTracingInterceptor.AddToContext(_logger);
3125
}
3226

3327
[Fact]
3428
[Trait(Category.AcceptanceType, Category.LiveOnly)]
3529
public void TestAzureIotHubConfigurationLifecycle()
3630
{
37-
IotHubController.NewInstance.RunPsTest(_logger, "Test-AzureRmIotHubConfigurationLifecycle");
31+
TestRunner.RunTestScript("Test-AzureRmIotHubConfigurationLifecycle");
3832
}
3933
}
4034
}

src/IotHub/IotHub.Test/ScenarioTests/IotHubDPDeviceTests.cs

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

15-
using Microsoft.Azure.ServiceManagement.Common.Models;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1816
using Xunit;
1917
using Xunit.Abstractions;
2018

2119
namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
2220
{
23-
public class IotHubDPDeviceTests : RMTestBase
21+
public class IotHubDPDeviceTests : IotHubTestRunner
2422
{
25-
public XunitTracingInterceptor _logger;
26-
27-
public IotHubDPDeviceTests(ITestOutputHelper output)
23+
public IotHubDPDeviceTests(ITestOutputHelper output) : base(output)
2824
{
29-
_logger = new XunitTracingInterceptor(output);
30-
XunitTracingInterceptor.AddToContext(_logger);
3125
}
3226

3327
[Fact]
3428
[Trait(Category.AcceptanceType, Category.LiveOnly)]
3529
public void TestAzureIotHubDeviceLifecycle()
3630
{
37-
IotHubController.NewInstance.RunPsTest(_logger, "Test-AzureRmIotHubDeviceLifecycle");
31+
TestRunner.RunTestScript("Test-AzureRmIotHubDeviceLifecycle");
3832
}
3933
}
4034
}

src/IotHub/IotHub.Test/ScenarioTests/IotHubDPModuleTests.cs

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

15-
using Microsoft.Azure.ServiceManagement.Common.Models;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1816
using Xunit;
1917
using Xunit.Abstractions;
2018

2119
namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
2220
{
23-
public class IotHubDPModuleTests : RMTestBase
21+
public class IotHubDPModuleTests : IotHubTestRunner
2422
{
25-
public XunitTracingInterceptor _logger;
26-
27-
public IotHubDPModuleTests(ITestOutputHelper output)
23+
public IotHubDPModuleTests(ITestOutputHelper output) : base(output)
2824
{
29-
_logger = new XunitTracingInterceptor(output);
30-
XunitTracingInterceptor.AddToContext(_logger);
3125
}
3226

3327
[Fact]
3428
[Trait(Category.AcceptanceType, Category.LiveOnly)]
3529
public void TestAzureIotHubModuleLifecycle()
3630
{
37-
IotHubController.NewInstance.RunPsTest(_logger, "Test-AzureRmIotHubModuleLifecycle");
31+
TestRunner.RunTestScript("Test-AzureRmIotHubModuleLifecycle");
3832
}
3933
}
4034
}

src/IotHub/IotHub.Test/ScenarioTests/IotHubDPTracingTests.cs

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

15-
using Microsoft.Azure.ServiceManagement.Common.Models;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1816
using Xunit;
1917
using Xunit.Abstractions;
2018

2119
namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
2220
{
23-
public class IotHubDPTracingTests : RMTestBase
21+
public class IotHubDPTracingTests : IotHubTestRunner
2422
{
25-
public XunitTracingInterceptor _logger;
26-
27-
public IotHubDPTracingTests(ITestOutputHelper output)
23+
public IotHubDPTracingTests(ITestOutputHelper output) : base(output)
2824
{
29-
_logger = new XunitTracingInterceptor(output);
30-
XunitTracingInterceptor.AddToContext(_logger);
3125
}
3226

3327
[Fact]
3428
[Trait(Category.AcceptanceType, Category.LiveOnly)]
3529
public void TestAzureIotHubTracing()
3630
{
37-
IotHubController.NewInstance.RunPsTest(_logger, "Test-AzureRmIotHubTracing");
31+
TestRunner.RunTestScript("Test-AzureRmIotHubTracing");
3832
}
3933
}
4034
}

src/IotHub/IotHub.Test/ScenarioTests/IotHubRoutingTests.cs

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

15-
using Microsoft.Azure.ServiceManagement.Common.Models;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17-
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
1816
using Xunit;
1917
using Xunit.Abstractions;
2018

2119
namespace Microsoft.Azure.Commands.IotHub.Test.ScenarioTests
2220
{
23-
public class IotHubRoutingTests : RMTestBase
21+
public class IotHubRoutingTests : IotHubTestRunner
2422
{
25-
public XunitTracingInterceptor _logger;
26-
27-
public IotHubRoutingTests(ITestOutputHelper output)
23+
public IotHubRoutingTests(ITestOutputHelper output) : base(output)
2824
{
29-
_logger = new XunitTracingInterceptor(output);
30-
XunitTracingInterceptor.AddToContext(_logger);
3125
}
3226

3327
[Fact]
3428
[Trait(Category.AcceptanceType, Category.CheckIn)]
3529
[Trait("Re-record", "ClientRuntime changes")]
3630
public void TestAzureIotHubRoutingLifeCycle()
3731
{
38-
IotHubController.NewInstance.RunPsTest(_logger, "Test-AzureRmIotHubRoutingLifecycle");
32+
TestRunner.RunTestScript("Test-AzureRmIotHubRoutingLifecycle");
3933
}
4034
}
4135
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.IotHub.Test.ScenarioTests
20+
{
21+
public class IotHubTestRunner
22+
{
23+
protected readonly ITestRunner TestRunner;
24+
25+
protected IotHubTestRunner(ITestOutputHelper output)
26+
{
27+
TestRunner = TestManager.CreateInstance(output)
28+
.WithNewPsScriptFilename($"{GetType().Name}.ps1")
29+
.WithProjectSubfolderForTests("ScenarioTests")
30+
.WithCommonPsScripts(new[]
31+
{
32+
@"Assert.ps1",
33+
@"Common.ps1",
34+
@"../AzureRM.Resources.ps1"
35+
})
36+
.WithNewRmModules(helper => new[]
37+
{
38+
helper.RMProfileModule,
39+
helper.GetRMModulePath("Az.IotHub.psd1"),
40+
helper.GetRMModulePath("Az.EventHub.psd1"),
41+
helper.GetRMModulePath("Az.Storage.psd1")
42+
})
43+
.WithNewRecordMatcherArguments(
44+
userAgentsToIgnore: new Dictionary<string, string>
45+
{
46+
{"Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01"}
47+
},
48+
resourceProviders: new Dictionary<string, string>
49+
{
50+
{"Microsoft.Resources", null},
51+
{"Microsoft.Features", null},
52+
{"Microsoft.Storage", null },
53+
{"Microsoft.Authorization", null},
54+
{"Microsoft.EventHub", null}
55+
}
56+
)
57+
.Build();
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)