private bool DoesContainAssertion(MethodCall methodCall) { if (!methodCall.HasMethodDefinition || !methodCall.MethodDefinition.HasBody) return false; var frameworks = new[] {Framework}.Concat(_mockFrameworks); return frameworks.Any(fw => fw.DoesContainAssertion(methodCall.MethodDefinition)); }
private IEnumerable<IList<MethodCall>> AddPathsToRoot(MethodCall call) { if (!DoesContainAssertion(call)) return new IList<MethodCall>[0]; var graph = CallGraph; // Create a graph with edges in the other direction so we can // backtrack from this method to the test method (root). var builder = new GraphBuilder<MethodCall>(graph.TailsFor); var backGraph = builder.Build(call); return backGraph.FindPaths(call, graph.Root); }
private static IEnumerable<MethodCall> CalledMethodsFinder(MethodCall call) { if (!call.HasMethodDefinition) return new MethodCall[0]; // no body to parse anyway var definition = call.MethodDefinition; return definition.CalledMethods().Where(mc => !mc.MethodReference.Name.Equals(".ctor")).Select(TryResolve); }
private static MethodCall TryResolve(MethodCall mc) { if (mc.HasMethodDefinition) return mc; MethodReference result; try { result = mc.MethodReference.Resolve(); } catch (AssemblyResolutionException) { // resolution is best-effort, keep the reference result = mc.MethodReference; } return new MethodCall(mc.Instruction, result); }
protected bool Equals(MethodCall other) { return Equals(Instruction, other.Instruction); }