|
| 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.WindowsAzure.Commands.ServiceManagement.Extensions; |
| 16 | +using System; |
| 17 | +using Xunit; |
| 18 | + |
| 19 | +namespace Microsoft.WindowsAzure.Commands.ScenarioTest |
| 20 | +{ |
| 21 | + public partial class ServiceManagementTests |
| 22 | + { |
| 23 | + [Fact] |
| 24 | + [Trait(Category.Service, Category.ServiceManagement)] |
| 25 | + [Trait(Category.AcceptanceType, Category.CheckIn)] |
| 26 | + [Trait(Category.AcceptanceType, Category.BVT)] |
| 27 | + public void TestExtensionRoleNames() |
| 28 | + { |
| 29 | + var roleNames = new string[] |
| 30 | + { |
| 31 | + "test Role Name", |
| 32 | + "!!!!! _____ test Role Name ~~~", |
| 33 | + "testRoleName", |
| 34 | + " testRoleName", |
| 35 | + "testRoleName ", |
| 36 | + " testRoleName" |
| 37 | + }; |
| 38 | + var expectedPrefixName = "testRoleName"; |
| 39 | + var expectedExtensionId = "testRoleName-test-test-Ext-0"; |
| 40 | + foreach (var roleName in roleNames) |
| 41 | + { |
| 42 | + ExtensionRole er = new ExtensionRole(roleName); |
| 43 | + Assert.Equal(er.PrefixName, expectedPrefixName); |
| 44 | + Assert.Equal(er.GetExtensionId("test", "test", 0), expectedExtensionId); |
| 45 | + } |
| 46 | + |
| 47 | + var longRoleNames = new string[] |
| 48 | + { |
| 49 | + "A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789", |
| 50 | + " A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789 ~~~" |
| 51 | + }; |
| 52 | + |
| 53 | + // Extenion ID's Max Length 60 = 43 + 1 + 4 + 1 + 4 + 1 + 5 |
| 54 | + // i.e. 'A123...E123' + '-' + 'test' + '-' + 'test' + '-' + 'Ext-0' |
| 55 | + // L=43 L=1 L=4 L=1 L=4 L=1 L=5 |
| 56 | + expectedPrefixName = longRoleNames[0]; |
| 57 | + expectedExtensionId = "A123456789B123456789C123456789D123456789E123-test-test-Ext-0"; |
| 58 | + foreach (var roleName in longRoleNames) |
| 59 | + { |
| 60 | + ExtensionRole er = new ExtensionRole(roleName); |
| 61 | + Assert.Equal(er.PrefixName, expectedPrefixName); |
| 62 | + Assert.Equal(er.GetExtensionId("test", "test", 0), expectedExtensionId); |
| 63 | + } |
| 64 | + |
| 65 | + |
| 66 | + var longExtensionNames = longRoleNames; |
| 67 | + expectedExtensionId = "D-A123456789B123456789C123456789D123456789E123456-test-Ext-1"; |
| 68 | + foreach (var extensionName in longExtensionNames) |
| 69 | + { |
| 70 | + ExtensionRole er = new ExtensionRole(); |
| 71 | + Assert.Equal(er.PrefixName, "Default"); |
| 72 | + Assert.Equal(er.GetExtensionId(extensionName, "test", 1), expectedExtensionId); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments