コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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)));
        }
コード例 #3
0
        /// <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));
        }
コード例 #4
0
        /// <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());
        }
コード例 #5
0
        /// <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)));
        }
コード例 #6
0
        /// <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()));
        }
コード例 #7
0
        /// <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));
        }
コード例 #8
0
        public void NamePropertyIsAnd()
        {
            var criteria = new AndCriteria();

            Assert.Equal("and", criteria.Name);
        }