| | | 1 | | using AsiBackbone.Core.Audit; |
| | | 2 | | |
| | | 3 | | namespace AsiBackbone.Testing.Contracts; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Reusable contract fixture for <see cref="IDecisionReceiptSink" /> implementations. |
| | | 7 | | /// </summary> |
| | | 8 | | public abstract class DecisionReceiptSinkContract |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Creates the decision receipt sink implementation under test. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <returns>The decision receipt sink implementation to validate.</returns> |
| | | 14 | | protected abstract IDecisionReceiptSink CreateDecisionReceiptSink(); |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Creates the decision receipt supplied to the sink implementation under test. |
| | | 18 | | /// </summary> |
| | | 19 | | /// <returns>The decision receipt to write.</returns> |
| | | 20 | | protected abstract IDecisionReceipt CreateDecisionReceipt(); |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// Verifies that a decision receipt sink accepts a valid decision receipt value without weakening its required shap |
| | | 24 | | /// </summary> |
| | | 25 | | /// <param name="cancellationToken">A token that can cancel the contract validation.</param> |
| | | 26 | | /// <returns>A task that completes when the contract validation succeeds.</returns> |
| | | 27 | | public async ValueTask VerifyDecisionReceiptSinkAcceptsValidReceiptAsync(CancellationToken cancellationToken = defau |
| | | 28 | | { |
| | 6 | 29 | | IDecisionReceiptSink receiptSink = CreateDecisionReceiptSink() |
| | 6 | 30 | | ?? throw new GovernanceContractViolationException("Decision receipt sink contract must provide a sink instan |
| | 5 | 31 | | IDecisionReceipt receipt = CreateDecisionReceipt() |
| | 5 | 32 | | ?? throw new GovernanceContractViolationException("Decision receipt sink contract must provide a decision re |
| | | 33 | | |
| | 4 | 34 | | _ = GovernanceDecisionContract.VerifyDecisionReceipt(receipt, "Decision receipt sink receipt"); |
| | | 35 | | |
| | | 36 | | try |
| | | 37 | | { |
| | 4 | 38 | | await receiptSink.WriteAsync(receipt, cancellationToken).ConfigureAwait(false); |
| | 1 | 39 | | } |
| | 1 | 40 | | catch (OperationCanceledException) |
| | | 41 | | { |
| | 1 | 42 | | throw; |
| | | 43 | | } |
| | 1 | 44 | | catch (GovernanceContractViolationException) |
| | | 45 | | { |
| | 1 | 46 | | throw; |
| | | 47 | | } |
| | 1 | 48 | | catch (Exception exception) |
| | | 49 | | { |
| | 1 | 50 | | throw new GovernanceContractViolationException( |
| | 1 | 51 | | "Decision receipt sink implementations must accept a valid decision receipt during normal contract valid |
| | 1 | 52 | | exception); |
| | | 53 | | } |
| | 1 | 54 | | } |
| | | 55 | | } |