1
- //
1
+ //
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ // http://www.apache.org/licenses/LICENSE-2.0
6
+ //
7
+ // Unless required by applicable law or agreed to in writing, software
8
+ // distributed under the License is distributed on an "AS IS" BASIS,
9
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ // See the License for the specific language governing permissions and
11
+ // limitations under the License.
12
+
13
+ //
2
14
// Licensed under the Apache License, Version 2.0 (the "License");
3
15
// you may not use this file except in compliance with the License.
4
16
// You may obtain a copy of the License at
10
22
// See the License for the specific language governing permissions and
11
23
// limitations under the License.
12
24
13
- using Microsoft . Azure . Commands . TestFx ;
14
- using Microsoft . Azure . Management . ApiManagement ;
15
- using Microsoft . Azure . Management . ApiManagement . Models ;
16
- using Microsoft . Azure . Management . ResourceManager ;
17
- using Microsoft . Azure . Management . ResourceManager . Models ;
18
- using Microsoft . Rest . ClientRuntime . Azure . TestFramework ;
19
- using System ;
20
- using System . Linq ;
21
- using ApiManagementClient = Microsoft . Azure . Management . ApiManagement . ApiManagementClient ;
25
+ // using Microsoft.Azure.Commands.TestFx;
26
+ // using Microsoft.Azure.Management.ApiManagement;
27
+ // using Microsoft.Azure.Management.ApiManagement.Models;
28
+ // using Microsoft.Azure.Management.Internal.Resources ;
29
+ // using Microsoft.Azure.Management.Internal.Resources .Models;
30
+ // using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
31
+ // using System;
32
+ // using System.Linq;
33
+ // using ApiManagementClient = Microsoft.Azure.Management.ApiManagement.ApiManagementClient;
22
34
23
- namespace Microsoft . Azure . Commands . ApiManagement . ServiceManagement . Test . ScenarioTests
24
- {
25
- public static class ApiManagementHelper
26
- {
27
- public static ApiManagementClient GetApiManagementClient ( MockContext context )
28
- {
29
- return context . GetServiceClient < ApiManagementClient > ( ) ;
30
- }
35
+ // namespace Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Test.ScenarioTests
36
+ // {
37
+ // public static class ApiManagementHelper
38
+ // {
39
+ // public static ApiManagementClient GetApiManagementClient(MockContext context)
40
+ // {
41
+ // return context.GetServiceClient<ApiManagementClient>();
42
+ // }
31
43
32
- public static ResourceManagementClient GetResourceManagementClient ( MockContext context )
33
- {
34
- return context . GetServiceClient < ResourceManagementClient > ( ) ;
35
- }
44
+ // public static ResourceManagementClient GetResourceManagementClient(MockContext context)
45
+ // {
46
+ // return context.GetServiceClient<ResourceManagementClient>();
47
+ // }
36
48
37
- private static void ThrowIfTrue ( bool condition , string message )
38
- {
39
- if ( condition )
40
- {
41
- throw new Exception ( message ) ;
42
- }
43
- }
49
+ // private static void ThrowIfTrue(bool condition, string message)
50
+ // {
51
+ // if (condition)
52
+ // {
53
+ // throw new Exception(message);
54
+ // }
55
+ // }
44
56
45
- public static void TryRegisterSubscriptionForResource ( this ResourceManagementClient resourceManagementClient , string providerName = "Microsoft.ApiManagement" )
46
- {
47
- var reg = resourceManagementClient . Providers . Register ( providerName ) ;
48
- ThrowIfTrue ( reg == null , "_client.Providers.Register returned null." ) ;
57
+ // public static void TryRegisterSubscriptionForResource(this ResourceManagementClient resourceManagementClient, string providerName = "Microsoft.ApiManagement")
58
+ // {
59
+ // var reg = resourceManagementClient.Providers.Register(providerName);
60
+ // ThrowIfTrue(reg == null, "_client.Providers.Register returned null.");
49
61
50
- var resultAfterRegister = resourceManagementClient . Providers . Get ( providerName ) ;
51
- ThrowIfTrue ( resultAfterRegister == null , "_client.Providers.Get returned null." ) ;
52
- ThrowIfTrue ( string . IsNullOrEmpty ( resultAfterRegister . Id ) , "Provider.Id is null or empty." ) ;
53
- ThrowIfTrue ( "Registered" != resultAfterRegister . RegistrationState &&
54
- "Registering" != resultAfterRegister . RegistrationState ,
55
- $ "Provider registration state was not 'Registered' or 'Registering', instead it was '{ resultAfterRegister . RegistrationState } '") ;
56
- ThrowIfTrue ( resultAfterRegister . ResourceTypes == null || resultAfterRegister . ResourceTypes . Count == 0 , "Provider.ResourceTypes is empty." ) ;
57
- ThrowIfTrue ( resultAfterRegister . ResourceTypes [ 0 ] . Locations == null || resultAfterRegister . ResourceTypes [ 0 ] . Locations . Count == 0 , "Provider.ResourceTypes[0].Locations is empty." ) ;
58
- }
62
+ // var resultAfterRegister = resourceManagementClient.Providers.Get(providerName);
63
+ // ThrowIfTrue(resultAfterRegister == null, "_client.Providers.Get returned null.");
64
+ // ThrowIfTrue(string.IsNullOrEmpty(resultAfterRegister.Id), "Provider.Id is null or empty.");
65
+ // ThrowIfTrue("Registered" != resultAfterRegister.RegistrationState &&
66
+ // "Registering" != resultAfterRegister.RegistrationState,
67
+ // $"Provider registration state was not 'Registered' or 'Registering', instead it was '{resultAfterRegister.RegistrationState}'");
68
+ // ThrowIfTrue(resultAfterRegister.ResourceTypes == null || resultAfterRegister.ResourceTypes.Count == 0, "Provider.ResourceTypes is empty.");
69
+ // ThrowIfTrue(resultAfterRegister.ResourceTypes[0].Locations == null || resultAfterRegister.ResourceTypes[0].Locations.Count == 0, "Provider.ResourceTypes[0].Locations is empty.");
70
+ // }
59
71
60
- public static string TryGetResourceGroup ( this ResourceManagementClient resourceManagementClient , string location )
61
- {
62
- var resourceGroups = resourceManagementClient . ResourceGroups . ListWithHttpMessagesAsync ( ) . GetAwaiter ( ) . GetResult ( ) . Body ;
63
- var resourceGroup = resourceGroups . Where ( group => string . IsNullOrWhiteSpace ( location ) || group . Location . Equals ( location , StringComparison . OrdinalIgnoreCase ) )
64
- . FirstOrDefault ( group => group . Name . Contains ( "Api-Default" ) ) ;
72
+ // public static string TryGetResourceGroup(this ResourceManagementClient resourceManagementClient, string location)
73
+ // {
74
+ // var resourceGroups = resourceManagementClient.ResourceGroups.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body;
75
+ // var resourceGroup = resourceGroups.Where(group => string.IsNullOrWhiteSpace(location) || group.Location.Equals(location, StringComparison.OrdinalIgnoreCase))
76
+ // .FirstOrDefault(group => group.Name.Contains("Api-Default"));
65
77
66
- return resourceGroup != null
67
- ? resourceGroup . Name
68
- : string . Empty ;
69
- }
78
+ // return resourceGroup != null
79
+ // ? resourceGroup.Name
80
+ // : string.Empty;
81
+ // }
70
82
71
- public static void TryRegisterResourceGroup ( this ResourceManagementClient resourceManagementClient , string location , string resourceGroupName )
72
- {
73
- resourceManagementClient . ResourceGroups . CreateOrUpdate ( resourceGroupName , new ResourceGroup ( location ) ) ;
74
- }
83
+ // public static void TryRegisterResourceGroup(this ResourceManagementClient resourceManagementClient, string location, string resourceGroupName)
84
+ // {
85
+ // resourceManagementClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup(location));
86
+ // }
75
87
76
- public static void TryCreateApiService (
77
- this ApiManagementClient client ,
78
- string resourceGroupName ,
79
- string apiServiceName ,
80
- string location ,
81
- string skuType = SkuType . Developer )
82
- {
83
- client . ApiManagementService . CreateOrUpdate (
84
- resourceGroupName ,
85
- apiServiceName ,
86
- new ApiManagementServiceResource
87
- {
88
- Location = location ,
89
- NotificationSenderEmail = "[email protected] " ,
90
- PublisherEmail = "[email protected] " ,
91
- PublisherName = "apimgmt" ,
92
- Sku = new ApiManagementServiceSkuProperties
93
- {
94
- Capacity = 1 ,
95
- Name = skuType
96
- } ,
97
- } ) ;
88
+ // public static void TryCreateApiService(
89
+ // this ApiManagementClient client,
90
+ // string resourceGroupName,
91
+ // string apiServiceName,
92
+ // string location,
93
+ // string skuType = SkuType.Developer)
94
+ // {
95
+ // client.ApiManagementService.CreateOrUpdate(
96
+ // resourceGroupName,
97
+ // apiServiceName,
98
+ // new ApiManagementServiceResource
99
+ // {
100
+ // Location = location,
101
+ // NotificationSenderEmail = "[email protected] ",
102
+ // PublisherEmail = "[email protected] ",
103
+ // PublisherName = "apimgmt",
104
+ // Sku = new ApiManagementServiceSkuProperties
105
+ // {
106
+ // Capacity = 1,
107
+ // Name = skuType
108
+ // },
109
+ // });
98
110
99
- var response = client . ApiManagementService . Get ( resourceGroupName , apiServiceName ) ;
100
- ThrowIfTrue ( ! response . Name . Equals ( apiServiceName ) , string . Format ( "ApiService name is not equal to {0}" , apiServiceName ) ) ;
101
- }
102
- }
103
- }
111
+ // var response = client.ApiManagementService.Get(resourceGroupName, apiServiceName);
112
+ // ThrowIfTrue(!response.Name.Equals(apiServiceName), string.Format("ApiService name is not equal to {0}", apiServiceName));
113
+ // }
114
+ // }
115
+ // }
0 commit comments