< Summary

Information
Class: UIBlazor.Services.Settings.LocalStorageService
Assembly: UIBlazor
File(s): /home/runner/work/InvAit/InvAit/UIBlazor/Services/Settings/LocalStorageService.cs
Tag: 71_26091983037
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 34
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%
TryGetItemAsync()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, ILogger<LocalStorageService> logger) : 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?> TryGetItemAsync<T>(string key)
 14    {
 15        try
 16        {
 017            var json = await js.InvokeAsync<string?>("localStorage.getItem", key);
 018            return json == null ? default : JsonSerializer.Deserialize<T>(json);
 19        }
 020        catch (Exception ex)
 21        {
 022            logger.LogError("Error getting item '{key}': {message}", key, ex.Message);
 023            return default;
 24        }
 025    }
 26
 27    public async Task RemoveItemAsync(string key)
 028        => await js.InvokeAsync<string?>("localStorage.removeItem", key);
 29
 30    public async Task<List<string>> GetAllKeysAsync()
 31    {
 032        return await js.InvokeAsync<List<string>>("eval", "Object.keys(localStorage)");
 033    }
 34}