/// <summary>
        /// Matches the specified call against the expression.
        /// </summary>
        /// <param name="call">The call to match.</param>
        /// <returns>True if the call is matched by the expression.</returns>
        public virtual bool Matches(IFakeObjectCall call)
        {
            Guard.AgainstNull(call, "call");

            return this.InvokesSameMethodOnTarget(call.FakedObject.GetType(), call.Method, this.Method)
                && this.ArgumentsMatches(call.Arguments);
        }
        public void SetUp()
        {
            this.firstCall = CreateFakedFakeObjectCall();
            this.secondCall = MakeEqualCopy(this.firstCall);

            this.comparer = new FakeCallEqualityComparer();
        }
Exemplo n.º 3
0
 protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return
         this.argumentsPredicate(fakeObjectCall.Arguments) &&
             (this.ApplicableToMembersWithReturnType == null
             || (this.ApplicableToMembersWithReturnType == fakeObjectCall.Method.ReturnType)
             || (this.ApplicableToAllNonVoidReturnTypes && fakeObjectCall.Method.ReturnType != typeof(void)));
 }
 private static IEnumerable<CancellationToken> GetCanceledTokens(IFakeObjectCall call)
 {
     return call.Method.GetParameters()
         .Select((param, index) => new { param, index })
         .Where(x => x.param.ParameterType == typeof(CancellationToken))
         .Select(x => (CancellationToken)call.Arguments[x.index])
         .Where(token => token.IsCancellationRequested);
 }
        private void GetFakeErrors(IFakeObjectCall obj)
        {
            var errors = (Dictionary<string, ErrorRecord>)obj.Arguments[2];

            for (var i = 0; i < _given.ExpectedErrorCount; i++)
            {
                errors.Add(i.ToString(), Random.ErrorRecord);
            }
        }
        /// <summary>
        /// Gets a human readable description of the specified
        /// fake object call.
        /// </summary>
        /// <param name="call">The call to get a description for.</param>
        /// <returns>A description of the call.</returns>
        public string GetDescription(IFakeObjectCall call)
        {
            var builder = new StringBuilder();

            builder
                .Append(this.fakeManagerAccessor.GetFakeManager(call.FakedObject).FakeObjectType)
                .Append(".");

            AppendMethodName(builder, call.Method);

            this.AppendArgumentsList(builder, call);

            return builder.ToString();
        }
 public FakeObjectCallEventArgs(IFakeObjectCall fakeObjectCall)
 {
     this.FakeObjectCall = fakeObjectCall;
 }
Exemplo n.º 8
0
 private static IEnumerable<object> GetOutputArgumentsForCall(IFakeObjectCall call)
 {
     return
         from valueAndParameterInfo in call.Method.GetParameters().Zip(
             call.Arguments.AsEnumerable(),
             (parameter, argument) => new { parameter.ParameterType, Argument = argument })
         where valueAndParameterInfo.ParameterType.IsByRef
         select valueAndParameterInfo.Argument;
 }
        private static IFakeObjectCall MakeEqualCopy(IFakeObjectCall call)
        {
            var copy = A.Fake<IFakeObjectCall>();

            A.CallTo(() => copy.Method).Returns(call.Method);
            A.CallTo(() => copy.Arguments).Returns(call.Arguments);
            A.CallTo(() => copy.FakedObject).Returns(call.FakedObject);

            return copy;
        }
Exemplo n.º 10
0
            public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
            {
                Guard.AgainstNull(fakeObjectCall, "fakeObjectCall");

                return EventCall.GetEvent(fakeObjectCall.Method) != null;
            }
Exemplo n.º 11
0
 protected abstract bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall);
Exemplo n.º 12
0
 protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return this.methodInfoManager.WillInvokeSameMethodOnTarget(fakeObjectCall.FakedObject.GetType(), fakeObjectCall.Method, this.ApplicableToMethod)
         && this.IsApplicableToArguments(fakeObjectCall.Arguments);
 }
 private bool IsPropertyGetter(IFakeObjectCall fakeObjectCall)
 {
     return(this.propertyGetter != null &&
            this.propertyGetter.GetBaseDefinition().Equals(fakeObjectCall.Method.GetBaseDefinition()) &&
            this.Indices.SequenceEqual(fakeObjectCall.Arguments));
 }
 public override bool IsApplicableTo(IFakeObjectCall fakeObjectCall) =>
 GetCanceledToken(fakeObjectCall).HasValue;
Exemplo n.º 15
0
 public abstract bool IsApplicableTo(IFakeObjectCall fakeObjectCall);
 protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return(true);
 }
 /// <summary>
 /// Gets wether this interceptor is applicable to the specified
 /// call, if true is returned the Apply-method of the interceptor will
 /// be called.
 /// </summary>
 /// <param name="fakeObjectCall">The call to check for applicability.</param>
 /// <returns>True if the interceptor is applicable.</returns>
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return(this.wrappedRule.IsApplicableTo(fakeObjectCall));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Gets if this rule is applicable to the specified call.
 /// </summary>
 /// <param name="fakeObjectCall">The call to validate.</param>
 /// <returns>True if the rule applies to the call.</returns>
 public virtual bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return(this.wherePredicates.All(x => x.Matches(fakeObjectCall)) &&
            this.OnIsApplicableTo(fakeObjectCall));
 }
        /// <summary>
        /// Gets the description of a call to a fake object.
        /// </summary>
        /// <param name="fakeObjectCall">The call to describe.</param>
        /// <returns>A description of the call.</returns>
        internal static string GetDescription(this IFakeObjectCall fakeObjectCall)
        {
            var method = fakeObjectCall.Method;

            return($"{method.DeclaringType}.{method.Name}({GetParametersString(fakeObjectCall)})");
        }
 private static IFakeObjectGenerator GetFakeObjectGeneratorForCall(IFakeObjectCall call)
 {
     return(FakeObjectGeneratorFactory.CreateGenerationCommand(call.Method.ReturnType, null, true));
 }
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return IsObjetMethod(fakeObjectCall);
 }
Exemplo n.º 22
0
        /// <summary>
        /// Gets the description of a call to a fake object.
        /// </summary>
        /// <param name="fakeObjectCall">The call to describe.</param>
        /// <returns>A description of the call.</returns>
        internal static string GetDescription(this IFakeObjectCall fakeObjectCall)
        {
            var method = fakeObjectCall.Method;

            return("{0}.{1}({2})".FormatInvariant(method.DeclaringType.FullName, method.Name, GetParametersString(fakeObjectCall)));
        }
Exemplo n.º 23
0
 private static IEnumerable<object> GetOutputArgumentsForCall(IFakeObjectCall call)
 {
     return
         from valueAndParameterInfo in call.Method.GetParameters().Zip(call.Arguments.AsEnumerable())
         where valueAndParameterInfo.Item1.ParameterType.IsByRef
         select valueAndParameterInfo.Item2;
 }
Exemplo n.º 24
0
 private static string GetParametersString(IFakeObjectCall fakeObjectCall)
 {
     return(fakeObjectCall.Arguments.ToCollectionString(x => GetArgumentAsString(x), ", "));
 }
 private bool IsPropertyGetter(IFakeObjectCall fakeObjectCall)
 {
     return this.propertyGetter != null &&
            this.propertyGetter.GetBaseDefinition().Equals(fakeObjectCall.Method.GetBaseDefinition()) &&
            this.Indices.SequenceEqual(fakeObjectCall.Arguments);
 }
Exemplo n.º 26
0
        public static string CallToUnconfiguredMethodOfStrictFake(IFakeObjectCall call)
        {
            var callFormatter = ServiceLocator.Current.Resolve <IFakeObjectCallFormatter>();

            return($"Call to unconfigured method of strict fake: {callFormatter.GetDescription(call)}.");
        }
Exemplo n.º 27
0
 /// <summary>
 /// Gets whether this interceptor is applicable to the specified
 /// call, if true is returned the Apply-method of the interceptor will
 /// be called.
 /// </summary>
 /// <param name="fakeObjectCall">The call to check for applicability.</param>
 /// <returns>True if the interceptor is applicable.</returns>
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return true;
 }
Exemplo n.º 28
0
        /// <summary>
        /// Gets if this rule is applicable to the specified call.
        /// </summary>
        /// <param name="fakeObjectCall">The call to validate.</param>
        /// <returns>True if the rule applies to the call.</returns>
        public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
        {
            Guard.IsNotNull(fakeObjectCall, "fakeObjectCall");

            return(this.OnIsApplicableTo(fakeObjectCall));
        }
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return this.IsPropertySetter(fakeObjectCall) || this.IsPropertyGetter(fakeObjectCall);
 }
Exemplo n.º 30
0
 protected abstract bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall);
Exemplo n.º 31
0
 /// <summary>
 /// Gets whether this rule is applicable to the specified
 /// call. If <c>true</c> is returned then <see cref="Apply" /> will be called.
 /// </summary>
 /// <param name="fakeObjectCall">The call to check for applicability.</param>
 /// <returns><c>true</c> if the call is a property setter.</returns>
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return(fakeObjectCall != null && IsSetter(fakeObjectCall.Method));
 }
 protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return(this.methodInfoManager.WillInvokeSameMethodOnTarget(fakeObjectCall.FakedObject.GetType(), fakeObjectCall.Method, this.ApplicableToMethod) &&
            this.IsApplicableToArguments(fakeObjectCall.Arguments));
 }
            public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
            {
                Guard.AgainstNull(fakeObjectCall, nameof(fakeObjectCall));

                return(PropertyBehaviorRule.IsPropertySetter(fakeObjectCall.Method));
            }
Exemplo n.º 34
0
 protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     this.OnIsApplicableToWasCalled = true;
     return(this.ReturnValueFromOnIsApplicableTo);
 }
        public static T GetArgument <T>(this IFakeObjectCall call, int argumentIndex)
        {
            Guard.AgainstNull(call, nameof(call));

            return(call.Arguments.Get <T>(argumentIndex));
        }
Exemplo n.º 36
0
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return(true);
 }
Exemplo n.º 37
0
 private static string GetParametersString(IFakeObjectCall fakeObjectCall)
 {
     return fakeObjectCall.Arguments.ToCollectionString(x => GetArgumentAsString(x), ", ");
 }
Exemplo n.º 38
0
 protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return(this.ExpressionMatcher.Matches(fakeObjectCall));
 }
 private static bool IsObjetMethod(IFakeObjectCall fakeObjectCall)
 {
     return ObjectMethodsMethodHandles.Contains(fakeObjectCall.Method.MethodHandle);
 }
Exemplo n.º 40
0
 internal bool Matches(IFakeObjectCall call) => EventCall.TryGetEventCall(call, out var eventCall) && this.Matches(eventCall);
Exemplo n.º 41
0
 protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return
         this.argumentsPredicate(fakeObjectCall.Arguments) &&
             (this.ApplicableToMembersWithReturnType == null || this.ApplicableToMembersWithReturnType.Equals(fakeObjectCall.Method.ReturnType));
 }
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return(PropertyBehaviorRule.IsPropertyGetter(fakeObjectCall.Method) && TypeIsFakeable(fakeObjectCall.Method.ReturnType));
 }
Exemplo n.º 43
0
                public static EventCall GetEventCall(
                    IFakeObjectCall fakeObjectCall)
                {
                    var eventInfo = GetEvent(fakeObjectCall.Method);

                    return new EventCall
                               {
                                   Event = eventInfo, 
                                   CallingMethod = fakeObjectCall.Method, 
                                   EventHandler = (Delegate)fakeObjectCall.Arguments[0],
                               };
                }
Exemplo n.º 44
0
 /// <summary>
 /// Determines whether this rule applies to the intercepted call.
 /// This rule applies to all calls.
 /// </summary>
 /// <param name="fakeObjectCall">The call to check.</param>
 /// <returns><c>true</c> all the time.</returns>
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall) => true;
 protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     this.OnIsApplicableToWasCalled = true;
     return this.ReturnValueFromOnIsApplicableTo;
 }
Exemplo n.º 46
0
 public bool Matches(IFakeObjectCall call)
 {
     return(this.builder.RuleBeingBuilt.IsApplicableTo(call));
 }
Exemplo n.º 47
0
 /// <summary>
 /// Gets if this rule is applicable to the specified call.
 /// </summary>
 /// <param name="fakeObjectCall">The call to validate.</param>
 /// <returns>True if the rule applies to the call.</returns>
 public virtual bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return this.wherePredicates.All(x => x.Item1.Invoke(fakeObjectCall))
         && this.OnIsApplicableTo(fakeObjectCall);
 }
 public static bool MatchesEndpointMethodByName(this IFakeObjectCall fake, string name) =>
 fake.Method.Name == name;
Exemplo n.º 49
0
 protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return this.ExpressionMatcher.Matches(fakeObjectCall);
 }
Exemplo n.º 50
0
 internal static ITestSession CreateSession(IFakeObjectCall arg)
 {
     return(new TestSession(Factory, _settings));
 }
Exemplo n.º 51
0
 /// <summary>
 /// Gets whether this interceptor is applicable to the specified
 /// call, if true is returned the Apply-method of the interceptor will
 /// be called.
 /// </summary>
 /// <param name="fakeObjectCall">The call to check for applicability.</param>
 /// <returns>True if the interceptor is applicable.</returns>
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return this.wrappedRule.IsApplicableTo(fakeObjectCall);
 }
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return PropertyBehaviorRule.IsPropertySetter(fakeObjectCall.Method);
 }
            public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
            {
                Guard.AgainstNull(fakeObjectCall, "fakeObjectCall");

                return PropertyBehaviorRule.IsPropertySetter(fakeObjectCall.Method);
            }
Exemplo n.º 54
0
 public bool IsApplicableTo(IFakeObjectCall fakeObjectCall)
 {
     return(IsObjetMethod(fakeObjectCall));
 }
 private bool IsPropertySetter(IFakeObjectCall fakeObjectCall)
 {
     return this.propertySetter != null && this.propertySetter.GetBaseDefinition().Equals(fakeObjectCall.Method.GetBaseDefinition());
 }
        private void AppendArgumentsList(StringBuilder builder, IFakeObjectCall call)
        {
            var allArguments = GetArgumentValueInfos(call);
            var argumentsForArgumentList = GetArgumentsForArgumentsList(allArguments, call.Method);

            if (argumentsForArgumentList.Length > 0 || !IsPropertyGetterOrSetter(call.Method))
            {
                AppendArgumentListPrefix(builder, call.Method);

                this.AppendArguments(builder, argumentsForArgumentList);

                AppendArgumentListSuffix(builder, call.Method);
            }

            if (IsPropertySetter(call.Method))
            {
                builder.Append(" = ");
                builder.Append(this.argumentValueFormatter.GetArgumentValueAsString(allArguments[allArguments.Length - 1].ArgumentValue));
            }
        }
Exemplo n.º 57
0
 private static IUnitOfWork CreateUnitOfWork(IFakeObjectCall arg)
 {
     return(new Ioc.UnitOfWork.UnitOfWork((IDbFactory)arg.FakedObject, CreateSession(null), IsolationLevel.Serializable));
 }
Exemplo n.º 58
0
 private static bool IsObjetMethod(IFakeObjectCall fakeObjectCall)
 {
     return(ObjectMethodsMethodHandles.Contains(fakeObjectCall.Method.MethodHandle));
 }
 public void OnBeforeCallIntercepted(IFakeObjectCall call)
 {
 }
 private static ArgumentValueInfo[] GetArgumentValueInfos(IFakeObjectCall call)
 {
     return
         (from argument in
             call.Method.GetParameters()
                 .Zip(call.Arguments, (parameter, value) => new { parameter.Name, Value = value })
             select new ArgumentValueInfo
             {
                 ArgumentName = argument.Name,
                 ArgumentValue = argument.Value
             }).ToArray();
 }