public static ValidationResult Validate(object value) { var s = value as string; if (s is null) { return(new ValidationResult("Invalid object type")); } if (s.Length == 0) { return(ValidationResult.Success); } try { var referenceRanges = Parser.Parse(s); var invalidReferences = new List <string>(); foreach (var range in referenceRanges) { if (!BibleDetails.IsValidBibleReferenceRange(range)) { invalidReferences.Add(range.ToFriendlyString()); } } if (invalidReferences.Count > 0) { var errorMessage = "Invalid Bible references:\n" + string.Join(", ", invalidReferences); return(new ValidationResult(errorMessage)); } } catch (InvalidOperationException e) { return(new ValidationResult("Unable to parse bible reference string. Details: " + e.Message)); } return(ValidationResult.Success); }
public void IsValidBibleReferenceRangeInvalidReferenceWithNoEndReference() { var refA = new BibleReference { Book = BibleBook.Exodus, Chapter = 40, Verse = 0 }; var range = new BibleReferenceRange { First = refA }; Assert.IsFalse(BibleDetails.IsValidBibleReferenceRange(range)); }
public void IsValidBibleReferenceRangeValidReferenceToInvalidReference() { var refA = new BibleReference { Book = BibleBook.Exodus, Chapter = 40, Verse = 1 }; var refB = new BibleReference { Book = BibleBook.Exodus, Chapter = 40, Verse = 39 }; var range = new BibleReferenceRange { First = refA, Last = refB }; Assert.IsFalse(BibleDetails.IsValidBibleReferenceRange(range)); }
public void IsValidBibleReferenceRangeValidReferenceToEarlierValidReference() { var refA = new BibleReference { Book = BibleBook.Deuteronomy }; var refB = new BibleReference { Book = BibleBook.Genesis }; var range = new BibleReferenceRange { First = refA, Last = refB }; Assert.IsFalse(BibleDetails.IsValidBibleReferenceRange(range)); }