private MocksRepository FindRepositoryInOps(RepositoryOperationsBase entryOps, object entryKey)
        {
            if (entryOps.IsUsedOnAllThreads)
            {
                var repo = entryOps.FindRepositoryFromAnyThread(entryKey);
                if (repo != null)
                {
                    if (repo.IsRetired)
                    {
                        entryOps.RetireRepository(entryKey, repo);
                        repo = null;
                    }
                }
                return(repo);
            }
            else
            {
                var repo = entryOps.FindRepository(entryKey);
                if (repo != null)
                {
                    if (repo.IsParentToAnotherRepository || repo.IsRetired)
                    {
                        entryOps.RetireRepository(entryKey, repo);
                        repo = null;
                    }
                }

                return(repo);
            }
        }
        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);
        }
		private MocksRepository FindRepositoryInOps(RepositoryOperationsBase entryOps, object entryKey)
		{
			if (entryOps.IsUsedOnAllThreads)
			{
				var repo = entryOps.FindRepositoryFromAnyThread(entryKey);
				if (repo != null)
				{
					if (repo.IsRetired)
					{
						entryOps.RetireRepository(entryKey, repo);
						repo = null;
					}
				}
				return repo;
			}
			else
			{
				var repo = entryOps.FindRepository(entryKey);
				if (repo != null)
				{
					if (repo.IsParentToAnotherRepository || repo.IsRetired)
					{
						entryOps.RetireRepository(entryKey, repo);
						repo = null;
					}
				}

				return repo;
			}
		}