Skip to content

Commit 84fe287

Browse files
committed
Extract common logic for Instance sku prefixes
1 parent d2bd6ee commit 84fe287

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet;
16+
using Microsoft.Azure.Commands.Sql.Test.Utilities;
17+
using Microsoft.Azure.ServiceManagement.Common.Models;
18+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
19+
using System;
20+
using Microsoft.Azure.Commands.Sql.ElasticPool.Services;
21+
using Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter;
22+
using Xunit;
23+
using Xunit.Abstractions;
24+
25+
namespace Microsoft.Azure.Commands.Sql.Test.UnitTests
26+
{
27+
public class AzureSqlInstanceUnitTests
28+
{
29+
public AzureSqlInstanceUnitTests(ITestOutputHelper output)
30+
{
31+
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
32+
}
33+
34+
[Fact]
35+
[Trait(Category.AcceptanceType, Category.CheckIn)]
36+
public void GetInstanceSkuPrefix()
37+
{
38+
Assert.Equal(
39+
"GP",
40+
AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix("GeneralPurpose"));
41+
Assert.Equal(
42+
"BC",
43+
AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix("BusinessCritical"));
44+
}
45+
}
46+
}

src/Sql/Sql/ManagedInstance/Cmdlet/NewAzureSqlManagedInstance.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Linq;
2323
using System.Management.Automation;
2424
using System.Security;
25+
using Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter;
2526

2627
namespace Microsoft.Azure.Commands.Sql.ManagedInstance.Cmdlet
2728
{
@@ -221,7 +222,7 @@ public override void ExecuteCmdlet()
221222
}
222223
else if (string.Equals(this.ParameterSetName, NewByEditionAndComputeGenerationParameterSet, System.StringComparison.OrdinalIgnoreCase))
223224
{
224-
string editionShort = Edition.Equals(Constants.GeneralPurposeEdition) ? "GP" : Edition.Equals(Constants.BusinessCriticalEdition) ? "BC" : "Unknown";
225+
string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
225226
Sku.Name = editionShort + "_" + ComputeGeneration;
226227
}
227228

src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Security;
2323
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
2424
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
25+
using Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter;
2526
using Microsoft.Azure.Commands.Sql.ManagedInstance.Model;
2627

2728
namespace Microsoft.Azure.Commands.Sql.ManagedInstance.Cmdlet
@@ -172,7 +173,7 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
172173
if (Edition != null)
173174
{
174175
string computeGeneration = existingInstance.Sku.Name.Contains(Constants.ComputeGenerationGen4) ? Constants.ComputeGenerationGen4 : Constants.ComputeGenerationGen5;
175-
string editionShort = Edition.Equals(Constants.GeneralPurposeEdition) ? "GP" : Edition.Equals(Constants.BusinessCriticalEdition) ? "BC" : "Unknown";
176+
string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
176177
Sku.Name = editionShort + "_" + computeGeneration;
177178
Sku.Tier = Edition;
178179
}

src/Sql/Sql/ManagedInstance/Services/AzureSqlManagedInstanceAdapter.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using System.Security.Permissions;
2323
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
2424
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
25+
using Microsoft.Azure.Commands.Sql.Common;
2526
using Microsoft.WindowsAzure.Commands.Common;
2627

2728
namespace Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter
@@ -183,5 +184,23 @@ private static AzureSqlManagedInstanceModel CreateManagedInstanceModelFromRespon
183184

184185
return managedInstance;
185186
}
187+
188+
/// <summary>
189+
/// Get instance sku name based on edition
190+
/// Edition | SkuName
191+
/// GeneralPurpose | GP
192+
/// BusinessCritical | BC
193+
/// </summary>
194+
/// <param name="tier">Azure Sql database edition</param>
195+
/// <returns>The sku name</returns>
196+
public static string GetInstanceSkuPrefix(string tier)
197+
{
198+
if (string.IsNullOrWhiteSpace(tier))
199+
{
200+
return null;
201+
}
202+
203+
return SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? "Unknown";
204+
}
186205
}
187206
}

0 commit comments

Comments
 (0)