public void CombineThrowsIfExpressionsIsNull() { Assert .That ( () => { ExpressionHelper.Combine <UserEntity, UserDto>(null); }, Throws.InstanceOf <ArgumentNullException>() ); }
/// <inheritdoc /> public virtual Expression <Func <TSource, TDestination> > Compile() { if (Count > 0) { return(ExpressionHelper.Combine(_expressions.ToArray())); } return(null); }
/// <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)); }
public void CombineThrowsIfFirstExpressionIsOtherThanMemberInitExpressionOrNewExpression() { Assert .That ( () => { var dto = new UserDto(); ExpressionHelper .Combine <UserEntity, UserDto>(x => dto, x => new UserDto { Username = x.Username }); }, Throws.ArgumentException ); }
public void CombineThrowsNothingIfExpressionsContainsNull() { Assert .That ( () => { ExpressionHelper .Combine <UserEntity, UserDto> ( x => new UserDto { Id = x.Id }, null, x => new UserDto { Username = x.Username } ); }, Throws.Nothing ); }
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 ); }