Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OrchardCoreContrib.Testing/ISiteContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public interface ISiteContext : IDisposable

string TenantName { get; }

Task InitializeAsync();
Task InitializeAsync(string tenantName = null);
}
30 changes: 26 additions & 4 deletions src/OrchardCoreContrib.Testing/SiteContextBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public SiteContextBase()

public string TenantName { get; private set; }

public virtual async Task InitializeAsync()
public virtual async Task InitializeAsync(string tenantName = null)
{
var tenantName = Guid.NewGuid().ToString("n");
tenantName ??= Guid.NewGuid().ToString("n");

var response = await CreateSiteAsync(tenantName);

Expand All @@ -53,8 +53,30 @@ public virtual async Task InitializeAsync()

lock (Site)
{
var url = new Uri(content.Trim('"'));
url = new Uri(url.Scheme + "://" + url.Authority + url.LocalPath + "/");
Uri url = null;

var rawUrl = content?.Trim().Trim('"');

if (!string.IsNullOrWhiteSpace(rawUrl))
{
if (!Uri.TryCreate(rawUrl, UriKind.Absolute, out url))
{
throw new InvalidOperationException($"Tenant create API returned an invalid URL: '{rawUrl}'.");
}
}
else if (response.Headers.Location is { } location)
{
url = location.IsAbsoluteUri
? location
: new Uri(DefaultTenantClient.BaseAddress ?? new Uri("http://localhost/"), location);
}
else
{
// Fallback for API responses with empty body and no Location header.
url = new Uri(DefaultTenantClient.BaseAddress ?? new Uri("http://localhost/"), $"{tenantName}/");
}

url = new Uri($"{url.Scheme}://{url.Authority}{url.LocalPath.TrimEnd('/')}/");

Client = Site.CreateDefaultClient(url);

Expand Down
Loading