src/Kingdom.OrTools.Sat.Parameters.Tests/ParameterTestFixtureBase.cs
/// <summary>
/// Verifies that Each Parameter Renders Correctly.
/// </summary>
/// <param name="parameter"></param>
/// <param name="valueOrItemType"></param>
/// <param name="value"></param>
/// <param name="rendered"></param>
/// <param name="ordinal"></param>
/// <param name="precision"></param>
/// <exception cref="InvalidOperationException">Thrown when <paramref name="parameter"/>
/// and <paramref name="value"/> cannot be reconciled.</exception>
Verifies that Each Parameter Renders Correctly.
Verifies that Each Parameter Renders Correctly .
[Theory, ClassData(typeof(IndividualParameterTestCases))]
        public void Each_Parameter_Renders_Correctly(IParameter parameter, Type valueOrItemType, object value, string rendered, long ordinal, int? precision)
        {
            const int defaultPrecision = 0;
            valueOrItemType.AssertNotNull();
            value.AssertNotNull();
            ordinal.AssertTrue(x => x > 0L);
            rendered.AssertNotNull().AssertNotEmpty();
            switch (parameter.AssertNotNull().AssertEqual(ordinal, x => x.Ordinal))
            {
                case IParameter<bool> boolParam when value is bool boolValue:
                    VerifyParameter(boolParam, boolValue, valueOrItemType, rendered);
                    break;
                case IParameter<int> intParam when value is int intValue:
                    VerifyParameter(intParam, intValue, valueOrItemType, rendered);
                    break;
                case IParameter<long> longParam when value is long longValue:
                    VerifyParameter(longParam, longValue, valueOrItemType, rendered);
                    break;
                case IParameter<Month> monthParam when value is Month monthValue:
                    VerifyParameter(monthParam, monthValue, valueOrItemType, rendered);
                    break;
                case IParameter<AnnotatedWeekday> weekdayParam when value is AnnotatedWeekday weekdayValue:
                    VerifyParameter(weekdayParam, weekdayValue, valueOrItemType, rendered);
                    break;
                case IParameter<double> doubleParam when value is double doubleValue:
                    VerifyParameter(doubleParam, doubleValue, precision.AssertNotNull() ?? defaultPrecision, valueOrItemType, rendered);
                    break;
                case IRepeatedParameter<bool> boolParam when value is IEnumerable<bool> boolValues:
                    VerifyRepeatedParameter(boolParam, FilterValues(boolValues), valueOrItemType, rendered);
                    break;
                case IRepeatedParameter<int> intParam when value is IEnumerable<int> intValues:
                    VerifyRepeatedParameter(intParam, FilterValues(intValues), valueOrItemType, rendered);
                    break;
                case IRepeatedParameter<long> longParam when value is IEnumerable<long> longValues:
                    VerifyRepeatedParameter(longParam, FilterValues(longValues), valueOrItemType, rendered);
                    break;
                case IRepeatedParameter<Month> monthParam when value is IEnumerable<Month> monthValues:
                    VerifyRepeatedParameter(monthParam, FilterValues(monthValues), valueOrItemType, rendered);
                    break;
                case IRepeatedParameter<AnnotatedWeekday> weekdayParam when value is IEnumerable<AnnotatedWeekday> weekdayValues:
                    VerifyRepeatedParameter(weekdayParam, FilterValues(weekdayValues), valueOrItemType, rendered);
                    break;
                case IRepeatedParameter<double> doubleParam when value is IEnumerable<double> doubleValues:
                    VerifyRepeatedParameter(doubleParam, FilterValues(doubleValues), precision.AssertNotNull() ?? defaultPrecision, valueOrItemType, rendered);
                    break;
                default:
                    string message = null;
                    string RenderValue(object x) => x is bool
                        ? $"{x}".ToLower()
                        : x is double y
                            ? $"{y:R}"
                            : $"{x}";
                    if (value is IEnumerable enumerableValue)
                    {
                        var renderedValue = Join(", ", Enumerate(enumerableValue).Select(RenderValue));
                        message = $"Repeated `{parameter.GetType().FullName}´ ({valueOrItemType.FullName}) with"
                                  + $" `{nameof(value)}´ [{renderedValue}] is an unexpected combination.";
                    }
                    string GetSingleParameterMessage()
                    {
                        return $"Single `{parameter.GetType().FullName}´ ({valueOrItemType.FullName}) with"
                               + $" `{nameof(value)}´ ({RenderValue(value)}) is an unexpected combination.";
                    }
                    throw new InvalidOperationException(message ?? GetSingleParameterMessage());
            }
        }
[ Theory , ClassData ( typeof ( IndividualParameterTestCases ) ) ] public void Each_Parameter_Renders_Correctly ( IParameter parameter , Type valueOrItemType , object value , string rendered , long ordinal , int ? precision ) { const int defaultPrecision = 0 ; valueOrItemType . AssertNotNull ( ) ; value . AssertNotNull ( ) ; ordinal . AssertTrue ( x => x > 0L ) ; rendered . AssertNotNull ( ) . AssertNotEmpty ( ) ; switch ( parameter . AssertNotNull ( ) . AssertEqual ( ordinal , x => x . Ordinal ) ) { case IParameter < bool > boolParam when value is bool boolValue : VerifyParameter ( boolParam , boolValue , valueOrItemType , rendered ) ; break ; case IParameter < int > intParam when value is int intValue : VerifyParameter ( intParam , intValue , valueOrItemType , rendered ) ; break ; case IParameter < long > longParam when value is long longValue : VerifyParameter ( longParam , longValue , valueOrItemType , rendered ) ; break ; case IParameter < Month > monthParam when value is Month monthValue : VerifyParameter ( monthParam , monthValue , valueOrItemType , rendered ) ; break ; case IParameter < AnnotatedWeekday > weekdayParam when value is AnnotatedWeekday weekdayValue : VerifyParameter ( weekdayParam , weekdayValue , valueOrItemType , rendered ) ; break ; case IParameter < double > doubleParam when value is double doubleValue : VerifyParameter ( doubleParam , doubleValue , precision . AssertNotNull ( ) ?? defaultPrecision , valueOrItemType , rendered ) ; break ; case IRepeatedParameter < bool > boolParam when value is IEnumerable < bool > boolValues : VerifyRepeatedParameter ( boolParam , FilterValues ( boolValues ) , valueOrItemType , rendered ) ; break ; case IRepeatedParameter < int > intParam when value is IEnumerable < int > intValues : VerifyRepeatedParameter ( intParam , FilterValues ( intValues ) , valueOrItemType , rendered ) ; break ; case IRepeatedParameter < long > longParam when value is IEnumerable < long > longValues : VerifyRepeatedParameter ( longParam , FilterValues ( longValues ) , valueOrItemType , rendered ) ; break ; case IRepeatedParameter < Month > monthParam when value is IEnumerable < Month > monthValues : VerifyRepeatedParameter ( monthParam , FilterValues ( monthValues ) , valueOrItemType , rendered ) ; break ; case IRepeatedParameter < AnnotatedWeekday > weekdayParam when value is IEnumerable < AnnotatedWeekday > weekdayValues : VerifyRepeatedParameter ( weekdayParam , FilterValues ( weekdayValues ) , valueOrItemType , rendered ) ; break ; case IRepeatedParameter < double > doubleParam when value is IEnumerable < double > doubleValues : VerifyRepeatedParameter ( doubleParam , FilterValues ( doubleValues ) , precision . AssertNotNull ( ) ?? defaultPrecision , valueOrItemType , rendered ) ; break ; default : string message = null ; string RenderValue ( object x ) => x is bool ? $" { x } " . ToLower ( ) : x is double y ? $" { y : } " : $" { x } " ; if ( value is IEnumerable enumerableValue ) { var renderedValue = Join ( " " , Enumerate ( enumerableValue ) . Select ( RenderValue ) ) ; message = $" Repeated ` { parameter . GetType ( ) . FullName } ´ ({ v alueOrItemType. F ullName} )  with" + $"  ` { nameof ( value ) } ´ [{ r enderedValue} ]  is an unexpected combination." ; } string GetSingleParameterMessage ( ) { return $" Single ` { parameter . GetType ( ) . FullName } ´ ({ v alueOrItemType. F ullName} )  with" + $"  ` { nameof ( value ) } ´ ({ R enderValue( v alue) } )  is an unexpected combination." ; } throw new InvalidOperationException ( message ?? GetSingleParameterMessage ( ) ) ; } }
Verifies that Each Parameter Renders Correctly.
Verifies that Each Parameter Renders Correctly .
// Borderline repeating ourselves here, but it is not terrible.
Thrown when
and  cannot be reconciled.
Thrown when and cannot be reconciled .
parameter
IParameter
None
valueOrItemType
Type
None
value
object
None
rendered
string
None
ordinal
long
None
precision
int?
None