< Summary

Information
Class: UIBlazor.Services.Settings.LocalStorageService
Assembly: UIBlazor
File(s): /home/runner/work/InvAit/InvAit/UIBlazor/Services/Settings/LocalStorageService.cs
Tag: 14_22728831704
Line coverage
0%
Covered lines: 0
Uncovered lines: 10
Coverable lines: 10
Total lines: 26
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
SetItemAsync()100%210%
GetItemAsync()0%620%
RemoveItemAsync()100%210%
GetAllKeysAsync()100%210%

File(s)

/home/runner/work/InvAit/InvAit/UIBlazor/Services/Settings/LocalStorageService.cs

#LineLine coverage
 1using Microsoft.JSInterop;
 2
 3namespace UIBlazor.Services.Settings;
 4
 05public class LocalStorageService(IJSRuntime js) : ILocalStorageService
 6{
 7    public async Task SetItemAsync<T>(string key, T value)
 8    {
 09        var json = JsonSerializer.Serialize(value);
 010        await js.InvokeVoidAsync("localStorage.setItem", key, json);
 011    }
 12
 13    public async Task<T?> GetItemAsync<T>(string key)
 14    {
 015        var json = await js.InvokeAsync<string?>("localStorage.getItem", key);
 016        return json == null ? default : JsonSerializer.Deserialize<T>(json);
 017    }
 18
 19    public async Task RemoveItemAsync(string key)
 020        => await js.InvokeAsync<string?>("localStorage.removeItem", key);
 21
 22    public async Task<List<string>> GetAllKeysAsync()
 23    {
 024        return await js.InvokeAsync<List<string>>("eval", "Object.keys(localStorage)");
 025    }
 26}