public void CountDecimalDigits__CountsWithNoDecimalPlaces() { // arrange var testNumber = 1; // act var result = utils.CountDecimalDigits(testNumber); // assert: Assert.IsTrue(result == 0); }
// Custom Validation public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { // No future dates if (Date > MaxDate) { yield return(new ValidationResult("Date cannot be in the future.", new string[] { "DateWritten" })); } // No dates less than defined minimum if (Date < MinDate) { yield return(new ValidationResult("Only dates within the last 20 years are allowed.", new string[] { "DateWritten" })); } var utils = new UtilityService(); if (utils.CountDecimalDigits(Amount) > 2) { yield return(new ValidationResult("Amount can only contain 2 decimal places.", new string[] { "Amount" })); } }