public void Create_should_return_validator_that_prints_description_from_ToString() { // Arrange var validator = ArgumentValidator <int> .Create(this.validations, x => true, "Any Int32"); // Act var description = validator.ToString(); // Assert Assert.That(description, Is.EqualTo("<Any Int32>")); }
public void Create_should_return_validator_with_the_passed_in_validations_object() { // Arrange var validations = A.Fake <ArgumentValidatorScope <int> >(); // Act var validator = ArgumentValidator <int> .Create(validations, x => true, "foo"); // Assert Assert.That(validator.Scope, Is.SameAs(validations)); }
public void Create_should_return_validator_that_delegates_response_from_predicate( [Values(true, false)] bool predicateResponse) { // Arrange Func <int, bool> predicate = x => predicateResponse; // Act var validator = ArgumentValidator.Create(this.validations, predicate, "foo"); var isValid = validator.IsValid(1); // Assert Assert.That(isValid, Is.EqualTo(predicateResponse)); }
public void Create_should_return_validator_that_calls_predicate_when_IsValid_is_called() { // Arrange string argumentForPredicate = null; Func <string, bool> predicate = x => { argumentForPredicate = x; return(true); }; // Act var validator = ArgumentValidator <string> .Create(predicate, "foo"); validator.IsValid("argument"); // Assert Assert.That(argumentForPredicate, Is.EqualTo("argument")); }
public void Create_should_return_validator_that_calls_predicate_when_IsValid_is_called() { // Arrange string argumentForPredicate = null; Func <string, bool> predicate = x => { argumentForPredicate = x; return(true); }; var validations = A.Fake <ArgumentValidatorScope <string> >(); A.CallTo(() => validations.IsValid(A <string> .Ignored)).Returns(true); // Act var validator = ArgumentValidator <string> .Create(validations, predicate, "foo"); validator.IsValid("argument"); // Assert Assert.That(argumentForPredicate, Is.EqualTo("argument")); }
public static ArgumentValidator <FakeObject> IsThis(this ArgumentValidations <FakeObject> validations, object fakedObject) { return(ArgumentValidator <FakeObject> .Create(validations, x => x.Equals(Fake.GetFakeObject(fakedObject)), "Specified FakeObject")); }
public static ArgumentValidator <Expression> ProducesValue(this ArgumentValidations <Expression> validations, object expectedValue) { return(ArgumentValidator <Expression> .Create(validations, x => object.Equals(expectedValue, ExpressionManager.GetValueProducedByExpression(x)), "Expression that produces the value {0}".FormatInvariant(expectedValue))); }
public static ArgumentValidator <T> IsThisSequence <T>(this ArgumentValidations <T> validations, params object[] collection) where T : IEnumerable { return(ArgumentValidator <T> .Create(validations, x => x.Cast <object>().SequenceEqual(collection.Cast <object>()), "Same sequence")); }
public static ArgumentValidator <string> Contains(this ArgumentValidatorScope <string> validations, string value) { return(ArgumentValidator <string> .Create(validations, x => x.Contains(value), string.Format("Contains \"{0}\"", value))); }
public static ArgumentValidator <string> StartsWith(this ArgumentValidatorScope <string> validations, string beginning) { return(ArgumentValidator <string> .Create(validations, x => x.StartsWith(beginning), string.Format("Starts with \"{0}\"", beginning))); }
public static ArgumentValidator <string> IsLongerThan(this ArgumentValidatorScope <string> validations, int length) { return(ArgumentValidator.Create(validations, x => x.Length > length, string.Format(CultureInfo.InvariantCulture, "Longer than {0}", length))); }
public void Create_should_be_null_guarded() { // Assert NullGuardedConstraint.Assert(() => ArgumentValidator <int> .Create(this.validations, x => true, "foo")); }
public void Create_should_throw_when_description_is_an_empty_string() { // Assert Assert.Throws <ArgumentNullException>(() => ArgumentValidator <int> .Create(this.validations, x => true, string.Empty)); }
private static ArgumentValidator <T> CreateValidator <T>(this ArgumentValidatorScope <T> scope, Func <T, bool> predicate, string descriptionFormat, params object[] args) { return(ArgumentValidator.Create(scope, predicate, descriptionFormat.FormatInvariant(args))); }
private static ArgumentValidator <T> CreateValidator <T>(this ArgumentValidatorScope <T> scope, Func <T, bool> predicate, string description) { return(ArgumentValidator.Create(scope, predicate, description)); }
/// <summary> /// Validates that the specified argument is not null. /// </summary> /// <typeparam name="T">The type of the argument.</typeparam> /// <param name="validations">The validations to extend.</param> /// <returns>A validator.</returns> public static ArgumentValidator <T> IsNotNull <T>(this ArgumentValidations <T> validations) where T : class { return(ArgumentValidator <T> .Create(x => x != null, "Not NULL")); }