4 using System.Collections.Generic;
9 using Monodoc.Generators;
11 using HtmlAgilityPack;
13 namespace MonoTests.Monodoc
16 public class HelpSourceTest
18 const string BaseDir = "../../class/monodoc/Test/monodoc_test/";
20 class CheckGenerator : IDocGenerator<bool>
22 public string LastCheckMessage { get; set; }
24 public bool Generate (HelpSource hs, string id, Dictionary<string, string> context)
26 LastCheckMessage = string.Format ("#1 : {0} {1}", hs, id);
27 if (hs == null || string.IsNullOrEmpty (id))
30 // Stripe the arguments parts since we don't need it
31 var argIdx = id.LastIndexOf ('?');
33 id = id.Substring (0, argIdx);
35 LastCheckMessage = string.Format ("#2 : {0} {1}", hs, id);
36 if (hs.IsRawContent (id))
37 return hs.GetText (id) != null;
39 IEnumerable<string> parts;
40 if (hs.IsMultiPart (id, out parts)) {
41 LastCheckMessage = string.Format ("#4 : {0} {1} ({2})", hs, id, string.Join (", ", parts));
42 foreach (var partId in parts)
43 if (!Generate (hs, partId, context))
47 LastCheckMessage = string.Format ("#3 : {0} {1}", hs, id);
48 if (hs.IsGeneratedContent (id))
49 return hs.GetCachedText (id) != null;
51 var s = hs.GetCachedHelpStream (id);
62 /* This test verifies that for every node in our tree that possed a PublicUrl,
63 * we can correctly access it back through RenderUrl
66 public void ReachabilityTest ()
68 var rootTree = RootTree.LoadTree (Path.GetFullPath (BaseDir), false);
70 var generator = new CheckGenerator ();
74 foreach (var leaf in GetLeaves (rootTree.RootNode)) {
75 if (!rootTree.RenderUrl (leaf.PublicUrl, generator, out result) || leaf != result) {
76 Console.WriteLine ("Error: {0} with HelpSource {1} ", leaf.PublicUrl, leaf.Tree.HelpSource.Name);
82 //Assert.AreEqual (0, errorCount, errorCount + " / " + testCount.ToString ());
84 // HACK: in reality we have currently 4 known issues which are due to duplicated namespaces across
85 // doc sources, something that was never supported and that we need to improve/fix at some stage
86 Assert.LessOrEqual (4, errorCount, errorCount + " / " + testCount.ToString ());
89 IEnumerable<Node> GetLeaves (Node node)
97 foreach (var child in node.ChildNodes) {
98 if (!string.IsNullOrEmpty (child.Element) && !child.Element.StartsWith ("root:/"))
100 foreach (var childLeaf in GetLeaves (child))
101 yield return childLeaf;
107 public void ReachabilityWithShortGenericNotationTest ()
109 var rootTree = RootTree.LoadTree (Path.GetFullPath (BaseDir), false);
111 var generator = new CheckGenerator ();
113 Assert.IsTrue (rootTree.RenderUrl ("T:System.Collections.Concurrent.IProducerConsumerCollection`1", generator, out result), "#1");
114 Assert.IsTrue (rootTree.RenderUrl ("T:System.Collections.Generic.Dictionary`2", generator, out result), "#2");
115 Assert.IsTrue (rootTree.RenderUrl ("T:System.Action`4", generator, out result), "#3");
119 public void AspNetStyleUrlReachabilityTest ()
121 var rootTree = RootTree.LoadTree (Path.GetFullPath (BaseDir), false);
123 var generator = new CheckGenerator ();
125 Assert.IsTrue (rootTree.RenderUrl ("T:System.Collections.Generic.Dictionary{TKey,TValue}", generator, out result), "#1");
126 Assert.IsTrue (rootTree.RenderUrl ("T:System.Action{T1,T2}", generator, out result), "#2");
127 Assert.IsTrue (rootTree.RenderUrl ("T:System.EventHandler{TEventArgs}", generator, out result), "#3");
128 Assert.IsTrue (rootTree.RenderUrl ("T:System.Func{T1,T2,T3,TResult}", generator, out result), "#4");
129 Assert.IsTrue (rootTree.RenderUrl ("T:System.Collections.Generic.Dictionary{TKey,TValue}+ValueCollection", generator, out result), "#5");
130 Assert.IsTrue (rootTree.RenderUrl ("T:System.IComparable{T}", generator, out result), "#6");