Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can Get Shell By Case Insensitive Name. #12120

59 changes: 18 additions & 41 deletions test/OrchardCore.Tests/Shell/ShellHostTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Environment.Shell;
using OrchardCore.Environment.Shell.Builders;
using OrchardCore.Environment.Shell.Models;
using OrchardCore.Tests.Apis.Context;
using Xunit;
Expand All @@ -10,54 +9,32 @@ namespace OrchardCore.Tests.Shell;

public class ShellHostTests : SiteContext
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly IShellHost _shellHost;
public static IShellHost ShellHost { get; }
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved

public ShellHostTests()
static ShellHostTests()
{
_shellHost = Site.Services.GetRequiredService<IShellHost>();
ShellHost = Site.Services.GetRequiredService<IShellHost>();
}

[Theory]
[InlineData("Test", "test")]
[InlineData("OrchardCore", "orchardcore")]
[InlineData(ShellHelper.DefaultShellName, "DeFauLt")]
public async Task FindCaseInsensitiveShellSettings(string shellName, string anotherVariantOfShellName)
[InlineData("Tenant1", "tEnAnT1")]
[InlineData(ShellHelper.DefaultShellName, "dEfAuLt")]
public static async Task ShellCanBeFoundByCaseInsensitiveName(string name, string searchName)
{
await GetOrCreateShellContextAsync(shellName);
_shellHost.TryGetSettings(shellName, out var shellSettings);
_shellHost.TryGetSettings(anotherVariantOfShellName, out var anotherVariantOfShellSettings);
var shellContext = await ShellHost.GetOrCreateShellContextAsync(
new ShellSettings()
{
Name = name,
State = TenantState.Uninitialized,
});

Assert.NotEqual(shellName, anotherVariantOfShellName);
Assert.NotNull(shellSettings);
Assert.NotNull(anotherVariantOfShellSettings);
Assert.Same(shellSettings, anotherVariantOfShellSettings);
}

[Theory]
[InlineData("Test", "test")]
[InlineData("OrchardCore", "orchardcore")]
[InlineData(ShellHelper.DefaultShellName, "dEfAult")]
public async Task FindCaseInsensitiveShellContext(string shellName, string anotherVariantOfShellName)
{
await GetOrCreateShellContextAsync(shellName);

_shellHost.TryGetShellContext(shellName, out var shellContext);
_shellHost.TryGetShellContext(anotherVariantOfShellName, out var anotherVariantOfShellContext);
var foundShellSettings = ShellHost.GetSettings(searchName);
ShellHost.TryGetShellContext(searchName, out var foundShellContext);

Assert.NotEqual(shellName, anotherVariantOfShellName);
Assert.NotNull(shellContext);
Assert.NotNull(anotherVariantOfShellContext);
Assert.Same(shellContext, anotherVariantOfShellContext);
}

private async Task<ShellContext> GetOrCreateShellContextAsync(string name)
{
var shellSettings = new ShellSettings()
{
Name = name,
State = TenantState.Uninitialized,
};

return await _shellHost.GetOrCreateShellContextAsync(shellSettings);
Assert.NotEqual(name, searchName);
Assert.Same(foundShellSettings, shellContext.Settings);
Assert.Same(foundShellContext.Settings, shellContext.Settings);
Assert.Same(foundShellContext, shellContext);
}
}
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved