Skip to content

Commit c536130

Browse files
committed
Refactor naming and how to count words
1 parent f38d48a commit c536130

File tree

7 files changed

+11
-13
lines changed

7 files changed

+11
-13
lines changed

src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Components/UploadFile.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
private async Task HandleFileUpload(InputFileChangeEventArgs args)
4040
{
41-
var content = await FileProcessor.GetContent(args.File);
41+
var content = await FileProcessor.GetContentAsync(args.File);
4242
await OnFileUploaded.InvokeAsync(content);
4343
}
44-
}
44+
}

src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Services/FileProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Services;
66

77
public class FileProcessor : IFileProcessor
88
{
9-
public async Task<string> GetContent(IBrowserFile file)
9+
public async Task<string> GetContentAsync(IBrowserFile file)
1010
{
1111
await using var stream = file.OpenReadStream();
1212
var reader = new StreamReader(stream);

src/LinkDotNet.Blog.Web/Features/Admin/BlogPostEditor/Services/IFileProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ namespace LinkDotNet.Blog.Web.Features.Admin.BlogPostEditor.Services;
55

66
public interface IFileProcessor
77
{
8-
Task<string> GetContent(IBrowserFile file);
9-
}
8+
Task<string> GetContentAsync(IBrowserFile file);
9+
}

src/LinkDotNet.Blog.Web/Features/Services/ReadingTimeCalculator.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ public static int CalculateReadingTime(string content)
2424
private static int GetWordCount(ReadOnlySpan<char> content)
2525
{
2626
var wordCount = 0;
27-
for (var i = 0; i < content.Length; i++)
27+
var index = 0;
28+
while ((index = content[index..].IndexOf(' ')) != -1)
2829
{
29-
if (content[i] == ' ')
30-
{
31-
wordCount++;
32-
}
30+
wordCount++;
3331
}
3432

3533
return wordCount;

tests/LinkDotNet.Blog.IntegrationTests/Web/Features/Admin/BlogPostEditor/CreateNewBlogPostPageTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static InputFileChangeEventArgs SetupUploadFile(string contentFromFile,
6868
{
6969
var file = new Mock<IBrowserFile>();
7070
var fileProcessor = new Mock<IFileProcessor>();
71-
fileProcessor.Setup(f => f.GetContent(file.Object)).ReturnsAsync(contentFromFile);
71+
fileProcessor.Setup(f => f.GetContentAsync(file.Object)).ReturnsAsync(contentFromFile);
7272
var args = new InputFileChangeEventArgs(new[]
7373
{
7474
file.Object,

tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Components/UploadFileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public async Task ShouldCallProcessorWhenFilesUploaded()
2222
var invokedContent = string.Empty;
2323
var file = new Mock<IBrowserFile>();
2424
var fileProcessor = new Mock<IFileProcessor>();
25-
fileProcessor.Setup(f => f.GetContent(file.Object)).ReturnsAsync(content);
25+
fileProcessor.Setup(f => f.GetContentAsync(file.Object)).ReturnsAsync(content);
2626
var args = new InputFileChangeEventArgs(new[]
2727
{
2828
file.Object,

tests/LinkDotNet.Blog.UnitTests/Web/Features/Admin/BlogPostEditor/Services/FileProcessorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public async Task ShouldProcessFileContent()
2020
browserFile.Setup(b => b.OpenReadStream(It.IsAny<long>(), default))
2121
.Returns(stream);
2222

23-
var content = await new FileProcessor().GetContent(browserFile.Object);
23+
var content = await new FileProcessor().GetContentAsync(browserFile.Object);
2424

2525
content.Should().Be(streamString);
2626
}

0 commit comments

Comments
 (0)