using MultiversalDiplomacy.Adjudicate; using MultiversalDiplomacy.Orders; using NUnit.Framework; namespace MultiversalDiplomacyTests; /// /// An object that provides a view into an order's fate during a test case. /// public class OrderReference where OrderType : Order { private TestCaseBuilder Builder { get; } /// /// The order. /// public OrderType Order { get; } /// /// The validation result for the order. Throws if validation has not occurred. /// public OrderValidation Validation { get { if (this.Builder.ValidationResults == null) { throw new InvalidOperationException("Validation has not been done yet"); } var orderValidation = this.Builder.ValidationResults.Where(v => this.Order == v.Order); if (!orderValidation.Any()) { throw new AssertionException($"Missing validation for {this.Order}"); } return orderValidation.Single(); } } /// /// The order that replaced this order, if any. Throws if validation has not occurred. /// public OrderValidation? Replacement { get { if (this.Builder.ValidationResults == null) { throw new InvalidOperationException("Validation has not been done yet"); } if (this.Order is UnitOrder unitOrder) { var replacementOrder = this.Builder.ValidationResults.Where( v => v.Order is UnitOrder uo && uo != unitOrder && uo.Unit == unitOrder.Unit); if (replacementOrder.Any()) { return replacementOrder.Single(); } } return null; } } public OrderReference(TestCaseBuilder builder, OrderType order) { this.Builder = builder; this.Order = order; } }