public void ConstructorSetsCriteria() { var criteria = new AndCriteria(sampleCriteria1, sampleCriteria2); Assert.Contains(sampleCriteria1, criteria.Criteria); Assert.Contains(sampleCriteria2, criteria.Criteria); Assert.Equal(2, criteria.Criteria.Count); }
/// <summary> /// Rewrite an <see cref="AndCriteria" /> as a <see cref="BoolCriteria" />. /// </summary> /// <param name="and"><see cref="AndCriteria" /> to rewrite.</param> /// <returns><see cref="BoolCriteria" /> with the criteria from the And mapped into Must.</returns> static BoolCriteria Rewrite(AndCriteria and) { var should = and.Criteria.OfType <OrCriteria>().ToList(); var mustNot = and.Criteria.OfType <NotCriteria>().ToList(); var must = and.Criteria.Except(should).Except(mustNot); return(new BoolCriteria(must.Select(Compensate), should.SelectMany(c => c.Criteria).Select(Compensate), mustNot.Select(c => c.Criteria).Select(Compensate))); }
/// <summary> /// Rewrite an <see cref="AndCriteria" /> as a <see cref="BoolCriteria" />. /// </summary> /// <param name="and"><see cref="AndCriteria" /> to rewrite.</param> /// <returns><see cref="BoolCriteria" /> with the criteria from the And mapped into Must.</returns> private static BoolCriteria Rewrite(AndCriteria and) { var should = and.Criteria.OfType<OrCriteria>().ToList(); var mustNot = and.Criteria.OfType<NotCriteria>().ToList(); var must = and.Criteria.Except(should).Except(mustNot); return new BoolCriteria(must.Select(Compensate), should.SelectMany(c => c.Criteria).Select(Compensate), mustNot.Select(c => c.Criteria).Select(Compensate)); }
/// <summary> /// Reduce a <see cref="AndCriteria" /> that might contain a <see cref="ConstantCriteria" />. /// </summary> /// <param name="andCriteria"><see cref="AndCriteria" /> to be reduced.</param> /// <returns>Reduced criteria.</returns> /// <remarks> /// Trues will be removed, falses will replace the entire And with a false. /// </remarks> private static ICriteria Reduce(AndCriteria andCriteria) { if (andCriteria.Criteria.Contains(ConstantCriteria.False)) return ConstantCriteria.False; return AndCriteria .Combine(andCriteria .Criteria .Select(Reduce) .Where(c => c != ConstantCriteria.True && c != null) .ToArray()); }
/// <summary> /// Rewrite an <see cref="AndCriteria" /> as a <see cref="BoolCriteria" />. /// </summary> /// <param name="and"><see cref="AndCriteria" /> to rewrite.</param> /// <returns><see cref="BoolCriteria" /> with the criteria from the And mapped into Must.</returns> static BoolCriteria Rewrite(AndCriteria and) { var mustNot = and.Criteria.OfType <NotCriteria>().ToList(); var orCriteria = and.Criteria.OfType <OrCriteria>().ToArray(); var canFlattenOrCriteria = orCriteria.Length == 1; var shouldCriteria = (canFlattenOrCriteria ? orCriteria.SelectMany(o => o.Criteria) : Enumerable.Empty <OrCriteria>()).ToList(); var must = and.Criteria.Except(mustNot).Except(shouldCriteria); return(new BoolCriteria(must.Select(Compensate), shouldCriteria, mustNot.Select(c => c.Criteria).Select(Compensate))); }
/// <summary> /// Reduce a <see cref="AndCriteria" /> that might contain a <see cref="ConstantCriteria" />. /// </summary> /// <param name="andCriteria"><see cref="AndCriteria" /> to be reduced.</param> /// <returns>Reduced criteria.</returns> /// <remarks> /// Trues will be removed, falses will replace the entire And with a false. /// </remarks> static ICriteria Reduce(AndCriteria andCriteria) { if (andCriteria.Criteria.Contains(ConstantCriteria.False)) { return(ConstantCriteria.False); } return(AndCriteria .Combine(andCriteria .Criteria .Select(Reduce) .Where(c => c != ConstantCriteria.True && c != null) .ToArray())); }
/// <summary> /// Rewrite an <see cref="AndCriteria" /> as a <see cref="BoolCriteria" />. /// </summary> /// <param name="and"><see cref="AndCriteria" /> to rewrite.</param> /// <returns><see cref="BoolCriteria" /> with the criteria from the And mapped into Must.</returns> static BoolCriteria Rewrite(AndCriteria and) { var mustNot = and.Criteria.OfType<NotCriteria>().ToList(); var orCriteria = and.Criteria.OfType<OrCriteria>().ToArray(); var canFlattenOrCriteria = orCriteria.Length == 1; var shouldCriteria = (canFlattenOrCriteria ? orCriteria.SelectMany(o => o.Criteria) : Enumerable.Empty<OrCriteria>()).ToList(); var must = and.Criteria.Except(mustNot).Except(shouldCriteria); return new BoolCriteria(must.Select(Compensate), shouldCriteria, mustNot.Select(c => c.Criteria).Select(Compensate)); }
public void NamePropertyIsAnd() { var criteria = new AndCriteria(); Assert.Equal("and", criteria.Name); }