Skip to content

Commit 9c3a22f

Browse files
committed
Use ValueTask instead of Task
1 parent 4eedeb7 commit 9c3a22f

File tree

4 files changed

+8
-11
lines changed

4 files changed

+8
-11
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ namespace LinkDotNet.Blog.Web.Features.Services;
44

55
public interface IUserRecordService
66
{
7-
Task StoreUserRecordAsync();
7+
ValueTask StoreUserRecordAsync();
88
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public UserRecordService(
2626
this.localStorageService = localStorageService;
2727
}
2828

29-
public async Task StoreUserRecordAsync()
29+
public async ValueTask StoreUserRecordAsync()
3030
{
3131
try
3232
{
@@ -38,7 +38,7 @@ public async Task StoreUserRecordAsync()
3838
}
3939
}
4040

41-
private async Task GetAndStoreUserRecordAsync()
41+
private async ValueTask GetAndStoreUserRecordAsync()
4242
{
4343
var userIdentity = (await authenticationStateProvider.GetAuthenticationStateAsync()).User.Identity;
4444
if (userIdentity == null || userIdentity.IsAuthenticated)
@@ -60,7 +60,7 @@ private async Task GetAndStoreUserRecordAsync()
6060
await userRecordRepository.StoreAsync(record);
6161
}
6262

63-
private async Task<int> GetIdentifierHashAsync()
63+
private async ValueTask<int> GetIdentifierHashAsync()
6464
{
6565
var hasKey = await TryGetKey();
6666
if (hasKey)

src/LinkDotNet.Blog.Web/Features/UrlExtensions.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,5 @@ public static string ToAbsoluteUrl(this string url, string baseUrl)
1515
return successful ? uri.ToString() : url;
1616
}
1717

18-
private static bool IsAbsoluteUrl(string url)
19-
{
20-
return Uri.TryCreate(url, UriKind.Absolute, out _);
21-
}
18+
private static bool IsAbsoluteUrl(string url) => Uri.TryCreate(url, UriKind.Absolute, out _);
2219
}

tests/LinkDotNet.Blog.UnitTests/Web/Features/Services/UserRecordServiceTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ public async Task ShouldNotStoreForAdmin()
7676
}
7777

7878
[Fact]
79-
public async Task ShouldNotThrowExceptionToOutsideWorld()
79+
public void ShouldNotThrowExceptionToOutsideWorld()
8080
{
8181
localStorageService.Setup(l => l.SetItemAsync("user", It.IsAny<Guid>())).Throws<Exception>();
8282

83-
Func<Task> act = () => sut.StoreUserRecordAsync();
83+
var act = () => sut.StoreUserRecordAsync();
8484

85-
await act.Should().NotThrowAsync<Exception>();
85+
act.Should().NotThrow<Exception>();
8686
}
8787

8888
[Fact]

0 commit comments

Comments
 (0)