public void ShouldBeValid() { var validationErrors = new List <ValidationResult>(); var sut = new PwmSettings { MinTemp = 1, MaxTemp = 10, MaxPwm = 255, MinPwm = 2, MinStart = 10, }; var isValid = Validator.TryValidateObject(sut, new ValidationContext(sut), validationErrors, true); Assert.True(isValid); }
public void ShouldHaveInvalidLessThan(int minTemp, int maxTemp, int maxPwm, int minPwm, int minStart) { var validationErrors = new List <ValidationResult>(); var sut = new PwmSettings { MinTemp = minTemp, MaxTemp = maxTemp, MaxPwm = maxPwm, MinPwm = minPwm, MinStart = minStart, }; var isValid = Validator.TryValidateObject(sut, new ValidationContext(sut), validationErrors, true); Assert.False(isValid); Assert.Contains( validationErrors, error => error.ErrorMessage.Contains("Value should be less") ); }