private void EnsureStage(AvailabilityTestScope.Stage requiredA, AvailabilityTestScope.Stage requiredB) { int requiredStageA = (int)requiredA, requiredStageB = (int)requiredB; int currStage = _currentStage; if (currStage != requiredStageA && currStage != requiredStageB) { throw new InvalidOperationException($"For this operation {nameof(AvailabilityTestScope)}.{nameof(CurrentStage)}" + $" is required to be \'{requiredA}\' (={requiredStageA}) or \'{requiredB}\' (={requiredStageB})," + $" but it is actually \'{((Stage) currStage)}\' (={currStage})."); } }
private void TransitionStage(AvailabilityTestScope.Stage from, AvailabilityTestScope.Stage to) { int fromStage = (int)from, toStage = (int)to; int prevStage = Interlocked.CompareExchange(ref _currentStage, toStage, fromStage); if (prevStage != fromStage) { throw new InvalidOperationException($"Error transitioning {nameof(AvailabilityTestScope)}.{nameof(CurrentStage)}" + $" to \'{to}\' (={toStage}): Previous {nameof(CurrentStage)} was expected to" + $" be \'{from}\' (={fromStage}), but it was actually \'{((Stage) prevStage)}\' (={prevStage})."); } }