< Summary

Information
Class: TeleFlow.Framework.States.UpdateWizard
Assembly: TeleFlow.Framework.Core
File(s): /_/src/TeleFlow.Framework.Core/States/UpdateWizard.cs
Line coverage
94%
Covered lines: 33
Uncovered lines: 2
Coverable lines: 35
Total lines: 82
Line coverage: 94.2%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Current()100%22100%
get_Data()100%11100%
GetCurrentAsync()100%22100%
GoToAsync()100%22100%
BackAsync()75%4480%
ResetAsync()100%11100%

File(s)

/_/src/TeleFlow.Framework.Core/States/UpdateWizard.cs

#LineLine coverage
 1namespace TeleFlow.Framework.States;
 2
 3public sealed class UpdateWizard
 4{
 5    private readonly UpdateState _state;
 6    private readonly IStateHistoryStore _historyStore;
 7
 8    internal UpdateWizard(
 9        UpdateState state,
 10        IStateHistoryStore historyStore)
 11    {
 1712        ArgumentNullException.ThrowIfNull(state);
 1713        ArgumentNullException.ThrowIfNull(historyStore);
 14
 1715        _state = state;
 1716        _historyStore = historyStore;
 1717    }
 18
 19    public State Current
 20    {
 21        get
 22        {
 823            var currentState = _state.CurrentStateSnapshot;
 524            if (string.IsNullOrWhiteSpace(currentState))
 25            {
 126                throw new InvalidOperationException(
 127                    "Wizard current state is not available because the current update has no active state.");
 28            }
 29
 430            return State.Create(currentState);
 31        }
 32    }
 33
 334    public UpdateStateData Data => _state.Data;
 35
 36    public async ValueTask<State?> GetCurrentAsync(CancellationToken cancellationToken = default)
 37    {
 238        var currentState = await _state.GetAsync(cancellationToken).ConfigureAwait(false);
 239        return string.IsNullOrWhiteSpace(currentState)
 240            ? null
 241            : State.Create(currentState);
 242    }
 43
 44    public async ValueTask GoToAsync(
 45        State state,
 46        CancellationToken cancellationToken = default)
 47    {
 848        var currentState = await _state.GetAsync(cancellationToken).ConfigureAwait(false);
 849        await _state.SetAsync(state, cancellationToken).ConfigureAwait(false);
 50
 751        if (!string.IsNullOrWhiteSpace(currentState))
 52        {
 653            await _historyStore.PushAsync(_state.Key, currentState, cancellationToken).ConfigureAwait(false);
 54        }
 655    }
 56
 57    public async ValueTask BackAsync(CancellationToken cancellationToken = default)
 58    {
 459        var previousState = await _historyStore.PeekAsync(_state.Key, cancellationToken).ConfigureAwait(false);
 460        if (string.IsNullOrWhiteSpace(previousState))
 61        {
 162            throw new InvalidOperationException(
 163                "Wizard cannot go back because state history is empty for the current update.");
 64        }
 65
 366        await _state.SetAsync(previousState, cancellationToken).ConfigureAwait(false);
 67
 268        var poppedState = await _historyStore.PopAsync(_state.Key, cancellationToken).ConfigureAwait(false);
 269        if (!string.Equals(poppedState, previousState, StringComparison.Ordinal))
 70        {
 071            throw new InvalidOperationException(
 072                "Wizard state history changed while going back. State history storage returned an unexpected previous st
 73        }
 274    }
 75
 76    public async ValueTask ResetAsync(CancellationToken cancellationToken = default)
 77    {
 478        await _state.Data.ClearAsync(cancellationToken).ConfigureAwait(false);
 379        await _historyStore.ClearAsync(_state.Key, cancellationToken).ConfigureAwait(false);
 280        await _state.ClearAsync(cancellationToken).ConfigureAwait(false);
 281    }
 82}