Exemple #1
0
        public void Should_BeAnd_When_AndIsCalled()
        {
            // Arrange
            ISpecification <object> spec = new TrueSpecification <object>();

            // Act
            spec = spec.And(new TrueSpecification <object>());

            // Assert
            spec.Should().BeOfType <AndSpecification <object> >();
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public Expression <Func <T, bool> > SatisfiedBy()
        {
            ISpecification <T> filter = new TrueSpecification <T>();

            if (_properties == null)
            {
                return(filter.SatisfiedBy());
            }

            foreach (var property in _properties.Where(f => !string.IsNullOrWhiteSpace(f.Value)))
            {
                var propertyInfo = typeof(T).GetProperties().Where(p => p.CanWrite).SingleOrDefault(t => t.Name.ToUpper() == property.Field.ToUpper());

                if (propertyInfo == null)
                {
                    throw new ArgumentNullException(nameof(propertyInfo));
                }

                filter = filter.And(new PropertyContainsOrEqualSpecification <T>(propertyInfo, property.Value));
            }


            return(filter.SatisfiedBy());
        }