< Summary

Information
Class: TeleFlow.Framework.States.UpdateContextStateExtensions
Assembly: TeleFlow.Framework.Core
File(s): /_/src/TeleFlow.Framework.Core/States/UpdateContextStateExtensions.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 37
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetState(...)100%22100%
TryGetState(...)100%44100%

File(s)

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

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using TeleFlow.Framework.Updates;
 3
 4namespace TeleFlow.Framework.States;
 5
 6public static class UpdateContextStateExtensions
 7{
 8    public static UpdateState GetState(this UpdateContext context)
 9    {
 2910        ArgumentNullException.ThrowIfNull(context);
 11
 2912        if (context.TryGetState(out var state))
 13        {
 2814            return state;
 15        }
 16
 117        throw new InvalidOperationException(
 118            "State is not available for the current update. Register state storage and state middleware before using ctx
 19    }
 20
 21    public static bool TryGetState(
 22        this UpdateContext context,
 23        [NotNullWhen(true)] out UpdateState? state)
 24    {
 11225        ArgumentNullException.ThrowIfNull(context);
 26
 11227        if (context.Items.TryGetValue(UpdateStateContextKeys.State, out var value) &&
 11228            value is UpdateState updateState)
 29        {
 6030            state = updateState;
 6031            return true;
 32        }
 33
 5234        state = null;
 5235        return false;
 36    }
 37}