From ed75f46054290292a3fc2e5943522a0048d1771e Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 12 Oct 2024 14:34:23 -0400 Subject: [PATCH] InvokeAsync_UnInitializedShell_PerformsSetup --- .../AutoSetupMiddlewareTests.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/OrchardCore.Tests/Modules/OrchardCore.AutoSetup/AutoSetupMiddlewareTests.cs b/test/OrchardCore.Tests/Modules/OrchardCore.AutoSetup/AutoSetupMiddlewareTests.cs index 98bf0976404..50d5b5b3f07 100644 --- a/test/OrchardCore.Tests/Modules/OrchardCore.AutoSetup/AutoSetupMiddlewareTests.cs +++ b/test/OrchardCore.Tests/Modules/OrchardCore.AutoSetup/AutoSetupMiddlewareTests.cs @@ -103,6 +103,39 @@ public async Task InvokeAsync_FailedSetup_ReturnsServiceUnavailable() Assert.Equal(StatusCodes.Status503ServiceUnavailable, httpContext.Response.StatusCode); } + [Fact] + public async Task InvokeAsync_UnInitializedShell_PerformsSetup() + { + // Arrange + _shellSettings.State = TenantState.Uninitialized; + + SetupDistributedLockMock(true); + + var setupContext = new SetupContext(); + _mockAutoSetupService.Setup(s => s.SetupTenantAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync((setupContext, true)); + + var httpContext = new DefaultHttpContext(); + httpContext.RequestServices = new ServiceCollection() + .AddSingleton(_mockAutoSetupService.Object) + .BuildServiceProvider(); + + var middleware = new AutoSetupMiddleware( + next: (innerHttpContext) => Task.CompletedTask, + _mockShellHost.Object, + _shellSettings, + _mockShellSettingsManager.Object, + _mockDistributedLock.Object, + _mockOptions.Object); + + // Act + await middleware.InvokeAsync(httpContext); + + // Assert + Assert.Equal(StatusCodes.Status302Found, httpContext.Response.StatusCode); // Redirect + _mockAutoSetupService.Verify(s => s.SetupTenantAsync(It.IsAny(), It.IsAny()), Times.Once); + } + [Fact] public async Task InvokeAsync_FailedLockAcquisition_ThrowsTimeoutException() {