public QualifiedTopicRevisionCollection AllReferencesByTopic(UnqualifiedTopicName referencingTopic, ExistencePolicy existencePolicy) { if (referencingTopic == null) { throw new ArgumentNullException("referencingTopic"); } TopicRevisionCollection references = ContentProviderChain.GetParsedTopic(new UnqualifiedTopicRevision(referencingTopic.LocalName)).TopicLinks; // In-scope namespaces include this namespace and every imported namespace. IList<string> inScopeNamespaces = new List<string>(); inScopeNamespaces.Add(Namespace); foreach (string importedNamespace in ImportedNamespaces) { inScopeNamespaces.Add(importedNamespace); } // Since the list that comes back might be read-only, we make a new one. QualifiedTopicRevisionCollection resolvedReferences = new QualifiedTopicRevisionCollection(); foreach (TopicRevision reference in references) { // If the reference has no namespace, consider it to be relative to // every in-scope namespace if (reference.Namespace == null) { foreach (string inScopeNamespace in inScopeNamespaces) { resolvedReferences.Add(reference.ResolveRelativeTo(inScopeNamespace)); } } else { resolvedReferences.Add(new QualifiedTopicRevision(reference.LocalName, reference.Namespace)); } } if (existencePolicy == ExistencePolicy.ExistingOnly) { // We can't remove items from a list we're iterating over, so // we need to make a new list. QualifiedTopicRevisionCollection filteredReferences = new QualifiedTopicRevisionCollection(); foreach (QualifiedTopicRevision resolvedReference in resolvedReferences) { NamespaceManager manager = Federation.NamespaceManagerForNamespace(resolvedReference.Namespace); if (manager != null) { if (manager.Exists) { if (manager.TopicExists(resolvedReference.LocalName, ImportPolicy.DoNotIncludeImports)) { filteredReferences.Add(resolvedReference); } } } } resolvedReferences = filteredReferences; } return resolvedReferences; }
private void AssertReferencesCorrect(QualifiedTopicRevisionCollection actualTopics, params QualifiedTopicRevision[] expectedTopics) { Assert.AreEqual(expectedTopics.Length, actualTopics.Count, "Checking that the correct number of topics were returned."); for (int i = 0; i < actualTopics.Count; i++) { Assert.AreEqual(expectedTopics[i], actualTopics[i], string.Format("Checking that topic {0} was correct", i)); } }