Пример #1
0
        private static IExpectationContext GetParentOf(IExpectationContext child)
        {
            var propInfo = child.GetType()
                           .GetPublicInstanceProperty(nameof(IExpectationContext.Parent));

            return(propInfo?.GetValue(child) as IExpectationContext);
        }
Пример #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);
        }
Пример #3
0
 private static IStringPropertyContinuation More(
     this IExpectationContext <string> context
     )
 {
     return(ContinuationFactory.Create <string, StringPropertyContinuation>(
                (context as ICanAddMatcher <string>).GetActual(),
                context
                ));
 }
Пример #4
0
        private static bool TryReadIsNegatedOn(IExpectationContext current)
        {
            var propInfo = current
                           .GetType()
                           .GetPublicInstanceProperties()
                           .FirstOrDefault(pi => pi.Name == "isnegated");

            return((bool?)propInfo?.GetValue(current) ?? false);
        }
Пример #5
0
        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);
        }
Пример #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);
        }
Пример #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);
            }
        }
Пример #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>;
 }
Пример #10
0
 public InstanceContinuation(Func <Type> actualFetcher, IExpectationContext originalParent)
     : base(actualFetcher)
 {
     Parent = originalParent;
 }
Пример #11
0
        private static bool IsNegatedPrivate(IExpectationContext current)
        {
            var concrete = current as ExpectationBase;

            return(concrete?.IsNegated ?? TryReadIsNegatedOn(current));
        }
Пример #12
0
 public InstanceContinuation(Type actual, IExpectationContext originalParent)
 {
     Actual = actual;
     Parent = originalParent;
 }