public void SingleValue_MatchesOnlyThatValue() { var sieve = new EqualitySieve<ABusinessObject>().ForProperty(x => x.AnInt).ForValue(1); var sut = sieve.ToExpression(); sut.Compile().Invoke(ABusinessObjectWithAnIntOf1).Should().BeTrue(); sut.Compile().Invoke(ABusinessObjectWithAnIntOf2).Should().BeFalse(); sut.Compile().Invoke(ABusinessObjectWithAnIntOf3).Should().BeFalse(); }
WithInvalidValue_AndInvalidValueBehaviorSetToThrowException_ExceptionIsThrownWhenToExpressionIsCalled () { var sieve = new EqualitySieve<ABusinessObject>().ForProperty(x => x.AnInt) .WithInvalidValueBehavior(InvalidValueBehavior.ThrowInvalidSieveValueException) .ForValue("2abc"); // ReSharper disable once UnusedVariable -- used for purposes of this action only Action act = () => { var sut = sieve.ToExpression(); }; act.ShouldThrow<InvalidSieveValueException>().And.Message.Should().ContainEquivalentOf("2abc"); }
public void WithoutPropertySet_ThrowsSievePropertyNotSetException() { var sieve = new EqualitySieve<ABusinessObject, int>().ForValue(1); Action act = () => sieve.ToExpression(); act.ShouldThrow<SievePropertyNotSetException>() .And.Message.Should() .ContainEquivalentOf("try calling ForProperty"); }
WhenSpecifyingAnExceptionBeThrown_InvalidValueThrowsInvalidSieveValueExceptionWhenCallingToExpression () { const string STRING_VALUES = "7/25/2010, 12/1abc/2012"; var sieve = new EqualitySieve<ABusinessObject>().ForProperty(x => x.ADateTime) .WithInvalidValueBehavior(InvalidValueBehavior.ThrowInvalidSieveValueException) .ForValue(STRING_VALUES); // ReSharper disable once UnusedVariable -- used for purposes of this action only Action act = () => { var sut = sieve.ToExpression(); }; act.ShouldThrow<InvalidSieveValueException>() .And.Message.Should() .ContainEquivalentOf("12/1abc/2012"); }