internal static AzureRelayListener CreateServer(string baseUrl, string path) { var listener = new AzureRelayListener(new AzureRelayOptions() { TokenProvider = Microsoft.Azure.Relay.AspNetCore.Utilities.CreateTokenProvider() }, new LoggerFactory()); listener.Options.UrlPrefixes.Add(UrlPrefix.Create(new Uri(new Uri(baseUrl), path).AbsoluteUri)); listener.Start(); return(listener); }
/// <summary> /// AcceptAsync extension with timeout. This extension should be used in all tests to prevent /// unexpected hangs when a request does not arrive. /// </summary> internal static async Task <RequestContext> AcceptAsync(this AzureRelayListener server, TimeSpan timeout) { var acceptTask = server.AcceptAsync(); var completedTask = await Task.WhenAny(acceptTask, Task.Delay(timeout)); if (completedTask == acceptTask) { return(await acceptTask); } else { server.Dispose(); throw new TimeoutException("AcceptAsync has timed out."); } }
internal static AzureRelayListener CreateDynamicHttpServer(string basePath, out string root, out string baseAddress, TokenProvider tp = null) { if (basePath.StartsWith("/")) { basePath = basePath.Substring(1); } var rootUri = new Uri(Microsoft.Azure.Relay.AspNetCore.Utilities.GetRelayUrl()); var prefix = UrlPrefix.Create(new Uri(rootUri, basePath).AbsoluteUri, tp != null ? tp : CreateTokenProvider()); root = rootUri.ToString(); baseAddress = prefix.FullPrefix; var listener = new AzureRelayListener(new AzureRelayOptions(), new LoggerFactory()); listener.Options.UrlPrefixes.Add(prefix); listener.Start(); return(listener); }