public void AddChild(CallPattern callPattern, IMethodMock methodMock, int id) { var node = new MethodMockMatcherTreeNode(methodMock, id); callPattern.MethodMockNode = node; AddChildInternal(callPattern, 0, node); }
public static void Attach(IMethodMock methodMock) { var behavior = new PreserveRefOutValuesBehavior(methodMock); var madeReplacements = ReplaceRefOutArgsWithAnyMatcher(methodMock.CallPattern); if (madeReplacements) methodMock.Behaviors.Add(behavior); }
public static void Attach(IMethodMock methodMock) { var callPattern = methodMock.CallPattern; if (!(callPattern.Method is ConstructorInfo) || callPattern.Method.IsStatic || !(callPattern.InstanceMatcher is AnyMatcher)) return; methodMock.Behaviors.Add(new ConstructorMockBehavior()); }
public OccurrencesMatcherTreeNode(IMethodMock mock) : this() { if (mock != null) { Mocks.Add(mock); } }
public static void Attach(IMethodMock methodMock) { var callPattern = methodMock.CallPattern; if (!(callPattern.Method is ConstructorInfo) || callPattern.Method.IsStatic || !(callPattern.InstanceMatcher is AnyMatcher) || typeof(string) == callPattern.Method.DeclaringType #if !COREFX || typeof(ContextBoundObject).IsAssignableFrom(callPattern.Method.DeclaringType) #endif ) return; methodMock.Behaviors.Add(new ConstructorMockBehavior()); }
public static void Attach(IMethodMock methodMock) { var callPattern = methodMock.CallPattern; if (!(callPattern.Method is ConstructorInfo) || callPattern.Method.IsStatic || !(callPattern.InstanceMatcher is AnyMatcher) || typeof(string) == callPattern.Method.DeclaringType #if !COREFX || typeof(ContextBoundObject).IsAssignableFrom(callPattern.Method.DeclaringType) #endif ) { return; } methodMock.Behaviors.Add(new ConstructorMockBehavior()); }
public PreserveRefOutValuesBehavior(IMethodMock methodMock) { var argMatchers = methodMock.CallPattern.ArgumentMatchers; var method = methodMock.CallPattern.Method; var parameters = GetParameters(method); var offsetDueToExtensionMethod = method.IsExtensionMethod() ? 1 : 0; for (int i = 0; i < parameters.Length; ++i) { if (!parameters[i].ParameterType.IsByRef || argMatchers[i].ProtectRefOut) continue; var matcher = argMatchers[i] as IValueMatcher; if (matcher == null) continue; var value = matcher.Value; values.Add(i + offsetDueToExtensionMethod, value); } }
public void AddOrUpdateOccurence(CallPattern callPattern, IMethodMock mock) { AddOrUpdateOccurenceInternal(callPattern, 0, mock); }
public void AddChild(CallPattern callPattern, IMethodMock methodMock,int id) { var node = new MethodMockMatcherTreeNode(methodMock, id); callPattern.MethodMockNode = node; AddChildInternal(callPattern, 0, node); }
void MockMethod(string name, IMethodMock method) { MethodGroup existingMock = null; if (Values.ContainsKey(name)) { existingMock = Values[name] as MethodGroup; if (existingMock == null) throw new InvalidMockException("The member \"" + name + "\" has already been set as a parameter and cannot be mocked now as a method"); //TODM } if (existingMock == null) { existingMock = new MethodGroup(method); SetMember(name, existingMock); } else { //TODM: if a method is mocked twice, the second mock will take precedence existingMock.Insert(0, method); } }
protected void AddOrUpdateOccurenceInternal(CallPattern callPattern, int depth, IMethodMock mock) { if (depth == callPattern.ArgumentMatchers.Count+1) { var resultNode = this.Children.FirstOrDefault() as OccurrencesMatcherTreeNode; if(mock != null) resultNode.Mocks.Add(mock); resultNode.Calls++; return; } var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth - 1]; var child = this.GetMatchingChild(matcher, MatchingOptions.Exact, depth); if (child != null) { child.AddOrUpdateOccurenceInternal(callPattern, depth + 1, mock); } else { this.AddChildInternal(callPattern, depth, new OccurrencesMatcherTreeNode(mock)); } }
public MethodMockMatcherTreeNode(IMethodMock methodMock = null, int id = 0) : base(null) { MethodMock = methodMock; Id = id; }
public ActivatorCreateInstanceTBehavior(IMethodMock delegatedMock) { this.delegatedMock = delegatedMock; }
public InvocationOccurrenceBehavior(IMethodMock methodMock) { this.methodMock = methodMock; }
public static void Attach(IMethodMock newExprMethodMock, IMethodMock createInstanceMethodMock) { var activatorBehavior = new ActivatorCreateInstanceTBehavior(newExprMethodMock); createInstanceMethodMock.Behaviors.Add(activatorBehavior); }
public MethodMockMatcherTreeNode(IMethodMock methodMock = null, int id = 0) :base(null) { MethodMock = methodMock; Id = id; }
protected void AddOrUpdateOccurenceInternal(CallPattern callPattern, int depth, IMethodMock mock) { if (depth == callPattern.ArgumentMatchers.Count + 1) { var resultNode = this.Children.FirstOrDefault() as OccurrencesMatcherTreeNode; if (mock != null) { resultNode.Mocks.Add(mock); } resultNode.Calls++; return; } var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth - 1]; var child = this.GetMatchingChild(matcher, MatchingOptions.Exact, depth); if (child != null) { child.AddOrUpdateOccurenceInternal(callPattern, depth + 1, mock); } else { this.AddChildInternal(callPattern, depth, new OccurrencesMatcherTreeNode(mock)); } }
public OccurrencesMatcherTreeNode(IMethodMock mock) : this() { if (mock != null) Mocks.Add(mock); }