13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using Microsoft . Azure . Commands . Common . Authentication ;
16
- using Microsoft . Azure . Gallery ;
17
- using Microsoft . Azure . Management . Authorization ;
18
- using Microsoft . Azure . Management . Resources ;
19
16
using Microsoft . Azure . Management . Storage ;
20
- using Microsoft . Azure . Subscriptions ;
21
17
using Microsoft . Azure . Test . HttpRecorder ;
22
18
using Microsoft . Rest . ClientRuntime . Azure . TestFramework ;
23
19
using Microsoft . WindowsAzure . Commands . ScenarioTest ;
24
20
using System ;
25
21
using System . Collections . Generic ;
22
+ using System . Diagnostics ;
26
23
using System . IO ;
27
24
using System . Linq ;
28
- using LegacyTest = Microsoft . Azure . Test ;
25
+ using Microsoft . Azure . Management . Internal . Resources ;
29
26
using TestEnvironmentFactory = Microsoft . Rest . ClientRuntime . Azure . TestFramework . TestEnvironmentFactory ;
30
- using TestUtilities = Microsoft . Rest . ClientRuntime . Azure . TestFramework . TestUtilities ;
31
27
32
28
namespace Microsoft . Azure . Commands . Management . Storage . Test . ScenarioTests
33
29
{
34
30
public class TestController
35
31
{
36
- private LegacyTest . CSMTestEnvironmentFactory csmTestFactory ;
37
- private EnvironmentSetupHelper helper ;
32
+ private readonly EnvironmentSetupHelper _helper ;
38
33
39
34
public ResourceManagementClient ResourceManagementClient { get ; private set ; }
40
35
41
- public SubscriptionClient SubscriptionClient { get ; private set ; }
42
-
43
- public AuthorizationManagementClient AuthorizationManagementClient { get ; private set ; }
44
-
45
36
public StorageManagementClient StorageClient { get ; private set ; }
46
37
47
- public GalleryClient GalleryClient { get ; private set ; }
48
-
49
-
50
38
public string UserDomain { get ; private set ; }
51
39
52
- public static TestController NewInstance
53
- {
54
- get
55
- {
56
- return new TestController ( ) ;
57
- }
58
- }
40
+ public static TestController NewInstance => new TestController ( ) ;
59
41
60
42
public TestController ( )
61
43
{
62
- helper = new EnvironmentSetupHelper ( ) ;
44
+ _helper = new EnvironmentSetupHelper ( ) ;
63
45
}
64
46
65
47
public void RunPsTest ( params string [ ] scripts )
66
48
{
67
- var callingClassType = TestUtilities . GetCallingClass ( 2 ) ;
68
- var mockName = TestUtilities . GetCurrentMethodName ( 2 ) ;
49
+ var sf = new StackTrace ( ) . GetFrame ( 1 ) ;
50
+ var callingClassType = sf . GetMethod ( ) . ReflectedType ? . ToString ( ) ;
51
+ var mockName = sf . GetMethod ( ) . Name ;
69
52
70
53
RunPsTestWorkflow (
71
54
( ) => scripts ,
72
- // no custom initializer
73
- null ,
74
55
// no custom cleanup
75
56
null ,
76
57
callingClassType ,
@@ -79,7 +60,6 @@ public void RunPsTest(params string[] scripts)
79
60
80
61
public void RunPsTestWorkflow (
81
62
Func < string [ ] > scriptBuilder ,
82
- Action < LegacyTest . CSMTestEnvironmentFactory > initialize ,
83
63
Action cleanup ,
84
64
string callingClassType ,
85
65
string mockName )
@@ -95,26 +75,18 @@ public void RunPsTestWorkflow(
95
75
96
76
using ( MockContext context = MockContext . Start ( callingClassType , mockName ) )
97
77
{
98
-
99
- this . csmTestFactory = new LegacyTest . CSMTestEnvironmentFactory ( ) ;
100
-
101
- if ( initialize != null )
102
- {
103
- initialize ( this . csmTestFactory ) ;
104
- }
105
-
106
78
SetupManagementClients ( context ) ;
107
79
108
- helper . SetupEnvironment ( AzureModule . AzureResourceManager ) ;
80
+ _helper . SetupEnvironment ( AzureModule . AzureResourceManager ) ;
109
81
110
82
var callingClassName = callingClassType
111
83
. Split ( new [ ] { "." } , StringSplitOptions . RemoveEmptyEntries )
112
84
. Last ( ) ;
113
- helper . SetupModules ( AzureModule . AzureResourceManager ,
114
- helper . RMProfileModule ,
115
- helper . RMResourceModule ,
116
- helper . RMStorageDataPlaneModule ,
117
- helper . RMStorageModule ,
85
+ _helper . SetupModules ( AzureModule . AzureResourceManager ,
86
+ _helper . RMProfileModule ,
87
+ _helper . RMResourceModule ,
88
+ _helper . RMStorageDataPlaneModule ,
89
+ _helper . RMStorageModule ,
118
90
"ScenarioTests\\ Common.ps1" ,
119
91
"ScenarioTests\\ " + callingClassName + ".ps1" ,
120
92
"AzureRM.Resources.ps1" ) ;
@@ -127,54 +99,30 @@ public void RunPsTestWorkflow(
127
99
128
100
if ( psScripts != null )
129
101
{
130
- helper . RunPowerShellTest ( psScripts ) ;
102
+ _helper . RunPowerShellTest ( psScripts ) ;
131
103
}
132
104
}
133
105
}
134
106
finally
135
107
{
136
- if ( cleanup != null )
137
- {
138
- cleanup ( ) ;
139
- }
108
+ cleanup ? . Invoke ( ) ;
140
109
}
141
110
}
142
111
}
143
112
144
113
private void SetupManagementClients ( MockContext context )
145
114
{
146
- ResourceManagementClient = GetResourceManagementClient ( ) ;
147
- SubscriptionClient = GetSubscriptionClient ( ) ;
115
+ ResourceManagementClient = GetResourceManagementClient ( context ) ;
148
116
StorageClient = GetStorageManagementClient ( context ) ;
149
- GalleryClient = GetGalleryClient ( ) ;
150
- AuthorizationManagementClient = GetAuthorizationManagementClient ( ) ;
151
117
152
- helper . SetupManagementClients (
118
+ _helper . SetupManagementClients (
153
119
ResourceManagementClient ,
154
- SubscriptionClient ,
155
- StorageClient ,
156
- GalleryClient ,
157
- AuthorizationManagementClient ) ;
158
- }
159
-
160
- private ResourceManagementClient GetResourceManagementClient ( )
161
- {
162
- return LegacyTest . TestBase . GetServiceClient < ResourceManagementClient > ( this . csmTestFactory ) ;
163
- }
164
-
165
- private SubscriptionClient GetSubscriptionClient ( )
166
- {
167
- return LegacyTest . TestBase . GetServiceClient < SubscriptionClient > ( this . csmTestFactory ) ;
168
- }
169
-
170
- private AuthorizationManagementClient GetAuthorizationManagementClient ( )
171
- {
172
- return LegacyTest . TestBase . GetServiceClient < AuthorizationManagementClient > ( this . csmTestFactory ) ;
120
+ StorageClient ) ;
173
121
}
174
122
175
- private GalleryClient GetGalleryClient ( )
123
+ private ResourceManagementClient GetResourceManagementClient ( MockContext context )
176
124
{
177
- return LegacyTest . TestBase . GetServiceClient < GalleryClient > ( this . csmTestFactory ) ;
125
+ return context . GetServiceClient < ResourceManagementClient > ( TestEnvironmentFactory . GetTestEnvironment ( ) ) ;
178
126
}
179
127
180
128
private StorageManagementClient GetStorageManagementClient ( MockContext context )
0 commit comments