Changed the default way to modify values in store. Added basic validation to stores. Using interfaces to DI store objects.

This commit is contained in:
Tom
2025-01-16 19:49:02 +00:00
parent b00c72ec2a
commit ee3f128a9f
24 changed files with 173 additions and 61 deletions

View File

@@ -41,10 +41,29 @@ namespace HermesSocketServer.Store
protected override void OnInitialAdd(string key, Policy value)
{
ArgumentException.ThrowIfNullOrWhiteSpace(key, nameof(key));
ArgumentNullException.ThrowIfNull(value, nameof(value));
ArgumentException.ThrowIfNullOrWhiteSpace(value.UserId, nameof(value.UserId));
ArgumentOutOfRangeException.ThrowIfEqual(value.GroupId, default, nameof(value.GroupId));
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(value.Usage, nameof(value.Usage));
ArgumentOutOfRangeException.ThrowIfGreaterThan(value.Usage, 99, nameof(value.Usage));
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(value.Span, nameof(value.Span));
ArgumentOutOfRangeException.ThrowIfLessThan(value.Span, 1000, nameof(value.Span));
ArgumentOutOfRangeException.ThrowIfGreaterThan(value.Span, 86400, nameof(value.Span));
}
protected override void OnInitialModify(string key, Policy value)
protected override void OnInitialModify(string key, Policy oldValue, Policy newValue)
{
ArgumentNullException.ThrowIfNull(newValue, nameof(newValue));
ArgumentException.ThrowIfNullOrWhiteSpace(newValue.UserId, nameof(newValue.UserId));
ArgumentOutOfRangeException.ThrowIfEqual(newValue.GroupId, default, nameof(newValue.GroupId));
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(newValue.Usage, nameof(newValue.Usage));
ArgumentOutOfRangeException.ThrowIfGreaterThan(newValue.Usage, 99, nameof(newValue.Usage));
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(newValue.Span, nameof(newValue.Span));
ArgumentOutOfRangeException.ThrowIfLessThan(newValue.Span, 1000, nameof(newValue.Span));
ArgumentOutOfRangeException.ThrowIfGreaterThan(newValue.Span, 86400, nameof(newValue.Span));
ArgumentOutOfRangeException.ThrowIfNotEqual(oldValue.Id, newValue.Id, nameof(oldValue.Id));
ArgumentOutOfRangeException.ThrowIfNotEqual(oldValue.UserId, newValue.UserId, nameof(oldValue.UserId));
}
protected override void OnPostRemove(string key, Policy value)