public void Validate() { ValidationChecks.CannotBeNullOrEmpty(nameof(Id), Id); ValidationChecks.CannotBeNullOrEmpty(nameof(RecordString), RecordString); ValidationChecks.CannotBeNull(nameof(RecordDateTime), RecordDateTime); ValidationChecks.CannotBeNull(nameof(RecordOrdinal), RecordOrdinal); }
public static void Assert(HandHistory hand, ValidationChecks checks = ValidationChecks.ALL) { string reason = null; if (!Check(hand, checks, out reason)) { throw new HandIntegrityException(reason); } }
public static bool Check(HandHistory hand, ValidationChecks checks, out string reason) { reason = null; if (checks.HasFlag(ValidationChecks.TOTAL_POT)) { if (!CheckTotalPot(hand, out reason)) { return(false); } } if (checks.HasFlag(ValidationChecks.STREET_ORDER)) { if (!CheckStreetOrder(hand.HandActions, out reason)) { return(false); } } if (checks.HasFlag(ValidationChecks.BLIND_ORDER)) { if (!CheckBlindOrder(hand.HandActions, out reason)) { return(false); } } if (checks.HasFlag(ValidationChecks.ACTION_ORDER)) { if (!CheckActionOrder(hand.HandActions, out reason)) { return(false); } } if (checks.HasFlag(ValidationChecks.ACTION_TOTAL_AMOUNTS)) { if (!CheckActionTotalAmounts(hand.Players, hand.HandActions, out reason)) { return(false); } } if (checks.HasFlag(ValidationChecks.PLAYERLIST_SITOUT_WITH_ACTIONS)) { if (!CheckPlayerListSitoutWithActions(hand.Players, hand.HandActions, out reason)) { return(false); } } if (checks.HasFlag(ValidationChecks.PLAYERLIST_SITIN_WITHOUT_ACTIONS)) { if (!CheckPlayerListSitinWithoutActions(hand.Players, hand.HandActions, out reason)) { return(false); } } return(true); }
private bool ValidateNumeric(ValidationChecks format, bool isEmpty) { var expectNumber = (format & ValidationChecks.Numeric) != 0; if (expectNumber && !isEmpty && !IsNumeric()) { MarkInvalid(FieldValidationExtensions.GetNumericErrorMessage(Field)); return(false); } return(true); }
private bool ValidateNonEmpty(ValidationChecks format, out bool isEmpty) { var expectNonEmpty = (format & ValidationChecks.NonEmpty) != 0; isEmpty = string.IsNullOrWhiteSpace(GetFieldValue()); if (expectNonEmpty && isEmpty) { MarkInvalid(FieldValidationExtensions.GetNonEmptyErrorMessage(Field)); return(false); } return(true); }
private void ValidateDischargeValues() { if (string.IsNullOrEmpty(StageUnits)) { ThrowIfNotNull(nameof(StageAtStart), StageAtStart); ThrowIfNotNull(nameof(StageAtEnd), StageAtEnd); } ValidationChecks.CannotBeNull(nameof(Discharge), Discharge); ValidationChecks.CannotBeNullOrEmpty(nameof(DischargeUnits), DischargeUnits); ValidationChecks.CannotBeNullOrEmpty(nameof(ChannelName), ChannelName); ValidationChecks.CannotBeNullOrEmpty(nameof(WidthUnits), WidthUnits); ValidationChecks.CannotBeNullOrEmpty(nameof(AreaUnits), AreaUnits); ValidationChecks.CannotBeNullOrEmpty(nameof(VelocityUnits), VelocityUnits); }
private bool ValidateEqualsPattern(ValidationChecks format) { var expectEquality = (format & ValidationChecks.EqualsPattern) != 0; var pattern = FieldValidationExtensions.GetPattern(Field); if (expectEquality && pattern != null && !GetFieldValue().Equals(pattern, StringComparison.Ordinal)) { MarkInvalid(FieldValidationExtensions.GetDefaultErrorMessage(Field)); return(false); } return(true); }
private bool ValidateMinLength(ValidationChecks format) { var expectMinLength = (format & ValidationChecks.MinLength) != 0; if (expectMinLength && GetMinLength() > GetFieldValue().Length) { var messageFormat = FieldValidationExtensions.GetMinLengthErrorMessage(Field) ?? ""; var message = string.Format(messageFormat, GetMinLength()); MarkInvalid(message); return(false); } return(true); }
private bool ValidateMatchesRegexPattern(ValidationChecks format) { var expectPattern = (format & ValidationChecks.MatchesRegexPattern) != 0; var pattern = FieldValidationExtensions.GetPattern(Field); if (expectPattern && pattern != null && !Regex.IsMatch(GetFieldValue(), pattern)) { var messageFormat = FieldValidationExtensions.GetPatternErrorMessage(Field) ?? ""; var message = string.Format(messageFormat, pattern); MarkInvalid(message); return(false); } return(true); }
public void Validate() { ValidationChecks.CannotBeNullOrEmpty(nameof(LocationIdentifier), LocationIdentifier); if (Discharge.HasValue) { ValidateDischargeValues(); } else { ValidateEmptyDischarge(); } ValidateReading(); ThrowIfNoDischargeOrReadings(); ValidationChecks .MustBeAValidInterval(nameof(MeasurementStartDateTime), MeasurementStartDateTime, nameof(MeasurementEndDateTime), MeasurementEndDateTime); }
private AppendedResults ParseJson(string jsonText) { JsonConfig.Configure(); try { var results = jsonText.FromJson <AppendedResults>(); if (results.FrameworkAssemblyQualifiedName == null && results.PluginAssemblyQualifiedTypeName == null) { return(null); } ValidationChecks.CannotBeNull(nameof(results.AppendedVisits), results.AppendedVisits); return(results); } catch (SerializationException) { return(null); } }
public void Calculate(string input) { PrepareData(ref input); var validation = new ValidationChecks(); IsCalculationSuccessful = validation.ApplyAllChecks(input, out string message); CalculationResultMessage = message; if (IsCalculationSuccessful) { try { var calculation = new Calculation(input); ResultText = string.Concat(resultTextPrefix, calculation.Result.ToString()); } catch (Exception e) { IsCalculationSuccessful = false; CalculationResultMessage = e.Message; } } }
private bool ValidateIncludesDigits(ValidationChecks format) { var expectDigits = (format & ValidationChecks.IncludesDigits) != 0; if (expectDigits) { var fieldValue = GetFieldValue(); for (int i = 0; i < fieldValue.Length; i++) { if (char.IsDigit(fieldValue, i)) { return(true); } } MarkInvalid(FieldValidationExtensions.GetDefaultErrorMessage(Field)); return(false); } return(true); }
private bool ValidateNoDoubles(ValidationChecks format) { var expectNoDoubles = (format & ValidationChecks.IncludesSymbol) != 0; if (expectNoDoubles) { var fieldValue = GetFieldValue(); for (int i = 0; i < fieldValue.Length; i++) { for (int j = 1; i + j * 2 < fieldValue.Length; j++) { var isDouble = true; for (int k = 0; k < j; k++) { if (fieldValue[i + k] != fieldValue[i + j + k]) { isDouble = false; break; } } if (isDouble) { MarkInvalid(FieldValidationExtensions.GetDefaultErrorMessage(Field)); return(false); } } } } return(true); }
/// <summary> /// Sets the Format property. This dependency property /// indicates the formats to validate for. /// </summary> public static void SetFormat(DependencyObject d, ValidationChecks value) { d.SetValue(FormatProperty, value); }
/// <summary> /// Sets the Format property. This dependency property /// indicates the formats to validate for. /// </summary> public static void SetFormat(DependencyObject d, ValidationChecks value) { d.SetValue(FormatProperty, value); }
public void ReturnFalseGivenValueLengthGreaterThan12InLength(string value) { var result = ValidationChecks.MPANIsValid(value); Assert.False(result, $"{value} should not be mpan"); }
protected HandIntegrityBaseTests(ValidationChecks checks) { this.checks = checks; }