public override bool RetireRepository() { RepositoryOperationsBase entryOps = null; int repoIdx; var testMethod = FindTestMethod(out repoIdx, out entryOps); if (testMethod == null) { return(false); } var entryKey = entryOps.GetKey(testMethod); MocksRepository repo = FindRepositoryInOps(entryOps, entryKey); if (repo != null) { entryOps.RetireRepository(entryKey, repo); } return(true); }
public override MocksRepository ResolveRepository(UnresolvedContextBehavior unresolvedContextBehavior) { RepositoryOperationsBase entryOps = null; int repoIdx; var testMethod = FindTestMethod(out repoIdx, out entryOps); if (testMethod == null) { return(null); } var entryKey = entryOps.GetKey(testMethod); MocksRepository repo = FindRepositoryInOps(entryOps, entryKey); if (repo != null) { return(repo); } if (unresolvedContextBehavior == UnresolvedContextBehavior.DoNotCreateNew) { return(null); } //Check if this is the same kind of method but from a derived class, thus building context. MocksRepository parentRepo = entryOps.FindRepositoryToInherit(testMethod); if (parentRepo == null) { for (var repoIdxParent = repoIdx + 1; parentRepo == null && repoIdxParent < this.repoOperations.Count; ++repoIdxParent) { var ops = this.repoOperations[repoIdxParent]; if (ops.IsLeaf) { continue; } var parentKey = ops.GetKey(testMethod); if (ops.IsUsedOnAllThreads) { parentRepo = ops.FindRepositoryFromAnyThread(parentKey); } else { parentRepo = ops.FindRepository(parentKey) ?? ops.FindRepositoryToInherit(testMethod); } } } MocksRepository entryRepo; try { entryRepo = new MocksRepository(parentRepo, testMethod); entryOps.AddRepository(entryKey, entryRepo); OnMocksRepositoryCreated(repo); } catch (TypeInitializationException e) { throw e.InnerException; } return(entryRepo); }