/// <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(); }
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; }
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; }
public bool IsApplicableTo(IFakeObjectCall fakeObjectCall) { Guard.AgainstNull(fakeObjectCall, "fakeObjectCall"); return EventCall.GetEvent(fakeObjectCall.Method) != null; }
protected abstract bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall);
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;
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)); }
/// <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); }
/// <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))); }
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; }
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); }
public static string CallToUnconfiguredMethodOfStrictFake(IFakeObjectCall call) { var callFormatter = ServiceLocator.Current.Resolve <IFakeObjectCallFormatter>(); return($"Call to unconfigured method of strict fake: {callFormatter.GetDescription(call)}."); }
/// <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; }
/// <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); }
protected abstract bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall);
/// <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)); }
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)); }
public bool IsApplicableTo(IFakeObjectCall fakeObjectCall) { return(true); }
private static string GetParametersString(IFakeObjectCall fakeObjectCall) { return fakeObjectCall.Arguments.ToCollectionString(x => GetArgumentAsString(x), ", "); }
protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall) { return(this.ExpressionMatcher.Matches(fakeObjectCall)); }
private static bool IsObjetMethod(IFakeObjectCall fakeObjectCall) { return ObjectMethodsMethodHandles.Contains(fakeObjectCall.Method.MethodHandle); }
internal bool Matches(IFakeObjectCall call) => EventCall.TryGetEventCall(call, out var eventCall) && this.Matches(eventCall);
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)); }
public static EventCall GetEventCall( IFakeObjectCall fakeObjectCall) { var eventInfo = GetEvent(fakeObjectCall.Method); return new EventCall { Event = eventInfo, CallingMethod = fakeObjectCall.Method, EventHandler = (Delegate)fakeObjectCall.Arguments[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; }
public bool Matches(IFakeObjectCall call) { return(this.builder.RuleBeingBuilt.IsApplicableTo(call)); }
/// <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;
protected override bool OnIsApplicableTo(IFakeObjectCall fakeObjectCall) { return this.ExpressionMatcher.Matches(fakeObjectCall); }
internal static ITestSession CreateSession(IFakeObjectCall arg) { return(new TestSession(Factory, _settings)); }
/// <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); }
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)); } }
private static IUnitOfWork CreateUnitOfWork(IFakeObjectCall arg) { return(new Ioc.UnitOfWork.UnitOfWork((IDbFactory)arg.FakedObject, CreateSession(null), IsolationLevel.Serializable)); }
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(); }