Skip to content

Commit e4f6a99

Browse files
committed
Trim whitespaces from tags
1 parent d4231ea commit e4f6a99

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

LinkDotNet.Blog.UnitTests/Domain/BlogPostTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FluentAssertions;
1+
using System.Linq;
2+
using FluentAssertions;
23
using LinkDotNet.Blog.TestUtilities;
34
using LinkDotNet.Domain;
45
using Xunit;
@@ -23,5 +24,14 @@ public void ShouldUpdateBlogPost()
2324
blogPostToUpdate.PreviewImageUrl.Should().Be("Url");
2425
blogPostToUpdate.Tags.Should().BeNullOrEmpty();
2526
}
27+
28+
[Fact]
29+
public void ShouldTrimWhitespacesFromTags()
30+
{
31+
var blogPost = BlogPost.Create("Title", "Sub", "Content", "Ppeview", new[] { " Tag 1", " Tag 2 " });
32+
33+
blogPost.Tags.Select(t => t.Content).Should().Contain("Tag 1");
34+
blogPost.Tags.Select(t => t.Content).Should().Contain("Tag 2");
35+
}
2636
}
2737
}

LinkDotNet.Domain/BlogPost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static BlogPost Create(string title, string shortDescription, string cont
3333
Content = content,
3434
UpdatedDate = DateTime.Now,
3535
PreviewImageUrl = previewImageUrl,
36-
Tags = tags?.Select(t => new Tag() { Content = t }).ToList(),
36+
Tags = tags?.Select(t => new Tag { Content = t.Trim() }).ToList(),
3737
};
3838

3939
return blogPost;

0 commit comments

Comments
 (0)