|
| 1 | +namespace sigtran.net.Core.Utilities; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Identifies the result of an external interoperability evidence item. |
| 5 | +/// </summary> |
| 6 | +public enum SigtranInteropEvidenceResult |
| 7 | +{ |
| 8 | + /// <summary>The evidence item passed.</summary> |
| 9 | + Passed, |
| 10 | + |
| 11 | + /// <summary>The evidence item failed.</summary> |
| 12 | + Failed, |
| 13 | + |
| 14 | + /// <summary>The evidence item is informational only.</summary> |
| 15 | + Informational |
| 16 | +} |
| 17 | + |
| 18 | +/// <summary> |
| 19 | +/// Describes one external interoperability evidence item. |
| 20 | +/// </summary> |
| 21 | +public sealed class SigtranInteropEvidenceItem |
| 22 | +{ |
| 23 | + /// <summary>Creates an interoperability evidence item.</summary> |
| 24 | + /// <param name="id">The stable evidence id.</param> |
| 25 | + /// <param name="peerStack">The peer stack or product name.</param> |
| 26 | + /// <param name="scenario">The tested scenario.</param> |
| 27 | + /// <param name="traceReference">The trace or artifact reference.</param> |
| 28 | + /// <param name="result">The evidence result.</param> |
| 29 | + public SigtranInteropEvidenceItem( |
| 30 | + string id, |
| 31 | + string peerStack, |
| 32 | + string scenario, |
| 33 | + string traceReference, |
| 34 | + SigtranInteropEvidenceResult result) |
| 35 | + { |
| 36 | + Id = string.IsNullOrWhiteSpace(id) ? throw new ArgumentException("Evidence id is required.", nameof(id)) : id; |
| 37 | + PeerStack = string.IsNullOrWhiteSpace(peerStack) ? throw new ArgumentException("Peer stack is required.", nameof(peerStack)) : peerStack; |
| 38 | + Scenario = string.IsNullOrWhiteSpace(scenario) ? throw new ArgumentException("Scenario is required.", nameof(scenario)) : scenario; |
| 39 | + TraceReference = string.IsNullOrWhiteSpace(traceReference) ? throw new ArgumentException("Trace reference is required.", nameof(traceReference)) : traceReference; |
| 40 | + Result = result; |
| 41 | + } |
| 42 | + |
| 43 | + /// <summary>The stable evidence id.</summary> |
| 44 | + public string Id { get; } |
| 45 | + |
| 46 | + /// <summary>The peer stack or product name.</summary> |
| 47 | + public string PeerStack { get; } |
| 48 | + |
| 49 | + /// <summary>The tested scenario.</summary> |
| 50 | + public string Scenario { get; } |
| 51 | + |
| 52 | + /// <summary>The trace or artifact reference.</summary> |
| 53 | + public string TraceReference { get; } |
| 54 | + |
| 55 | + /// <summary>The evidence result.</summary> |
| 56 | + public SigtranInteropEvidenceResult Result { get; } |
| 57 | +} |
| 58 | + |
| 59 | +/// <summary> |
| 60 | +/// Stores external interoperability evidence in deterministic order. |
| 61 | +/// </summary> |
| 62 | +public sealed class SigtranInteropEvidenceRegistry |
| 63 | +{ |
| 64 | + private readonly List<SigtranInteropEvidenceItem> _items = []; |
| 65 | + |
| 66 | + /// <summary>Adds an evidence item.</summary> |
| 67 | + /// <param name="item">The evidence item.</param> |
| 68 | + public void Add(SigtranInteropEvidenceItem item) |
| 69 | + { |
| 70 | + ArgumentNullException.ThrowIfNull(item); |
| 71 | + if (_items.Any(existing => string.Equals(existing.Id, item.Id, StringComparison.OrdinalIgnoreCase))) |
| 72 | + { |
| 73 | + throw new InvalidOperationException($"Interop evidence '{item.Id}' already exists."); |
| 74 | + } |
| 75 | + |
| 76 | + _items.Add(item); |
| 77 | + } |
| 78 | + |
| 79 | + /// <summary>Returns a deterministic evidence snapshot.</summary> |
| 80 | + /// <returns>The evidence snapshot.</returns> |
| 81 | + public IReadOnlyList<SigtranInteropEvidenceItem> Snapshot() |
| 82 | + { |
| 83 | + return _items.ToArray(); |
| 84 | + } |
| 85 | + |
| 86 | + /// <summary>Returns whether all evidence items passed and at least one item exists.</summary> |
| 87 | + /// <returns>True when the registry has passing evidence; otherwise false.</returns> |
| 88 | + public bool HasPassingEvidence() |
| 89 | + { |
| 90 | + return _items.Count > 0 && _items.All(static item => item.Result == SigtranInteropEvidenceResult.Passed); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +/// <summary> |
| 95 | +/// Provides external interoperability evidence inventory helpers. |
| 96 | +/// </summary> |
| 97 | +public static class SigtranInteropEvidence |
| 98 | +{ |
| 99 | + /// <summary>Creates the current external evidence registry.</summary> |
| 100 | + /// <returns>The current external evidence registry.</returns> |
| 101 | + public static SigtranInteropEvidenceRegistry CreateCurrentRegistry() |
| 102 | + { |
| 103 | + return new SigtranInteropEvidenceRegistry(); |
| 104 | + } |
| 105 | +} |
0 commit comments