private static IExpectationContext GetParentOf(IExpectationContext child) { var propInfo = child.GetType() .GetPublicInstanceProperty(nameof(IExpectationContext.Parent)); return(propInfo?.GetValue(child) as IExpectationContext); }
internal static T2 Create <T1, T2>(T1 actual, IExpectationContext <T1> parent) where T2 : IExpectationContext <T1> { var result = (T2)Activator.CreateInstance(typeof(T2), actual); result.Parent = parent; return(result); }
private static IStringPropertyContinuation More( this IExpectationContext <string> context ) { return(ContinuationFactory.Create <string, StringPropertyContinuation>( (context as ICanAddMatcher <string>).GetActual(), context )); }
private static bool TryReadIsNegatedOn(IExpectationContext current) { var propInfo = current .GetType() .GetPublicInstanceProperties() .FirstOrDefault(pi => pi.Name == "isnegated"); return((bool?)propInfo?.GetValue(current) ?? false); }
internal static T2 Create <T1, T2>( T1 actual, IExpectationContext <T1> parent, Action <T2> afterConstruction = null ) where T2 : IExpectationContext <T1> { var result = (T2)Activator.CreateInstance(typeof(T2), actual); result.TypedParent = parent; afterConstruction?.Invoke(result); return(result); }
/// <summary> /// Returns the negated status for the expectation context being operated on /// </summary> /// <param name="context"></param> /// <returns></returns> internal static bool IsNegated(this IExpectationContext context) { var current = context; var negated = false; while (current != null) { if (IsNegatedPrivate(current)) { negated = !negated; } current = GetParentOf(current); } return(negated); }
private static bool IsNegatedPrivate(IExpectationContext current) { var propInfo = current.GetType().GetProperty(nameof(ExpectationBase.IsNegated)); if (propInfo is null) { return(false); } try { return((bool)propInfo.GetValue(current)); } catch { return(false); } }
internal static T2 Create <T1, T2>( Func <T1> actualGenerator, IExpectationContext <T1> parent, Action <T2> afterConstruction = null ) where T2 : IExpectationContext <T1> { var result = (T2)Activator.CreateInstance(typeof(T2), actualGenerator); result.TypedParent = parent; afterConstruction?.Invoke(result); if (result is IResetNegation && result.IsNegated()) { result.Negate(); } parent.CopyAllMetadataTo(result); return(result); }
public StringContainContinuation(ICanAddMatcher <string> continuation) { _expectationContext = continuation as IExpectationContext <string>; }
public InstanceContinuation(Func <Type> actualFetcher, IExpectationContext originalParent) : base(actualFetcher) { Parent = originalParent; }
private static bool IsNegatedPrivate(IExpectationContext current) { var concrete = current as ExpectationBase; return(concrete?.IsNegated ?? TryReadIsNegatedOn(current)); }
public InstanceContinuation(Type actual, IExpectationContext originalParent) { Actual = actual; Parent = originalParent; }