| 1 | using System.Collections.Generic; |
| 2 | using CascadeIDE.Features.Launch.DataAcquisition; |
| 3 | using Xunit; |
| 4 | |
| 5 | namespace CascadeIDE.Tests; |
| 6 | |
| 7 | public sealed class KestrelLaunchBrowserTests |
| 8 | { |
| 9 | [Fact] |
| 10 | public void ResolveUrl_Without_LaunchUrl_Uses_First_AspNetCore_Url() |
| 11 | { |
| 12 | var env = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) |
| 13 | { |
| 14 | ["ASPNETCORE_URLS"] = "https://localhost:7208;http://localhost:33300" |
| 15 | }; |
| 16 | var u = KestrelLaunchBrowser.ResolveUrlToOpen(env, launchUrl: null); |
| 17 | Assert.Equal("https://localhost:7208", u); |
| 18 | } |
| 19 | |
| 20 | [Fact] |
| 21 | public void ResolveUrl_Absolute_LaunchUrl_Ignores_Env() |
| 22 | { |
| 23 | var u = KestrelLaunchBrowser.ResolveUrlToOpen( |
| 24 | environment: null, |
| 25 | "http://localhost:33300/graphql"); |
| 26 | Assert.Equal("http://localhost:33300/graphql", u); |
| 27 | } |
| 28 | |
| 29 | [Fact] |
| 30 | public void ResolveUrl_Leading_Slash_Combines_With_Base_Authority() |
| 31 | { |
| 32 | var env = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) |
| 33 | { |
| 34 | ["ASPNETCORE_URLS"] = "http://localhost:33300" |
| 35 | }; |
| 36 | var u = KestrelLaunchBrowser.ResolveUrlToOpen(env, "/graphql"); |
| 37 | Assert.Equal("http://localhost:33300/graphql", u); |
| 38 | } |
| 39 | |
| 40 | [Fact] |
| 41 | public void ResolveUrl_Leading_Slash_With_Query_Uses_UriBuilder() |
| 42 | { |
| 43 | var env = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) |
| 44 | { |
| 45 | ["ASPNETCORE_URLS"] = "http://localhost:33300" |
| 46 | }; |
| 47 | var u = KestrelLaunchBrowser.ResolveUrlToOpen(env, "/graphql?op=1"); |
| 48 | Assert.Equal("http://localhost:33300/graphql?op=1", u); |
| 49 | } |
| 50 | } |
| 51 | |