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 void AddChild(CallPattern callPattern, IMethodMock methodMock, int id) { var node = new MethodMockMatcherTreeNode(methodMock, id); callPattern.MethodMockNode = node; AddChildInternal(callPattern, 0, node); }
public List <MethodMockMatcherTreeNode> GetAllMethodMocks(CallPattern callPattern) { List <MethodMockMatcherTreeNode> results = new List <MethodMockMatcherTreeNode>(); GetMethodMockInternal(callPattern, 0, results, MatchingOptions.Concretizing); return(results.ToList()); }
public List <MethodMockMatcherTreeNode> GetMethodMock(CallPattern callPattern) { List <MethodMockMatcherTreeNode> results = new List <MethodMockMatcherTreeNode>(); GetMethodMockInternal(callPattern, 0, results, MatchingOptions.Generalizing); return(results); }
public List <OccurrencesMatcherTreeNode> GetOccurences(CallPattern callPattern) { List <OccurrencesMatcherTreeNode> results = new List <OccurrencesMatcherTreeNode>(); GetOccurencesInternal(callPattern, 0, results); return(results); }
protected void GetMethodMockInternal(CallPattern callPattern, int depth, List <MethodMockMatcherTreeNode> results, MatchingOptions matchingOptions) { if (depth == callPattern.ArgumentMatchers.Count + 1) { var resultNode = this.Children.Select(x => x as MethodMockMatcherTreeNode).ToList(); results.AddRange(resultNode); foreach (var result in resultNode) { DebugView.TraceEvent(IndentLevel.Matcher, () => String.Format("Found candidate arrangement (id={0}) {1} {2}", result.Id, result.MethodMock.ArrangementExpression, result.MethodMock.IsSequential ? String.Format("(in sequence, used: {0})", result.MethodMock.IsUsed ? "yes" : "no") : "")); } return; } var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth - 1]; var children = this.GetMatchingChildren(matcher, matchingOptions, depth); foreach (var child in children) { child.GetMethodMockInternal(callPattern, depth + 1, results, matchingOptions); } }
protected void GetMethodMockInternal(CallPattern callPattern, int depth, List<MethodMockMatcherTreeNode> results, MatchingOptions matchingOptions) { if (depth == callPattern.ArgumentMatchers.Count + 1) { var resultNode = this.Children.Select(x => x as MethodMockMatcherTreeNode).ToList(); results.AddRange(resultNode); foreach (var result in resultNode) { DebugView.TraceEvent(IndentLevel.Matcher, () => String.Format("Found candidate arrangement (id={0}) {1} {2}", result.Id, result.MethodMock.ArrangementExpression, result.MethodMock.IsSequential ? String.Format("(in sequence, used: {0})", result.MethodMock.IsUsed ? "yes" : "no") : "")); } return; } var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth - 1]; var children = this.GetMatchingChildren(matcher, matchingOptions, depth); foreach (var child in children) { child.GetMethodMockInternal(callPattern, depth + 1, results, matchingOptions); } }
public static bool ReplaceRefOutArgsWithAnyMatcher(CallPattern callPattern) { bool madeReplacements = false; var parameters = GetParameters(callPattern.Method); for (int i = 0; i < parameters.Length; ++i) { if (parameters[i].ParameterType.IsByRef && !callPattern.ArgumentMatchers[i].ProtectRefOut) { callPattern.ArgumentMatchers[i] = new AnyMatcher(); madeReplacements = true; } } return madeReplacements; }
protected void GetOccurencesInternal(CallPattern callPattern, int depth, List <OccurrencesMatcherTreeNode> results) { if (depth == callPattern.ArgumentMatchers.Count + 1) { var resultNode = this.Children.Cast <OccurrencesMatcherTreeNode>() .Where(node => NodeMatchesFilter(callPattern, node)); results.AddRange(resultNode); return; } var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth - 1]; var children = this.GetMatchingChildren(matcher, MatchingOptions.Concretizing, depth); foreach (var child in children) { child.GetOccurencesInternal(callPattern, depth + 1, results); } }
private static bool NodeMatchesFilter(CallPattern callPattern, IMatcherTreeNode node) { var filter = callPattern.Filter; if (filter == null) { return(true); } var args = new List <object>(); var nodeIter = node; while (nodeIter != null) { var valueMatcher = nodeIter.Matcher as IValueMatcher; if (valueMatcher != null) { args.Add(valueMatcher.Value); } nodeIter = nodeIter.Parent; } if (!callPattern.Method.IsStatic && filter.Method.GetParameters().Length + 1 == args.Count) { args.RemoveAt(args.Count - 1); } args.Reverse(); var argsArray = args.ToArray(); object state; MockingUtil.BindToMethod(MockingUtil.Default, new[] { filter.Method }, ref argsArray, null, null, null, out state); var filterFunc = MockingUtil.MakeFuncCaller(filter); var isMatch = (bool)ProfilerInterceptor.GuardExternal(() => filterFunc(argsArray, filter)); DebugView.TraceEvent(IndentLevel.Matcher, () => String.Format("Matcher predicate {0} call to {2} with arguments ({1})", isMatch ? "passed" : "rejected", String.Join(", ", args.Select(x => x.ToString()).ToArray()), callPattern.Method)); return(isMatch); }
protected void AddChildInternal(CallPattern callPattern, int depth, MatcherTreeNode leaf) { if (depth == callPattern.ArgumentMatchers.Count+1) { this.Children.Add(leaf); leaf.Parent = this; return; } var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth - 1]; var found = this.GetMatchingChild(matcher, MatchingOptions.Exact, depth); if (found != null) { found.AddChildInternal(callPattern, depth+1, leaf); } else { var node = new MatcherTreeNode(matcher); Children.Add(node); node.Parent = this; node.AddChildInternal(callPattern, depth+1, leaf); } }
protected void AddChildInternal(CallPattern callPattern, int depth, MatcherTreeNode leaf) { if (depth == callPattern.ArgumentMatchers.Count + 1) { this.Children.Add(leaf); leaf.Parent = this; return; } var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth - 1]; var found = this.GetMatchingChild(matcher, MatchingOptions.Exact, depth); if (found != null) { found.AddChildInternal(callPattern, depth + 1, leaf); } else { var node = new MatcherTreeNode(matcher); Children.Add(node); node.Parent = this; node.AddChildInternal(callPattern, depth + 1, leaf); } }
public List<MethodMockMatcherTreeNode> GetMethodMock(CallPattern callPattern) { List<MethodMockMatcherTreeNode> results = new List<MethodMockMatcherTreeNode>(); GetMethodMockInternal(callPattern, 0, results, MatchingOptions.Generalizing); return results; }
public List<MethodMockMatcherTreeNode> GetAllMethodMocks(CallPattern callPattern) { List<MethodMockMatcherTreeNode> results = new List<MethodMockMatcherTreeNode>(); GetMethodMockInternal(callPattern, 0, results, MatchingOptions.Concretizing); return results.ToList(); }
public void AddChild(CallPattern callPattern, IMethodMock methodMock,int id) { var node = new MethodMockMatcherTreeNode(methodMock, id); callPattern.MethodMockNode = node; AddChildInternal(callPattern, 0, node); }
public void AddChild(CallPattern callPattern, MethodMockMatcherTreeNode node) { AddChildInternal(callPattern, 0, node); }
protected void GetOccurencesInternal(CallPattern callPattern, int depth, List<OccurrencesMatcherTreeNode> results) { if (depth == callPattern.ArgumentMatchers.Count+1) { var resultNode = this.Children.Cast<OccurrencesMatcherTreeNode>() .Where(node => NodeMatchesFilter(callPattern, node)); results.AddRange(resultNode); return; } var matcher = depth == 0 ? callPattern.InstanceMatcher : callPattern.ArgumentMatchers[depth-1]; var children = this.GetMatchingChildren(matcher, MatchingOptions.Concretizing, depth); foreach (var child in children) { child.GetOccurencesInternal(callPattern, depth+1, results); } }
public void AddOrUpdateOccurence(CallPattern callPattern, IMethodMock mock) { AddOrUpdateOccurenceInternal(callPattern, 0, mock); }
private static bool NodeMatchesFilter(CallPattern callPattern, IMatcherTreeNode node) { var filter = callPattern.Filter; if (filter == null) return true; var args = new List<object>(); var nodeIter = node; while (nodeIter != null) { var valueMatcher = nodeIter.Matcher as IValueMatcher; if (valueMatcher != null) { args.Add(valueMatcher.Value); } nodeIter = nodeIter.Parent; } if (!callPattern.Method.IsStatic && filter.Method.GetParameters().Length + 1 == args.Count) { args.RemoveAt(args.Count - 1); } args.Reverse(); var argsArray = args.ToArray(); object state; MockingUtil.BindToMethod(MockingUtil.Default, new[] { filter.Method }, ref argsArray, null, null, null, out state); var filterFunc = MockingUtil.MakeFuncCaller(filter); var isMatch = (bool) ProfilerInterceptor.GuardExternal(() => filterFunc(argsArray, filter)); DebugView.TraceEvent(IndentLevel.Matcher, () => String.Format("Matcher predicate {0} call to {2} with arguments ({1})", isMatch ? "passed" : "rejected", String.Join(", ", args.Select(x => x.ToString()).ToArray()), callPattern.Method)); return isMatch; }
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 List<OccurrencesMatcherTreeNode> GetOccurences(CallPattern callPattern) { List<OccurrencesMatcherTreeNode> results = new List<OccurrencesMatcherTreeNode>(); GetOccurencesInternal(callPattern, 0, results); return results; }