@@ -33,6 +33,8 @@ public abstract class AzureBackupTestsBase
33
33
34
34
public BackupVaultServicesManagementClient BackupVaultServicesMgmtClient { get ; private set ; }
35
35
36
+ public BackupServicesManagementClient BackupServicesMgmtClient { get ; private set ; }
37
+
36
38
protected AzureBackupTestsBase ( )
37
39
{
38
40
this . helper = new EnvironmentSetupHelper ( ) ;
@@ -42,8 +44,10 @@ protected AzureBackupTestsBase()
42
44
protected void SetupManagementClients ( )
43
45
{
44
46
BackupVaultServicesMgmtClient = GetBackupVaultServicesManagementClient ( ) ;
47
+ BackupServicesMgmtClient = GetBackupServicesManagementClient ( ) ;
48
+
45
49
//helper.SetupManagementClients(BackupServicesMgmtClient);
46
- helper . SetupSomeOfManagementClients ( BackupVaultServicesMgmtClient ) ;
50
+ helper . SetupSomeOfManagementClients ( BackupVaultServicesMgmtClient , BackupServicesMgmtClient ) ;
47
51
}
48
52
49
53
protected void RunPowerShellTest ( params string [ ] scripts )
@@ -66,6 +70,11 @@ private BackupVaultServicesManagementClient GetBackupVaultServicesManagementClie
66
70
return GetServiceClient < BackupVaultServicesManagementClient > ( ) ;
67
71
}
68
72
73
+ private BackupServicesManagementClient GetBackupServicesManagementClient ( )
74
+ {
75
+ return GetServiceClient < BackupServicesManagementClient > ( ) ;
76
+ }
77
+
69
78
public static T GetServiceClient < T > ( ) where T : class
70
79
{
71
80
var factory = ( TestEnvironmentFactory ) new CSMTestEnvironmentFactory ( ) ;
@@ -74,32 +83,98 @@ public static T GetServiceClient<T>() where T : class
74
83
75
84
ServicePointManager . ServerCertificateValidationCallback = IgnoreCertificateErrorHandler ;
76
85
77
- BackupVaultServicesManagementClient client ;
78
86
string resourceName = ConfigurationManager . AppSettings [ "ResourceName" ] ;
79
87
string resourceGroupName = ConfigurationManager . AppSettings [ "ResourceGroupName" ] ;
80
88
89
+ if ( typeof ( T ) == typeof ( BackupVaultServicesManagementClient ) )
90
+ {
91
+ BackupVaultServicesManagementClient client ;
81
92
82
- if ( testEnvironment . UsesCustomUri ( ) )
93
+ if ( testEnvironment . UsesCustomUri ( ) )
94
+ {
95
+ client = new BackupVaultServicesManagementClient (
96
+ resourceName ,
97
+ resourceGroupName ,
98
+ testEnvironment . Credentials as SubscriptionCloudCredentials ,
99
+ testEnvironment . BaseUri ) ;
100
+ }
101
+
102
+ else
103
+ {
104
+ client = new BackupVaultServicesManagementClient (
105
+ resourceName ,
106
+ resourceGroupName ,
107
+ testEnvironment . Credentials as SubscriptionCloudCredentials ) ;
108
+ }
109
+
110
+ return GetServiceClient < T > ( factory , client ) ;
111
+ }
112
+ else
83
113
{
84
- client = new BackupVaultServicesManagementClient (
85
- resourceName ,
86
- resourceGroupName ,
87
- testEnvironment . Credentials as SubscriptionCloudCredentials ,
88
- testEnvironment . BaseUri ) ;
114
+ BackupServicesManagementClient client ;
115
+
116
+ if ( testEnvironment . UsesCustomUri ( ) )
117
+ {
118
+ client = new BackupServicesManagementClient (
119
+ resourceName ,
120
+ resourceGroupName ,
121
+ testEnvironment . Credentials as SubscriptionCloudCredentials ,
122
+ testEnvironment . BaseUri ) ;
123
+ }
124
+
125
+ else
126
+ {
127
+ client = new BackupServicesManagementClient (
128
+ resourceName ,
129
+ resourceGroupName ,
130
+ testEnvironment . Credentials as SubscriptionCloudCredentials ) ;
131
+ }
132
+
133
+ return GetVaultServiceClient < T > ( factory , client ) ;
89
134
}
135
+ }
90
136
91
- else
137
+ public static T GetServiceClient < T > ( TestEnvironmentFactory factory , BackupVaultServicesManagementClient client ) where T : class
138
+ {
139
+ TestEnvironment testEnvironment = factory . GetTestEnvironment ( ) ;
140
+
141
+ HttpMockServer instance ;
142
+ try
92
143
{
93
- client = new BackupVaultServicesManagementClient (
94
- resourceName ,
95
- resourceGroupName ,
96
- testEnvironment . Credentials as SubscriptionCloudCredentials ) ;
144
+ instance = HttpMockServer . CreateInstance ( ) ;
97
145
}
146
+ catch ( ApplicationException )
147
+ {
148
+ HttpMockServer . Initialize ( "TestEnvironment" , "InitialCreation" ) ;
149
+ instance = HttpMockServer . CreateInstance ( ) ;
150
+ }
151
+ T obj2 = typeof ( T ) . GetMethod ( "WithHandler" , new Type [ 1 ]
152
+ {
153
+ typeof ( DelegatingHandler )
154
+ } ) . Invoke ( ( object ) client , new object [ 1 ]
155
+ {
156
+ ( object ) instance
157
+ } ) as T ;
98
158
99
- return GetServiceClient < T > ( factory , client ) ;
159
+ if ( HttpMockServer . Mode == HttpRecorderMode . Record )
160
+ {
161
+ HttpMockServer . Variables [ TestEnvironment . SubscriptionIdKey ] = testEnvironment . SubscriptionId ;
162
+ }
163
+
164
+ if ( HttpMockServer . Mode == HttpRecorderMode . Playback )
165
+ {
166
+ PropertyInfo property1 = typeof ( T ) . GetProperty ( "LongRunningOperationInitialTimeout" , typeof ( int ) ) ;
167
+ PropertyInfo property2 = typeof ( T ) . GetProperty ( "LongRunningOperationRetryTimeout" , typeof ( int ) ) ;
168
+ if ( property1 != ( PropertyInfo ) null && property2 != ( PropertyInfo ) null )
169
+ {
170
+ property1 . SetValue ( ( object ) obj2 , ( object ) 0 ) ;
171
+ property2 . SetValue ( ( object ) obj2 , ( object ) 0 ) ;
172
+ }
173
+ }
174
+ return obj2 ;
100
175
}
101
176
102
- public static T GetServiceClient < T > ( TestEnvironmentFactory factory , BackupVaultServicesManagementClient client ) where T : class
177
+ public static T GetVaultServiceClient < T > ( TestEnvironmentFactory factory , BackupServicesManagementClient client ) where T : class
103
178
{
104
179
TestEnvironment testEnvironment = factory . GetTestEnvironment ( ) ;
105
180
0 commit comments