Example #1
0
        private static IExpectationContext GetParentOf(IExpectationContext child)
        {
            var propInfo = child.GetType()
                           .GetPublicInstanceProperty(nameof(IExpectationContext.Parent));

            return(propInfo?.GetValue(child) as IExpectationContext);
        }
Example #2
0
        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);
        }
Example #3
0
 private static IStringPropertyContinuation More(
     this IExpectationContext <string> context
     )
 {
     return(ContinuationFactory.Create <string, StringPropertyContinuation>(
                (context as ICanAddMatcher <string>).GetActual(),
                context
                ));
 }
Example #4
0
        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);
        }
Example #6
0
        /// <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);
        }
Example #7
0
        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);
            }
        }
Example #8
0
        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>;
 }
Example #10
0
 public InstanceContinuation(Func <Type> actualFetcher, IExpectationContext originalParent)
     : base(actualFetcher)
 {
     Parent = originalParent;
 }
Example #11
0
        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;
 }