public void SelectsExistentialQuantification() { var spec = new IntegerGreaterThanZero().ForAny(); Assert.IsTrue(spec.IsSatisfiedBy(new[] { -1, -2, -3, -4, 0, 1, 2 })); Assert.IsFalse(spec.IsSatisfiedBy(new[] { -1, -2, -3, -4, 0 })); }
public void ImplicitConversionFromSpecification() { var spec = new IntegerGreaterThanZero(); Expression<Func<int, bool>> expression = spec; Assert.That(expression, Is.SameAs(spec.Criteria)); }
public void SelectsUniversalQuantification() { var spec = new IntegerGreaterThanZero().ForAll(); Assert.IsTrue(spec.IsSatisfiedBy(new[] { 1, 1, 2, 3, 4, 5, 6 })); Assert.IsFalse(spec.IsSatisfiedBy(new[] { 3, 32, 589, 0, 11 })); }
public void IsSatisfiedBy_Uses_Criteria() { var spec = new IntegerGreaterThanZero(); Assert.That(spec.IsSatisfiedBy(1), Is.True); Assert.That(spec.IsSatisfiedBy(0), Is.False); Assert.That(spec.IsSatisfiedBy(-1), Is.False); }
public void AndGeneric_ReturnsConjunction() { var spec = new IntegerGreaterThanZero(); var conjoinedSpec = spec.And<IntegerLessThanZero>(); Assert.That(conjoinedSpec, Is.TypeOf<Conjunction<int>>()); Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec)); Assert.That(conjoinedSpec, Has.Property("Right").TypeOf<IntegerLessThanZero>()); }
public void SelectsInverse() { var spec = new IntegerGreaterThanZero(); var negatedSpec = new Negation<int>(spec); Assert.That(negatedSpec.IsSatisfiedBy(1), Is.False); Assert.That(negatedSpec.IsSatisfiedBy(0), Is.True); Assert.That(negatedSpec.IsSatisfiedBy(-1), Is.True); }
public void SelectsDisjunction() { var spec1 = new IntegerGreaterThanZero(); var spec2 = new IntegerEqualToZero(); var disjoinedSpec = new Disjunction<int>(spec1, spec2); Assert.That(disjoinedSpec.IsSatisfiedBy(1), Is.True); Assert.That(disjoinedSpec.IsSatisfiedBy(0), Is.True); Assert.That(disjoinedSpec.IsSatisfiedBy(-1), Is.False); }
public void SelectsConjunction() { var spec1 = new IntegerGreaterThanZero(); var spec2 = new IntegerPredicate(i => i > -1); var conjoinedSpec = new Conjunction<int>(spec1, spec2); Assert.That(conjoinedSpec.IsSatisfiedBy(1), Is.True); Assert.That(conjoinedSpec.IsSatisfiedBy(0), Is.False); Assert.That(conjoinedSpec.IsSatisfiedBy(-1), Is.False); }
public void SelectsConversion() { var spec = new IntegerGreaterThanZero(); var converter = (Expression<Func<double, int>>)(d => Math.Sign(d)); var convertedSpec = new Conversion<double, int>(spec, converter); Assert.That(convertedSpec.IsSatisfiedBy(1), Is.True); Assert.That(convertedSpec.IsSatisfiedBy(0), Is.False); Assert.That(convertedSpec.IsSatisfiedBy(-1), Is.False); }
public void Matching_IQueryable_Uses_Specification() { var spec = new IntegerGreaterThanZero(); var candidates = (new[] { -1, 0, 1, 2, 3 }).AsQueryable(); var queryable = candidates.Matching(spec); foreach(var i in queryable) { Assert.That(spec.IsSatisfiedBy(i)); } }
public void AndNot_ReturnsConjunction_WithNegationRight() { var spec1 = new IntegerGreaterThanZero(); var spec2 = new IntegerLessThanZero(); var conjoinedSpec = spec1.AndNot(spec2); Assert.That(conjoinedSpec, Is.TypeOf<Conjunction<int>>()); Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec1)); Assert.That(conjoinedSpec, Has.Property("Right").TypeOf<Negation<int>>()); Assert.That(conjoinedSpec, Has.Property("Right").With.Property("Inner").EqualTo(spec2)); }
public void Filter_IQueryable_Uses_Criteria() { var spec = new IntegerGreaterThanZero(); var candidates = (new[] { -1, 0, 1, 2, 3 }).AsQueryable(); var queryable = spec.Filter(candidates); foreach(var i in queryable) { Assert.That(spec.IsSatisfiedBy(i)); } }
public void AndConvert_ReturnsConjunctionWithConversion() { var spec1 = new IntegerGreaterThanZero(); var spec2 = Specify.EqualTo(DateTime.Now); var converter = (Expression<Func<DateTime, int>>)(dt => dt.Minute); var conjoinedSpec = spec2.And(converter, spec1); Assert.That(conjoinedSpec, Is.TypeOf<Conjunction<DateTime>>()); Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec2)); Assert.That(conjoinedSpec, Has.Property("Right").InstanceOf<Conversion<DateTime, int>>()); Assert.That(conjoinedSpec, Has.Property("Right").With.Property("Inner").EqualTo(spec1)); Assert.That(conjoinedSpec, Has.Property("Right").With.Property("Converter").EqualTo(converter)); }
public void ForOne_ReturnsUniqueQuantification() { var spec = new IntegerGreaterThanZero(); var anySpec = spec.ForOne(); Assert.That(anySpec, Is.TypeOf<UniqueQuantification<int>>()); Assert.That(anySpec, Has.Property("Inner").EqualTo(spec)); }
public void AndOperator_ReturnsConjunction() { var spec1 = new IntegerGreaterThanZero(); var spec2 = new IntegerLessThanZero(); var conjoinedSpec = spec1 & spec2; Assert.That(conjoinedSpec, Is.TypeOf<Conjunction<int>>()); Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec1)); Assert.That(conjoinedSpec, Has.Property("Right").EqualTo(spec2)); }
public void Xor_ReturnsExclusiveDisjunction() { var spec1 = new IntegerGreaterThanZero(); var spec2 = new IntegerLessThanZero(); var conjoinedSpec = spec1.Xor(spec2); Assert.That(conjoinedSpec, Is.TypeOf<ExclusiveDisjunction<int>>()); Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec1)); Assert.That(conjoinedSpec, Has.Property("Right").EqualTo(spec2)); }
public void XorNotGeneric_ReturnsExclusiveDisjunction_WithNegationRight() { var spec = new IntegerGreaterThanZero(); var conjoinedSpec = spec.XorNot<IntegerLessThanZero>(); Assert.That(conjoinedSpec, Is.TypeOf<ExclusiveDisjunction<int>>()); Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec)); Assert.That(conjoinedSpec, Has.Property("Right").TypeOf<Negation<int>>()); Assert.That(conjoinedSpec, Has.Property("Right").With.Property("Inner").TypeOf<IntegerLessThanZero>()); }
public void Not_ReturnsNegation() { var spec = new IntegerGreaterThanZero(); var negatedSpec = spec.IsFalse(); Assert.That(negatedSpec, Is.TypeOf<Negation<int>>()); Assert.That(negatedSpec, Has.Property("Inner").EqualTo(spec)); }
public void Convert_ReturnsConversion() { var spec = new IntegerGreaterThanZero(); var converter = (Expression<Func<double, int>>)(d => (int)d); var convertedSpec = spec.From(converter); Assert.That(convertedSpec, Is.TypeOf<Conversion<double, int>>()); Assert.That(convertedSpec, Has.Property("Inner").EqualTo(spec)); Assert.That(convertedSpec, Has.Property("Converter").EqualTo(converter)); }
public void ForAny_ReturnsExistentialQuantification() { var spec = new IntegerGreaterThanZero(); var anySpec = spec.ForAny(); Assert.That(anySpec, Is.TypeOf<ExistentialQuantification<int>>()); Assert.That(anySpec, Has.Property("Inner").EqualTo(spec)); }