< Summary

Information
Class: Pomodoro.Web.Services.Repositories.TimerSettingsRecord
Assembly: Pomodoro.Web
File(s): /home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/Repositories/SettingsRepository.cs
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 72
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_PomodoroMinutes()100%11100%
get_ShortBreakMinutes()100%11100%
get_LongBreakMinutes()100%11100%
get_SoundEnabled()100%11100%
get_NotificationsEnabled()100%11100%
get_AutoStartEnabled()100%11100%
get_AutoStartDelaySeconds()100%11100%

File(s)

/home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/Repositories/SettingsRepository.cs

#LineLine coverage
 1using Pomodoro.Web.Models;
 2
 3namespace Pomodoro.Web.Services.Repositories;
 4
 5/// <summary>
 6/// Repository implementation for settings persistence using IndexedDB
 7/// </summary>
 8public class SettingsRepository : ISettingsRepository
 9{
 10    private readonly IIndexedDbService _indexedDb;
 11
 12    public SettingsRepository(IIndexedDbService indexedDb)
 13    {
 14        _indexedDb = indexedDb;
 15    }
 16
 17    public async Task<TimerSettings?> GetAsync()
 18    {
 19        var record = await _indexedDb.GetAsync<TimerSettingsRecord>(Constants.Storage.SettingsStore, Constants.Storage.D
 20        if (record == null) return null;
 21
 22        return new TimerSettings
 23        {
 24            PomodoroMinutes = record.PomodoroMinutes,
 25            ShortBreakMinutes = record.ShortBreakMinutes,
 26            LongBreakMinutes = record.LongBreakMinutes,
 27            SoundEnabled = record.SoundEnabled,
 28            NotificationsEnabled = record.NotificationsEnabled,
 29            AutoStartEnabled = record.AutoStartEnabled,
 30            AutoStartDelaySeconds = record.AutoStartDelaySeconds
 31        };
 32    }
 33
 34    public async Task<bool> SaveAsync(TimerSettings settings)
 35    {
 36        if (settings == null) throw new ArgumentNullException(nameof(settings));
 37
 38        var record = new TimerSettingsRecord
 39        {
 40            Id = Constants.Storage.DefaultSettingsId,
 41            PomodoroMinutes = settings.PomodoroMinutes,
 42            ShortBreakMinutes = settings.ShortBreakMinutes,
 43            LongBreakMinutes = settings.LongBreakMinutes,
 44            SoundEnabled = settings.SoundEnabled,
 45            NotificationsEnabled = settings.NotificationsEnabled,
 46            AutoStartEnabled = settings.AutoStartEnabled,
 47            AutoStartDelaySeconds = settings.AutoStartDelaySeconds
 48        };
 49        return await _indexedDb.PutAsync(Constants.Storage.SettingsStore, record);
 50    }
 51
 52    public async Task ResetToDefaultsAsync()
 53    {
 54        var defaults = new TimerSettings();
 55        await SaveAsync(defaults);
 56    }
 57}
 58
 59/// <summary>
 60/// Record for storing timer settings in IndexedDB
 61/// </summary>
 62public class TimerSettingsRecord
 63{
 19564    public string Id { get; set; } = Constants.Storage.DefaultSettingsId;
 11965    public int PomodoroMinutes { get; set; }
 11966    public int ShortBreakMinutes { get; set; }
 11967    public int LongBreakMinutes { get; set; }
 11468    public bool SoundEnabled { get; set; }
 11469    public bool NotificationsEnabled { get; set; }
 11470    public bool AutoStartEnabled { get; set; }
 11471    public int AutoStartDelaySeconds { get; set; }
 72}