mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-29 19:57:09 +02:00
Add comments for ScenarioStateStore related code (#1433)
This commit is contained in:
@@ -1,42 +1,48 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace WireMock.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an in-memory implementation of the <see cref="IScenarioStateStore" /> interface for managing scenario state objects by name.
|
||||
/// </summary>
|
||||
public class InMemoryScenarioStateStore : IScenarioStateStore
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, ScenarioState> _scenarios = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGet(string name, [NotNullWhen(true)] out ScenarioState? state)
|
||||
{
|
||||
return _scenarios.TryGetValue(name, out state);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyList<ScenarioState> GetAll()
|
||||
{
|
||||
return _scenarios.Values.ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool ContainsKey(string name)
|
||||
{
|
||||
return _scenarios.ContainsKey(name);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryAdd(string name, ScenarioState scenarioState)
|
||||
{
|
||||
return _scenarios.TryAdd(name, scenarioState);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ScenarioState AddOrUpdate(string name, Func<string, ScenarioState> addFactory, Func<string, ScenarioState, ScenarioState> updateFactory)
|
||||
{
|
||||
return _scenarios.AddOrUpdate(name, addFactory, updateFactory);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ScenarioState? Update(string name, Action<ScenarioState> updateAction)
|
||||
{
|
||||
if (_scenarios.TryGetValue(name, out var state))
|
||||
@@ -48,13 +54,15 @@ public class InMemoryScenarioStateStore : IScenarioStateStore
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryRemove(string name)
|
||||
{
|
||||
return _scenarios.TryRemove(name, out _);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Clear()
|
||||
{
|
||||
_scenarios.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user