From 04211c0f67dec4e03aecf47a3e6833598e0eba30 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 8 Mar 2020 18:45:21 -0700 Subject: [PATCH] Fix connecting to web sockets with regex urls --- Ooui/UI.cs | 10 ++++++++++ Tests/UITests.cs | 14 +++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Ooui/UI.cs b/Ooui/UI.cs index eaac8d4..5444f31 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -221,6 +221,13 @@ namespace Ooui return url; } + public static string GetWebSocketUrl (string path) + { + var localhost = host == "*" ? "localhost" : host; + var url = $"ws://{localhost}:{port}{path}"; + return url; + } + public static void WaitUntilStarted () => started.WaitOne (); static void Start () @@ -561,6 +568,9 @@ namespace Ooui if (m.Success) { pp = p; found = true; + for (var ig = 1; ig < m.Groups.Count; ig++) { + variables[p.RegexPath.GroupNameFromNumber (ig)] = m.Groups[ig].Value; + } break; } } diff --git a/Tests/UITests.cs b/Tests/UITests.cs index 8639cdd..d7c2daf 100644 --- a/Tests/UITests.cs +++ b/Tests/UITests.cs @@ -1,5 +1,7 @@ using System; using System.Net.Http; +using System.Net.WebSockets; +using System.Threading; using System.Threading.Tasks; #if NUNIT @@ -83,14 +85,20 @@ namespace Tests } [TestMethod] - public void PublishElementPatternUrl () + public async Task PublishElementPatternUrl () { + bool gotRequest = false; UI.Publish ("/pattern/(?[a-z0-9]+)", x => { + gotRequest = true; Assert.AreEqual ("fhe48yf", x["id"]); return new Paragraph (x["id"]); }); - var r = DownloadUI ("/pattern/fhe48yf"); - Assert.IsTrue (r.Length > 200); + UI.WaitUntilStarted (); + var ws = new ClientWebSocket (); + ws.Options.AddSubProtocol ("ooui"); + var url = new Uri (UI.GetWebSocketUrl ("/pattern/fhe48yf")); + await ws.ConnectAsync (url, CancellationToken.None); + Assert.IsTrue (gotRequest); } [TestMethod]