예제 #1
0
    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);
    }
예제 #2
0
    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")
            );
    }