mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-28 19:58: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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,6 +175,13 @@ public class WireMockServerSettings
|
||||
[JsonIgnore]
|
||||
public IFileSystemHandler FileSystemHandler { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the store used to persist scenario state information.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The scenario state store manages the storage and retrieval of state data associated with scenarios.
|
||||
/// By default, an in-memory implementation is used, but this property can be set to a custom implementation to support alternative storage mechanisms such as databases or distributed caches.
|
||||
/// </remarks>
|
||||
[PublicAPI]
|
||||
[JsonIgnore]
|
||||
public IScenarioStateStore ScenarioStateStore { get; set; } = new InMemoryScenarioStateStore();
|
||||
@@ -258,7 +265,7 @@ public class WireMockServerSettings
|
||||
/// Whether to accept any client certificate
|
||||
/// </summary>
|
||||
public bool AcceptAnyClientCertificate { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Defines the global IWebhookSettings to use.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user