/// <summary> /// Creates a link to another DebugNode. /// </summary> /// <param name="text">The text of the link.</param> /// <param name="subUrl">The subUrl to link to.</param> /// <param name="walkableQueue">The current walkableQueue.</param> /// <param name="requestedAction">The requested Action for the linked DebugNode.</param> /// <returns>The link as HLink.</returns> public static HLink GetLink(string text, ID subUrl, WalkableQueue <Tuple <ID, string> > walkableQueue, string requestedAction = null) { if (text == null) { throw new ArgumentNullException(nameof(text)); } if (subUrl == null) { throw new ArgumentNullException(nameof(subUrl)); } if (walkableQueue == null) { throw new ArgumentNullException(nameof(walkableQueue)); } List <Tuple <ID, string> > already = walkableQueue.GetPassed(); if (!walkableQueue.AtEnd()) { already.Add(walkableQueue.Peek()); } string ret = "/"; foreach (Tuple <ID, string> tuple in already) { ret += tuple.Item1 + "/"; } ret += "?"; for (int i = 0; i < already.Count - 1; i++) { if (!string.IsNullOrEmpty(already[i].Item2)) { ret += $"action_{i}={already[i].Item2}&"; } } if (!string.IsNullOrEmpty(requestedAction)) { ret += $"action_{already.Count - 1}={requestedAction.EncodeUrl()}"; } return(new HLink(text, ret)); }
/// <inheritdoc /> public override HElement GetContents(SessionData sessionData, string requestedAction, WalkableQueue <Tuple <ID, string> > positionQueue) { if (positionQueue.AtEnd()) { HElement list = new HList(HList.EListType.UnorderedList, (from s in _subNodes select GetLink(s.Value.Name, s.Key, positionQueue, positionQueue.Position, null)).ToArray()) { Class = "subnodes" }; if (((HList)list).IsEmpty()) { list = new HItalic("This DebugNode includes no Subnodes.") { Class = "subnodes" } } ; else { list = new HHeadline("Subnodes of this DebugNode", 3) { Class = "subnodes" } } +list; return(new HHeadline(Name) + new HLine() { Class = "start" } +(_description == null ? new HText(_description) : (HElement) new HString()) + new HContainer(GetElements(sessionData)) + new HLine() { Class = "subnodes" } +list); } else { HLink navlink = GetLink(this); navlink.Class = "nav"; HInlineContainer name = new HInlineContainer() { Elements = { navlink } }; DebugResponseNode node = null; positionQueue.Pop(); if (_subNodes) { node = _subNodes[positionQueue.Peek().Item1]; } if (ReferenceEquals(node, null)) { HElement list = new HList(HList.EListType.UnorderedList, (from s in _subNodes select GetLink(s.Value.Name, s.Value.URL)).ToArray()) { Class = "subnodes" }; if (((HList)list).IsEmpty()) { list = new HItalic("This DebugNode includes no Subnodes.") { Class = "subnodes" } } ; else { list = new HHeadline("Subnodes of this DebugNode", 3) { Class = "subnodes" } } +list; return(name + new HHeadline(Name) + new HLine() { Class = "start" } +new HText($"The ID '{positionQueue.Peek().Item1.Value}' is not a child of this {nameof(DebugContainerResponseNode)}.") { Class = "invalid" } +new HLine() { Class = "subnodes" } +list); } else { return(name + node.GetContents(sessionData, positionQueue.Peek().Item2, positionQueue)); } } }
public void TestWalkableQueue() { WalkableQueue <string> walkableQueue = new WalkableQueue <string>(); Assert.AreEqual(0, walkableQueue.Count); Assert.IsTrue(walkableQueue.AtEnd()); walkableQueue.Push(""); Assert.IsTrue(walkableQueue.AtEnd()); Assert.AreEqual(1, walkableQueue.Count); Assert.AreEqual("", walkableQueue.Peek()); Assert.AreEqual("", walkableQueue.Pop()); Assert.IsTrue(walkableQueue.AtEnd()); walkableQueue.Push("a"); Assert.AreEqual(2, walkableQueue.Count); Assert.AreEqual("a", walkableQueue.Peek()); Assert.AreEqual("", walkableQueue.Current); Assert.AreEqual("a", walkableQueue.Pop()); Assert.IsTrue(walkableQueue.AtEnd()); List <string> passed = walkableQueue.GetPassed(); Assert.AreEqual(2, passed.Count); Assert.AreEqual("", passed[0]); Assert.AreEqual("a", passed[1]); walkableQueue.Push("b"); walkableQueue.Push("c"); walkableQueue.Push("d"); List <string> consumable = walkableQueue.GetConsumable(); Assert.AreEqual(3, consumable.Count); Assert.AreEqual("b", consumable[0]); Assert.AreEqual("c", consumable[1]); Assert.AreEqual("d", consumable[2]); Assert.IsFalse(walkableQueue.AtEnd()); Assert.AreEqual(5, walkableQueue.Count); Assert.AreEqual("a", walkableQueue.Current); Assert.AreEqual("b", walkableQueue.Peek()); Assert.IsFalse(walkableQueue.AtEnd()); Assert.AreEqual("b", walkableQueue.Pop()); Assert.IsFalse(walkableQueue.AtEnd()); Assert.AreEqual("c", walkableQueue.Peek()); Assert.AreEqual("b", walkableQueue.Current); Assert.IsFalse(walkableQueue.AtEnd()); Assert.AreEqual("c", walkableQueue.Pop()); Assert.AreEqual("c", walkableQueue.Current); Assert.IsTrue(walkableQueue.AtEnd()); Assert.AreEqual("d", walkableQueue.Pop()); Assert.IsTrue(walkableQueue.AtEnd()); List <string> all = walkableQueue.GetAll(); Assert.AreEqual(5, all.Count); walkableQueue.ResetPosition(); Assert.AreEqual("", walkableQueue.Pop()); Assert.AreEqual("a", walkableQueue.Pop()); Assert.AreEqual("b", walkableQueue.Pop()); Assert.AreEqual("c", walkableQueue.Pop()); Assert.AreEqual("d", walkableQueue.Pop()); walkableQueue.Clear(); Assert.AreEqual(0, walkableQueue.Count); walkableQueue = new WalkableQueue <string>(new List <string> { "0", "1", "2", "3", "4" }); Assert.AreEqual(5, walkableQueue.Count); for (int i = 0; i < 5; i++) { Assert.AreEqual(i.ToString(), walkableQueue[i]); walkableQueue[i] = new string('-', i); Assert.AreEqual(new string('-', i), walkableQueue[i]); } int index = 0; foreach (string s in walkableQueue) { Assert.AreEqual(index++, s.Length); } List <string> range = walkableQueue.GetRange(2, 2); index = 2; foreach (string s in range) { Assert.AreEqual(index++, s.Length); } }