Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 6f0a809

Browse files
authored
fix: Fixed collection of api tags (',' vs. ', ') (#853)
* Fixed collection of tags (',' vs. ', ') * Added therories for api tags separated with and without whitespaces after the separator
1 parent 159f2b5 commit 6f0a809

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

src/ArmTemplates/Creator/TemplateCreators/TagAPITemplateCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public List<TagApiTemplateResource> CreateTagAPITemplateResources(ApiConfig api,
3535
// create a tag/apis association resource for each tag in the config file
3636
List<TagApiTemplateResource> tagAPITemplates = new List<TagApiTemplateResource>();
3737
// tags is comma seperated list pf tags
38-
string[] tagIDs = api.Tags.Split(", ");
38+
string[] tagIDs = api.Tags.Split(",", System.StringSplitOptions.TrimEntries);
3939
foreach (string tagID in tagIDs)
4040
{
4141
TagApiTemplateResource tagAPITemplate = this.CreateTagAPITemplateResource(tagID, api.Name, dependsOn);

src/ArmTemplates/Creator/TemplateCreators/TagTemplateCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Template CreateTagTemplate(CreatorParameters creatorConfig)
5858
{
5959
if (!api.Tags.IsNullOrEmpty())
6060
{
61-
var apiTags = api.Tags.Split(",");
61+
var apiTags = api.Tags.Split(",", System.StringSplitOptions.TrimEntries);
6262

6363
foreach (var apiTag in apiTags)
6464
{

tests/ArmTemplates.Tests/Creator/TemplateCreatorTests/TagTemplateCreatorTests.cs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Tests.Creator.Te
2121
[Trait("Category", "Tag Template Creation")]
2222
public class TagTemplateCreatorTests
2323
{
24-
CreatorParameters GenerateCreatorParameters(List<string> tagNames = null, List<string> apiTagNames = null)
24+
CreatorParameters GenerateCreatorParameters(List<string> tagNames = null, string apiTagNames = null)
2525
{
2626
var creatorConfig = new CreatorParameters();
2727

@@ -41,11 +41,10 @@ CreatorParameters GenerateCreatorParameters(List<string> tagNames = null, List<s
4141
if (!apiTagNames.IsNullOrEmpty())
4242
{
4343
creatorConfig.Apis = new List<ApiConfig>();
44-
var apiTagNamesString = string.Join(",", apiTagNames.ToArray());
4544

4645
var apiConfig = new ApiConfig
4746
{
48-
Tags = apiTagNamesString
47+
Tags = apiTagNames
4948
};
5049

5150
creatorConfig.Apis.Add(apiConfig);
@@ -54,20 +53,17 @@ CreatorParameters GenerateCreatorParameters(List<string> tagNames = null, List<s
5453
return creatorConfig;
5554
}
5655

57-
[Fact]
58-
public void CreateTagTemplate_ShouldCreateTemplateFromCreatorConfig_GivenApiTagsAndConfigTags()
56+
[Theory]
57+
[InlineData("tag 1,tag2,api tag 3,api tag2")]
58+
[InlineData("tag 1, tag2, api tag 3, api tag2")]
59+
public void CreateTagTemplate_ShouldCreateTemplateFromCreatorConfig_GivenApiTagsAndConfigTags(string apiTagNames)
5960
{
6061
var tagTemplateCreator = new TagTemplateCreator(new TemplateBuilder());
6162

6263
var tagNames = new List<string>()
6364
{
6465
"tag 1", "tag2", "tag 3", "tag2"
6566
};
66-
var apiTagNames = new List<string>()
67-
{
68-
"tag 1", "tag2", "api tag 3", "api tag2"
69-
};
70-
7167
var creatorConfig = this.GenerateCreatorParameters(tagNames, apiTagNames);
7268

7369
var expectedTagsDictionary = new Dictionary<string, string>()
@@ -102,15 +98,12 @@ public void CreateTagTemplate_ShouldCreateTemplateFromCreatorConfig_GivenApiTags
10298
}
10399
}
104100

105-
[Fact]
106-
public void CreateTagTemplate_ShouldCreateTemplateFromCreatorConfig_GivenOnlyApiTags()
101+
[Theory]
102+
[InlineData("tag 1,tag2,api tag 3,api tag2")]
103+
[InlineData("tag 1, tag2, api tag 3, api tag2")]
104+
public void CreateTagTemplate_ShouldCreateTemplateFromCreatorConfig_GivenOnlyApiTags(string apiTagNames)
107105
{
108106
var tagTemplateCreator = new TagTemplateCreator(new TemplateBuilder());
109-
110-
var apiTagNames = new List<string>()
111-
{
112-
"tag 1", "tag2", "api tag 3", "api tag2"
113-
};
114107
var creatorConfig = this.GenerateCreatorParameters(apiTagNames: apiTagNames);
115108

116109
var expectedTagsDictionary = new Dictionary<string, string>()
@@ -164,16 +157,13 @@ public void CreateTagTemplate_ShouldThrowEmptyResourceNameAfterSanitizingErrorMe
164157
{
165158
var tagTemplateCreator = new TagTemplateCreator(new TemplateBuilder());
166159

167-
var apiTagNames = new List<string>()
168-
{
169-
"tag 1", "tag2", "api tag 3", " "
170-
};
160+
var apiTagNames = "tag 1,tag2,api tag 3,";
171161
var creatorConfig = this.GenerateCreatorParameters(apiTagNames: apiTagNames);
172162

173163

174164
//act & assert
175165
Action act = () => tagTemplateCreator.CreateTagTemplate(creatorConfig);
176-
act.Should().Throw<EmptyResourceNameException>().WithMessage(string.Format(ErrorMessages.EmptyResourceNameAfterSanitizingErrorMessage, " "));
166+
act.Should().Throw<EmptyResourceNameException>().WithMessage(string.Format(ErrorMessages.EmptyResourceNameAfterSanitizingErrorMessage, string.Empty)); ;
177167
}
178168
}
179169
}

0 commit comments

Comments
 (0)