< Summary

Information
Class: TeleFlow.Storage.Memory.MemoryStateStore
Assembly: TeleFlow.Storage.Memory
File(s): /_/src/TeleFlow.Storage.Memory/MemoryStateStore.cs
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 41
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
.ctor()100%11100%
GetStateAsync(...)100%11100%
SetStateAsync(...)100%11100%
ClearStateAsync(...)100%11100%

File(s)

/_/src/TeleFlow.Storage.Memory/MemoryStateStore.cs

#LineLine coverage
 1using System.Collections.Concurrent;
 2using TeleFlow.Framework.States;
 3
 4namespace TeleFlow.Storage.Memory;
 5
 6public sealed class MemoryStateStore : IStateStore
 7{
 368    private readonly ConcurrentDictionary<StateKey, string> _states = new();
 9
 10    public ValueTask<string?> GetStateAsync(
 11        StateKey key,
 12        CancellationToken cancellationToken = default)
 13    {
 4914        cancellationToken.ThrowIfCancellationRequested();
 15
 4816        _states.TryGetValue(key, out var state);
 4817        return ValueTask.FromResult(state);
 18    }
 19
 20    public ValueTask SetStateAsync(
 21        StateKey key,
 22        string state,
 23        CancellationToken cancellationToken = default)
 24    {
 4125        cancellationToken.ThrowIfCancellationRequested();
 4026        ArgumentException.ThrowIfNullOrWhiteSpace(state);
 27
 3928        _states[key] = state;
 3929        return ValueTask.CompletedTask;
 30    }
 31
 32    public ValueTask ClearStateAsync(
 33        StateKey key,
 34        CancellationToken cancellationToken = default)
 35    {
 1336        cancellationToken.ThrowIfCancellationRequested();
 37
 1238        _states.TryRemove(key, out _);
 1239        return ValueTask.CompletedTask;
 40    }
 41}