Esempio n. 1
0
 public void CombineThrowsIfExpressionsIsNull()
 {
     Assert
     .That
     (
         () => { ExpressionHelper.Combine <UserEntity, UserDto>(null); },
         Throws.InstanceOf <ArgumentNullException>()
     );
 }
Esempio n. 2
0
        /// <inheritdoc />
        public virtual Expression <Func <TSource, TDestination> > Compile()
        {
            if (Count > 0)
            {
                return(ExpressionHelper.Combine(_expressions.ToArray()));
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Returns a specification query strategy for getting an entity by it's primary key values.
        /// </summary>
        /// <param name="source">The repository conventions.</param>
        /// <param name="keyValues">The primary key values.</param>
        /// <returns>The new specification.</returns>
        public static ISpecificationQueryStrategy <T> GetByPrimaryKeySpecification <T>([NotNull] this IRepositoryConventions source, [NotNull] params object[] keyValues) where T : class
        {
            Guard.NotEmpty(keyValues, nameof(keyValues));

            var propInfos = source.GetPrimaryKeyPropertyInfos <T>();

            if (keyValues.Length != propInfos.Length)
            {
                throw new ArgumentException(Resources.EntityPrimaryKeyValuesLengthMismatch, nameof(keyValues));
            }

            var lambda = ExpressionHelper.Combine <T>(propInfos, keyValues, (left, right) => Expression.AndAlso(left, right));

            return(new SpecificationQueryStrategy <T>(lambda));
        }
Esempio n. 4
0
        public void CombineThrowsIfFirstExpressionIsOtherThanMemberInitExpressionOrNewExpression()
        {
            Assert
            .That
            (
                () =>
            {
                var dto = new UserDto();

                ExpressionHelper
                .Combine <UserEntity, UserDto>(x => dto, x => new UserDto {
                    Username = x.Username
                });
            },
                Throws.ArgumentException
            );
        }
Esempio n. 5
0
 public void CombineThrowsNothingIfExpressionsContainsNull()
 {
     Assert
     .That
     (
         () =>
     {
         ExpressionHelper
         .Combine <UserEntity, UserDto>
         (
             x => new UserDto {
             Id = x.Id
         },
             null,
             x => new UserDto {
             Username = x.Username
         }
         );
     },
         Throws.Nothing
     );
 }
Esempio n. 6
0
        public void CombineThrowsIfExpressionsContainsNonMemberInitExpression()
        {
            Assert
            .That
            (
                () =>
            {
                var dto = new UserDto();

                ExpressionHelper
                .Combine <UserEntity, UserDto>
                (
                    x => new UserDto {
                    Id = x.Id
                },
                    x => dto,
                    x => new UserDto {
                    Username = x.Username
                }
                );
            },
                Throws.ArgumentException
            );
        }