< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetAsync()100%22100%
SaveAsync()100%22100%
ResetToDefaultsAsync()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
 8412    public SettingsRepository(IIndexedDbService indexedDb)
 8413    {
 8414        _indexedDb = indexedDb;
 8415    }
 16
 17    public async Task<TimerSettings?> GetAsync()
 4718    {
 4719        var record = await _indexedDb.GetAsync<TimerSettingsRecord>(Constants.Storage.SettingsStore, Constants.Storage.D
 7020        if (record == null) return null;
 21
 1422        return new TimerSettings
 1423        {
 1424            PomodoroMinutes = record.PomodoroMinutes,
 1425            ShortBreakMinutes = record.ShortBreakMinutes,
 1426            LongBreakMinutes = record.LongBreakMinutes,
 1427            SoundEnabled = record.SoundEnabled,
 1428            NotificationsEnabled = record.NotificationsEnabled,
 1429            AutoStartEnabled = record.AutoStartEnabled,
 1430            AutoStartDelaySeconds = record.AutoStartDelaySeconds
 1431        };
 4232    }
 33
 34    public async Task<bool> SaveAsync(TimerSettings settings)
 8635    {
 8736        if (settings == null) throw new ArgumentNullException(nameof(settings));
 37
 8538        var record = new TimerSettingsRecord
 8539        {
 8540            Id = Constants.Storage.DefaultSettingsId,
 8541            PomodoroMinutes = settings.PomodoroMinutes,
 8542            ShortBreakMinutes = settings.ShortBreakMinutes,
 8543            LongBreakMinutes = settings.LongBreakMinutes,
 8544            SoundEnabled = settings.SoundEnabled,
 8545            NotificationsEnabled = settings.NotificationsEnabled,
 8546            AutoStartEnabled = settings.AutoStartEnabled,
 8547            AutoStartDelaySeconds = settings.AutoStartDelaySeconds
 8548        };
 8549        return await _indexedDb.PutAsync(Constants.Storage.SettingsStore, record);
 7650    }
 51
 52    public async Task ResetToDefaultsAsync()
 2953    {
 2954        var defaults = new TimerSettings();
 2955        await SaveAsync(defaults);
 2756    }
 57}
 58
 59/// <summary>
 60/// Record for storing timer settings in IndexedDB
 61/// </summary>
 62public class TimerSettingsRecord
 63{
 64    public string Id { get; set; } = Constants.Storage.DefaultSettingsId;
 65    public int PomodoroMinutes { get; set; }
 66    public int ShortBreakMinutes { get; set; }
 67    public int LongBreakMinutes { get; set; }
 68    public bool SoundEnabled { get; set; }
 69    public bool NotificationsEnabled { get; set; }
 70    public bool AutoStartEnabled { get; set; }
 71    public int AutoStartDelaySeconds { get; set; }
 72}