Skip to content

Commit f3eb2d6

Browse files
committed
comment out ApiManagementHelper.cs (#26989)
* Update ApiManagementHelper.cs * Update resource manager namespace imports * Comment out unused code in ApiManagementHelper.cs * Update ApiManagementTests.cs
1 parent 8bd24a6 commit f3eb2d6

File tree

2 files changed

+103
-91
lines changed

2 files changed

+103
-91
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
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+
//
214
// Licensed under the Apache License, Version 2.0 (the "License");
315
// you may not use this file except in compliance with the License.
416
// You may obtain a copy of the License at
@@ -10,94 +22,94 @@
1022
// See the License for the specific language governing permissions and
1123
// limitations under the License.
1224

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;
2234

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+
// }
3143

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+
// }
3648

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+
// }
4456

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.");
4961

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+
// }
5971

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"));
6577

66-
return resourceGroup != null
67-
? resourceGroup.Name
68-
: string.Empty;
69-
}
78+
// return resourceGroup != null
79+
// ? resourceGroup.Name
80+
// : string.Empty;
81+
// }
7082

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+
// }
7587

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+
// });
98110

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+
// }

src/ApiManagement/ApiManagement.ServiceManagement.Test/ScenarioTests/ApiManagementTests.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ public ApiManagementTests(Xunit.Abstractions.ITestOutputHelper output) : base(ou
2929
{
3030
using (var context = MockContext.Start("ApiManagementTests", "CreateApiManagementService"))
3131
{
32-
var resourceManagementClient = ApiManagementHelper.GetResourceManagementClient(context);
32+
//var resourceManagementClient = ApiManagementHelper.GetResourceManagementClient(context);
3333
ResourceGroupName = "Apim-NetSdk-20210801";
34-
Location = "CentralUSEUAP";
34+
//Location = "CentralUSEUAP";
3535

36-
if (string.IsNullOrWhiteSpace(ResourceGroupName))
37-
{
38-
ResourceGroupName = TestUtilities.GenerateName("Api-Default");
39-
resourceManagementClient.TryRegisterResourceGroup(Location, ResourceGroupName);
40-
}
36+
//if (string.IsNullOrWhiteSpace(ResourceGroupName))
37+
//{
38+
// ResourceGroupName = TestUtilities.GenerateName("Api-Default");
39+
// resourceManagementClient.TryRegisterResourceGroup(Location, ResourceGroupName);
40+
//}
4141

4242
ApiManagementServiceName = "powershellsdkservicetest";
43-
ApiManagementHelper.GetApiManagementClient(context).TryCreateApiService(ResourceGroupName, ApiManagementServiceName, Location);
43+
//ApiManagementHelper.GetApiManagementClient(context).TryCreateApiService(ResourceGroupName, ApiManagementServiceName, Location);
4444
}
4545
}
4646

@@ -301,4 +301,4 @@ public void ApiDiagnosticCrudTest()
301301
TestRunner.RunTestScript(ConvertScriptName("ApiDiagnostic-CrudTest"));
302302
}
303303
}
304-
}
304+
}

0 commit comments

Comments
 (0)