public void IsValidThrowsExceptionWhenOtherPropertyNotFoundTest() { var skill = Model.Create <Skill>().Set(x => x.YearLastUsed = 2015); var context = new ValidationContext(skill); var sut = new GreaterOrEqualToAttribute("NotHere"); Action action = () => sut.GetValidationResult(skill.YearLastUsed, context); action.Should().Throw <InvalidOperationException>(); }
public void IsValidReturnsSuccessWhenValueIsNullTest() { var skill = Model.Create <Skill>(); var context = new ValidationContext(skill); var sut = new GreaterOrEqualToAttribute(nameof(Skill.YearStarted)); var actual = sut.GetValidationResult(null, context); actual.Should().Be(ValidationResult.Success); }
public void IsValidReturnsSuccessWhenOtherValueIsLessOrEqualToTest(int yearStarted, int yearLastUsed) { var skill = Model.Create <Skill>().Set(x => x.YearStarted = yearStarted) .Set(x => x.YearLastUsed = yearLastUsed); var context = new ValidationContext(skill); var sut = new GreaterOrEqualToAttribute(nameof(Skill.YearStarted)); var actual = sut.GetValidationResult(skill.YearLastUsed, context); actual.Should().Be(ValidationResult.Success); }
public void IsValidReturnsFailureWhenOtherValueIsGreaterTest() { var skill = Model.Create <Skill>().Set(x => x.YearStarted = 2000).Set(x => x.YearLastUsed = 1999); var context = new ValidationContext(skill) { MemberName = nameof(Skill.YearLastUsed) }; var sut = new GreaterOrEqualToAttribute(nameof(Skill.YearStarted)); var actual = sut.GetValidationResult(skill.YearLastUsed, context); _output.WriteLine(actual.ErrorMessage); actual.Should().NotBe(ValidationResult.Success); actual.ErrorMessage.Should().NotBeNullOrWhiteSpace(); actual.MemberNames.Should().Contain(nameof(Skill.YearStarted)); actual.MemberNames.Should().Contain(nameof(Skill.YearLastUsed)); }