private static IExpectation BuildParamExpectation(IInvocation invocation, MethodInfo method) { ArgManager.CheckMethodSignature(method); IExpectation expectation = new ConstraintsExpectation(invocation, ArgManager.GetAllConstraints(), new Range(1, null)); expectation.OutRefParams = ArgManager.GetAllReturnValues(); return(expectation); }
/// <summary> /// Add a method call for this state' mock. /// </summary> /// <param name="invocation">The invocation for this method</param> /// <param name="method">The method that was called</param> /// <param name="args">The arguments this method was called with</param> public object MethodCall(IInvocation invocation, MethodInfo method, params object[] args) { try { AssertPreviousMethodIsClose(); repository.lastMockedObject = mockedObject; MockRepository.lastRepository = repository; IExpectation expectation; // Has the Arg class been used? if (ArgManager.HasBeenUsed) { expectation = expectationBuilder.BuildParamExpectation(invocation, method); } else { expectation = expectationBuilder.BuildDefaultExpectation(invocation, method, args, GetDefaultCallCountRangeExpectation); } RhinoMocks.Logger.Log(string.Format("{0} -> {1} ", expectation.ErrorMessage, expectation.GetType())); repository.Recorder.Record(mockedObject, method, expectation); LastExpectation = expectation; methodCallsCount++; RhinoMocks.Logger.LogRecordedExpectation(invocation, expectation); object returnValue; if (TryCreateReturnValue(expectation, out returnValue)) { return(returnValue); } return(ReturnValueUtil.DefaultValue(method.ReturnType, invocation)); } finally { // Consume the Arg constraints only once, and reset it after each call. // this is in the finally block to make sure that an exeption does not // make subsequent unit tests fail. ArgManager.Clear(); } }
/// <summary> /// Evaluate an equal constraint for <see cref="IComparable"/>. /// </summary> /// <param name="obj">The object the parameter should equal to</param> public T Equal(object obj) { obj = ConvertObjectTypeToMatch(obj); ArgManager.AddInArgument(Is.Equal(obj)); return(default(T)); }
/// <summary> /// Evaluate a greater-than-or-equal constraint for <see cref="IComparable"/>. /// </summary> /// <param name="objToCompare">The object the parameter should be greater than or equal to</param> public T GreaterThanOrEqual(IComparable objToCompare) { objToCompare = ConvertObjectTypeToMatch(objToCompare); ArgManager.AddInArgument(Is.GreaterThanOrEqual(objToCompare)); return(default(T)); }
/// <summary> /// Evaluate a less-than constraint for <see cref="IComparable"/>. /// </summary> /// <param name="objToCompare">The object the parameter should be less than</param> public T LessThan(IComparable objToCompare) { objToCompare = ConvertObjectTypeToMatch(objToCompare); ArgManager.AddInArgument(Is.LessThan(objToCompare)); return(default(T)); }
/// <summary> /// Evaluate a not-same-as constraint. /// </summary> /// <param name="obj">The object the parameter should not be the same as.</param> public T NotSame(object obj) { ArgManager.AddInArgument(Is.NotSame(obj)); return(default(T)); }
/// <summary> /// Constrain the argument to validate according to regex pattern /// </summary> public string Like(string pattern) { ArgManager.AddInArgument(Text.Like(pattern)); return(null); }
/// <summary> /// Constrain the argument to contain the specified string /// </summary> public string Contains(string innerString) { ArgManager.AddInArgument(Text.Contains(innerString)); return(null); }
/// <summary> /// Constrain the argument to end with the specified string /// </summary> public string EndsWith(string end) { ArgManager.AddInArgument(Text.EndsWith(end)); return(null); }
/// <summary> /// Constrain the argument to starts with the specified string /// </summary> /// <returns></returns> public string StartsWith(string start) { ArgManager.AddInArgument(Text.StartsWith(start)); return(null); }
///<summary> /// Determines that all elements of the specified collection are in the the parameter collection ///</summary> ///<param name="collection">The collection to compare against</param> ///<returns>The constraint which should be applied to the list parameter.</returns> public T ContainsAll(IEnumerable collection) { ArgManager.AddInArgument(List.ContainsAll(collection)); return(default(T)); }
/// <summary> /// Determines that an element of the parameter collections conforms to another AbstractConstraint. /// </summary> /// <param name="index">The zero-based index of the list element.</param> /// <param name="constraint">The constraint which should be applied to the list element.</param> public T Element(int index, AbstractConstraint constraint) { ArgManager.AddInArgument(List.Element(index, constraint)); return(default(T)); }
/// <summary> /// Determines that the parameter collection has the specified number of elements. /// </summary> /// <param name="constraint">The constraint that should be applied to the collection count.</param> public T Count(AbstractConstraint constraint) { ArgManager.AddInArgument(List.Count(constraint)); return(default(T)); }
/// <summary> /// Determines that the parameter collection is identical to the specified collection /// </summary> public T Equal(IEnumerable collection) { ArgManager.AddInArgument(List.Equal(collection)); return(default(T)); }
/// <summary> /// Determines whatever the parameter is in the collection. /// </summary> public T OneOf(IEnumerable collection) { ArgManager.AddInArgument(List.OneOf(collection)); return(default(T)); }
/// <summary> /// Determines whether the specified object is in the parameter. /// The parameter must be IEnumerable. /// </summary> /// <param name="obj">Obj.</param> /// <returns></returns> public T IsIn(object obj) { ArgManager.AddInArgument(List.IsIn(obj)); return(default(T)); }