protected virtual AssertPair <TSrc, TDst> InternalShouldBeEqual <TType>(Expression <Func <TSrc, TType> > srcExp, Expression <Func <TSrc, TType> > srcAlias, Expression <Func <TDst, TType> > dstExp, Expression <Func <TDst, TType> > dstAlias) { var srcProp = Src.GetExpressionValue <TSrc, TType>(srcExp); var dstProp = Dst.GetExpressionValue <TDst, TType>(dstExp); var srcPropAlias = Src.GetExpressionValue <TSrc, TType>(srcAlias); var dstPropAlias = Dst.GetExpressionValue <TDst, TType>(dstAlias); var isValid = object.Equals(srcProp.Value, dstProp.Value); if (srcProp.Value is byte[] && dstProp.Value is byte[]) { isValid = (srcProp.Value as byte[]).SequenceEqual((dstProp.Value as byte[])); } InvokeOnPropertyValidated(this, new OnPropertyValidatedEventArgs { Result = new PropertyValidationResult { Tag = this.Tag, Src = srcPropAlias, Dst = dstPropAlias, IsValid = isValid } }); return(this); }
public AssertPair <TSrc, TDst> ShouldBeEqual(Expression <Func <TSrc, Guid> > srcExp) { var srcInfo = Src.GetExpressionValue(srcExp); var pX = Expression.Parameter(typeof(TDst)); var body = Expression.Property(pX, srcInfo.Name); var lambda = Expression.Lambda <Func <TDst, Guid> >(body, pX); return(ShouldBeEqual(srcExp, lambda)); }
public AssertPair <TSrc, TDst> ShouldBeEqualIfHasValue(Expression <Func <TSrc, bool?> > srcExp, Expression <Func <TDst, bool?> > dstExp) { var value = Src.GetExpressionValue(srcExp).Value as bool?; if (value.HasValue) { return(ShouldBeEqual(srcExp, dstExp)); } return(SkipProperty(srcExp, "Property is null or empty.")); }
public AssertPair <TSrc, TDst> ShouldBeEqualIfNotNullOrEmpty( Expression <Func <TSrc, string> > srcExp, Expression <Func <TDst, string> > dstExp) { var value = Src.GetExpressionValue(srcExp).Value as string; if (!string.IsNullOrEmpty(value)) { return(ShouldBeEqual(srcExp, dstExp)); } return(SkipProperty(srcExp)); }
protected virtual AssertPair <TSrc, TDst> InternalSkipProperty <TType>(Expression <Func <TSrc, TType> > srcPropExp, string message) { var srcProp = Src.GetExpressionValue <TSrc, TType>(srcPropExp); InvokeOnPropertyValidated(this, new OnPropertyValidatedEventArgs { Result = new PropertyValidationResult { Tag = this.Tag, Src = srcProp, Dst = null, IsValid = true, Message = message } }); return(this); }
public AssertPair <TSrc, TDst> ShouldBeEndOf(Expression <Func <TSrc, string> > srcExp, Expression <Func <TSrc, string> > srcAlias, Expression <Func <TDst, string> > dstExp, Expression <Func <TDst, string> > dstAlias) { var srcProp = Src.GetExpressionValue <TSrc, string>(srcExp); var dstProp = Dst.GetExpressionValue <TDst, string>(dstExp); var srcPropAlias = Src.GetExpressionValue <TSrc, string>(srcAlias); var dstPropAlias = Dst.GetExpressionValue <TDst, string>(dstAlias); InvokeOnPropertyValidated(this, new OnPropertyValidatedEventArgs { Result = new PropertyValidationResult { Tag = this.Tag, Src = srcPropAlias, Dst = dstPropAlias, IsValid = dstProp.Value.ToString().EndsWith(srcProp.Value.ToString()) } }); return(this); }