-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTenantTests.cs
62 lines (52 loc) · 2.36 KB
/
TenantTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Lombiq.Tests.UI.Constants;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Pages;
using OpenQA.Selenium;
using Shouldly;
using System.Threading.Tasks;
using Xunit;
namespace Lombiq.Tests.UI.Samples.Tests;
// You can also test multi-tenant web apps. Creating tenants on the fly is supported as well with a shortcut. If you'd
// like to test the tenant creation-setup process itself, then look into using CreateNewTenantManuallyAsync() instead.
public class TenantTests : UITestBase
{
private const string TestTenantName = "Test";
private const string TestTenantUrlPrefix = "test";
private const string TestTenantDisplayName = "Lombiq's OSOCE - Test Tenant";
public TenantTests(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
{
}
[Fact]
public Task CreatingTenantShouldWork() =>
ExecuteTestAfterSetupAsync(
async context =>
{
const string tenantAdminName = "tenantAdmin";
await context.SignInDirectlyAsync();
// Create the tenant with a custom admin user.
await context.CreateAndSwitchToTenantAsync(
TestTenantName,
TestTenantUrlPrefix,
new OrchardCoreSetupParameters
{
SiteName = TestTenantDisplayName,
RecipeId = "Lombiq.OSOCE.Tests",
TablePrefix = TestTenantUrlPrefix,
UserName = tenantAdminName,
});
// Verify successful setup with custom site name.
context
.Get(By.ClassName("navbar-brand"))
.Text
.ShouldBe(TestTenantDisplayName);
await context.SignInDirectlyAsync(tenantAdminName);
(await context.GetCurrentUserNameAsync()).ShouldBe(tenantAdminName);
context.GetCurrentUri().AbsolutePath.ShouldStartWith($"/{TestTenantUrlPrefix}");
context.SwitchCurrentTenantToDefault();
(await context.GetCurrentUserNameAsync()).ShouldBe(DefaultUser.UserName);
context.GetCurrentUri().AbsolutePath.ShouldNotStartWith($"/{TestTenantUrlPrefix}");
});
}
// END OF TRAINING SECTION: Testing in tenants.
// NEXT STATION: Head over to InteractiveModeTests.cs.