diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxGroupDefinitionWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxGroupDefinitionWidgetTests.cs index 3ae0ec372..2f6a2b4c0 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxGroupDefinitionWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxGroupDefinitionWidgetTests.cs @@ -1,22 +1,23 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using System.Text.Json; using Unity.Flex.Web.Views.Shared.Components.CheckboxGroupDefinitionWidget; using Unity.Flex.Worksheets.Definitions; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class CheckboxGroupDefinitionWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class CheckboxGroupDefinitionWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public CheckboxGroupDefinitionWidgetTests() + public CheckboxGroupDefinitionWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxGroupWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxGroupWidgetTests.cs index 2dad6b56e..ce6dc3d95 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxGroupWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxGroupWidgetTests.cs @@ -1,21 +1,22 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Unity.Flex.Web.Views.Shared.Components.CheckboxGroupWidget; using Unity.Flex.Web.Views.Shared.Components.WorksheetInstanceWidget.ViewModels; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class CheckboxGroupWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class CheckboxGroupWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public CheckboxGroupWidgetTests() + public CheckboxGroupWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxWidgetTests.cs index d50ed7d57..6a9353f98 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CheckboxWidgetTests.cs @@ -1,21 +1,22 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Unity.Flex.Web.Views.Shared.Components.CheckboxWidget; using Unity.Flex.Web.Views.Shared.Components.WorksheetInstanceWidget.ViewModels; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class CheckboxWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class CheckboxWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public CheckboxWidgetTests() + public CheckboxWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/ComponentTestFixture.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/ComponentTestFixture.cs new file mode 100644 index 000000000..731cb41c9 --- /dev/null +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/ComponentTestFixture.cs @@ -0,0 +1,45 @@ +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Hosting; +using Unity.GrantManager; +using Unity.Modules.Shared.MessageBrokers.RabbitMQ.Interfaces; + +namespace Unity.Flex.Web.Tests.Components; + +public class ComponentTestFixture : WebApplicationFactory +{ + protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) + { + builder.ConfigureServices(services => + { + var hostedServices = services + .Where(d => typeof(IHostedService) + .IsAssignableFrom(d.ServiceType)) + .ToList(); + + foreach (var descriptor in hostedServices) + { + if (descriptor.ImplementationType?.Namespace?.Contains("RabbitMQ") == true) + { + services.Remove(descriptor); + } + } + +if (OperatingSystem.IsWindows()) + { + services.RemoveAll(); + } + + services.Replace( + ServiceDescriptor.Singleton() + ); + }); + } +} + +[CollectionDefinition(ComponentTestCollection.Name)] +public class ComponentTestCollection : ICollectionFixture +{ + public const string Name = "ComponentTests"; +} diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CurrencyDefinitionWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CurrencyDefinitionWidgetTests.cs index 8815b4730..54a780f2f 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CurrencyDefinitionWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CurrencyDefinitionWidgetTests.cs @@ -1,23 +1,23 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using System.Text.Json; using Unity.Flex.Web.Views.Shared.Components.CurrencyDefinitionWidget; using Unity.Flex.Worksheets.Definitions; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class CurrencyDefinitionWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class CurrencyDefinitionWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public CurrencyDefinitionWidgetTests() + public CurrencyDefinitionWidgetTests(ComponentTestFixture fixture) { - // Lazily resolve services needed by the ViewComponent - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CurrencyWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CurrencyWidgetTests.cs index d566f5dc2..8389402f3 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CurrencyWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/CurrencyWidgetTests.cs @@ -1,21 +1,22 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Unity.Flex.Web.Views.Shared.Components.CurrencyWidget; using Unity.Flex.Web.Views.Shared.Components.WorksheetInstanceWidget.ViewModels; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class CurrencyWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class CurrencyWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public CurrencyWidgetTests() + public CurrencyWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/DataGridDefinitionWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/DataGridDefinitionWidgetTests.cs index 62ec7d722..35e7663b1 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/DataGridDefinitionWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/DataGridDefinitionWidgetTests.cs @@ -1,22 +1,23 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using System.Text.Json; using Unity.Flex.Web.Views.Shared.Components.DataGridDefinitionWidget; using Unity.Flex.Worksheets.Definitions; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class DataGridDefinitionWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class DataGridDefinitionWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public DataGridDefinitionWidgetTests() + public DataGridDefinitionWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/DataGridWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/DataGridWidgetTests.cs index 6e18ab44d..0fab52c5d 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/DataGridWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/DataGridWidgetTests.cs @@ -1,21 +1,22 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Unity.Flex.Web.Views.Shared.Components.DataGridWidget; using Unity.Flex.Web.Views.Shared.Components.WorksheetInstanceWidget.ViewModels; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class DataGridWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class DataGridWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public DataGridWidgetTests() + public DataGridWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/RadioWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/RadioWidgetTests.cs index 67c69a018..c79d83181 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/RadioWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/RadioWidgetTests.cs @@ -1,21 +1,22 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Unity.Flex.Web.Views.Shared.Components.RadioWidget; using Unity.Flex.Web.Views.Shared.Components.WorksheetInstanceWidget.ViewModels; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class RadioWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class RadioWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public RadioWidgetTests() + public RadioWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/SelectListDefinitionWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/SelectListDefinitionWidgetTests.cs index a63c2c36e..95ef22e1d 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/SelectListDefinitionWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/SelectListDefinitionWidgetTests.cs @@ -1,22 +1,23 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using System.Text.Json; using Unity.Flex.Web.Views.Shared.Components.SelectListDefinitionWidget; using Unity.Flex.Worksheets.Definitions; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class SelectListDefinitionWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class SelectListDefinitionWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public SelectListDefinitionWidgetTests() + public SelectListDefinitionWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/SelectListWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/SelectListWidgetTests.cs index 167b2d182..245fb1e37 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/SelectListWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/SelectListWidgetTests.cs @@ -1,21 +1,22 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Unity.Flex.Web.Views.Shared.Components.SelectListWidget; using Unity.Flex.Web.Views.Shared.Components.WorksheetInstanceWidget.ViewModels; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class SelectListWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class SelectListWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public SelectListWidgetTests() + public SelectListWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextAreaDefinitionWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextAreaDefinitionWidgetTests.cs index 029d54586..66d091906 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextAreaDefinitionWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextAreaDefinitionWidgetTests.cs @@ -1,22 +1,23 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using System.Text.Json; using Unity.Flex.Web.Views.Shared.Components.TextAreaDefinitionWidget; using Unity.Flex.Worksheets.Definitions; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class TextAreaDefinitionWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class TextAreaDefinitionWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public TextAreaDefinitionWidgetTests() + public TextAreaDefinitionWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextAreaWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextAreaWidgetTests.cs index f8cbf63d7..5e1f09518 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextAreaWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextAreaWidgetTests.cs @@ -1,21 +1,22 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Unity.Flex.Web.Views.Shared.Components.TextAreaWidget; using Unity.Flex.Web.Views.Shared.Components.WorksheetInstanceWidget.ViewModels; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class TextAreaWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class TextAreaWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public TextAreaWidgetTests() + public TextAreaWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextDefinitionWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextDefinitionWidgetTests.cs index 065af83a5..ea5de7302 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextDefinitionWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/TextDefinitionWidgetTests.cs @@ -1,22 +1,23 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using System.Text.Json; using Unity.Flex.Web.Views.Shared.Components.TextDefinitionWidget; using Unity.Flex.Worksheets.Definitions; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class TextDefinitionWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class TextDefinitionWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public TextDefinitionWidgetTests() + public TextDefinitionWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/YesNoWidgetTests.cs b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/YesNoWidgetTests.cs index 145cb3ea9..c56a19980 100644 --- a/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/YesNoWidgetTests.cs +++ b/applications/Unity.GrantManager/modules/Unity.Flex/test/Unity.Flex.Web.Tests/Components/YesNoWidgetTests.cs @@ -1,21 +1,22 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using Shouldly; using Unity.Flex.Web.Views.Shared.Components.WorksheetInstanceWidget.ViewModels; using Unity.Flex.Web.Views.Shared.Components.YesNoWidget; -using Unity.GrantManager; using Volo.Abp.DependencyInjection; namespace Unity.Flex.Web.Tests.Components { - public class YesNoWidgetTests : GrantManagerWebTestBase + [Collection(ComponentTestCollection.Name)] + public class YesNoWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public YesNoWidgetTests() + public YesNoWidgetTests(ComponentTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicantInfoWidgetTests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicantInfoWidgetTests.cs index 77551b3d5..018a68911 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicantInfoWidgetTests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicantInfoWidgetTests.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Shouldly; using System; @@ -15,13 +16,14 @@ namespace Unity.GrantManager.Components { - public class ApplicantInfoWidgetTests : GrantManagerWebTestBase + [Collection(WebTestCollection.Name)] + public class ApplicantInfoWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public ApplicantInfoWidgetTests() + public ApplicantInfoWidgetTests(WebTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationContactWidgetTests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationContactWidgetTests.cs index 9b59458b0..a2a78f9f5 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationContactWidgetTests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationContactWidgetTests.cs @@ -12,14 +12,9 @@ namespace Unity.GrantManager.Components { - public class ApplicationContactWidgetTests : GrantManagerWebTestBase + [Collection(WebTestCollection.Name)] + public class ApplicationContactWidgetTests { - public ApplicationContactWidgetTests() - { - // Disable logging to avoid disposed logger errors during tests - Environment.SetEnvironmentVariable("Logging:LogLevel:Default", "None"); - } - [Fact] public async Task ApplicationContactWidgetReturnsStatus() { diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationStatusWidgetTests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationStatusWidgetTests.cs index 31fd866bf..387684542 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationStatusWidgetTests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationStatusWidgetTests.cs @@ -12,6 +12,7 @@ namespace Unity.GrantManager.Components { + [Collection(WebTestCollection.Name)] public class ApplicationStatusWidgetTests { public ApplicationStatusWidgetTests() diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationTagWidgetTests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationTagWidgetTests.cs index 42d1b1006..c98a74854 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationTagWidgetTests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ApplicationTagWidgetTests.cs @@ -13,7 +13,8 @@ namespace Unity.GrantManager.Components { - public class ApplicationTagsWidgetTests : GrantManagerWebTestBase + [Collection(WebTestCollection.Name)] + public class ApplicationTagsWidgetTests { [Fact] public async Task ApplicationTagsWidgetReturnsStatus() diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/AssessmentScoresWidgetTests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/AssessmentScoresWidgetTests.cs index b46bac967..332fb0953 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/AssessmentScoresWidgetTests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/AssessmentScoresWidgetTests.cs @@ -14,7 +14,8 @@ namespace Unity.GrantManager.Components { - public class AssessmentScoresWidgetTests : GrantManagerWebTestBase + [Collection(WebTestCollection.Name)] + public class AssessmentScoresWidgetTests { [Fact] public async Task AssessmentScoresWidgetReturnsStatus() diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/AttachmentControllerTests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/AttachmentControllerTests.cs index bf2318ffb..d1f2bcc3f 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/AttachmentControllerTests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/AttachmentControllerTests.cs @@ -13,7 +13,8 @@ namespace Unity.GrantManager.Components { - public class AttachmentControllerTests : GrantManagerWebTestBase + [Collection(WebTestCollection.Name)] + public class AttachmentControllerTests { [Fact] public async Task UploadApplicationAttachments_InvalidInput_ReturnsBadRequest() diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/FundingAgreementInfoWidgetTests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/FundingAgreementInfoWidgetTests.cs index 3e301ff66..e7b1b902d 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/FundingAgreementInfoWidgetTests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/FundingAgreementInfoWidgetTests.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Shouldly; using System; @@ -12,13 +13,14 @@ namespace Unity.GrantManager.Components { - public class FundingAgreementInfoWidgetTests : GrantManagerWebTestBase + [Collection(WebTestCollection.Name)] + public class FundingAgreementInfoWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public FundingAgreementInfoWidgetTests() + public FundingAgreementInfoWidgetTests(WebTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ProjectInfoWidgetTests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ProjectInfoWidgetTests.cs index 1ef14f6c3..44a4ed0ea 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ProjectInfoWidgetTests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/ProjectInfoWidgetTests.cs @@ -11,31 +11,20 @@ using Volo.Abp.DependencyInjection; using Xunit; using Microsoft.AspNetCore.Authorization; - using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; namespace Unity.GrantManager.Components { - public class ProjectInfoWidgetTests : GrantManagerWebTestBase + [Collection(WebTestCollection.Name)] + public class ProjectInfoWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; + private readonly IAuthorizationService authorizationService; - public ProjectInfoWidgetTests() + public ProjectInfoWidgetTests(WebTestFixture fixture) { - // Remove EventLog logger provider to prevent ObjectDisposedException during tests - var loggerFactory = GetRequiredService(); - foreach (var provider in loggerFactory - .GetType() - .GetField("_providers", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) - ?.GetValue(loggerFactory) as System.Collections.Generic.List ?? new System.Collections.Generic.List()) - { - if (provider.GetType().Name.Contains("EventLog")) - { - provider.Dispose(); - } - } - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); + authorizationService = fixture.Services.GetRequiredService(); } [Fact] @@ -56,9 +45,6 @@ public async Task ContactInfoReturnsStatus() var electoralDistrictService = Substitute.For(); var regionalDistrictService = Substitute.For(); var communitiesService = Substitute.For(); - var authorizationService = GetRequiredService(); - - var viewContext = new ViewContext { HttpContext = new DefaultHttpContext() @@ -68,7 +54,7 @@ public async Task ContactInfoReturnsStatus() ViewContext = viewContext }; - var viewComponent = new ProjectInfoViewComponent(appService, economicRegionService, electoralDistrictService, regionalDistrictService, communitiesService, authorizationService) + var viewComponent = new ProjectInfoViewComponent(appService, economicRegionService, electoralDistrictService, regionalDistrictService, communitiesService, this.authorizationService) { ViewComponentContext = viewComponentContext, LazyServiceProvider = lazyServiceProvider diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/SummaryWidgetTests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/SummaryWidgetTests.cs index 6844c62bc..11d6f2461 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/SummaryWidgetTests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Components/SummaryWidgetTests.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.Extensions.DependencyInjection; using NSubstitute; using Shouldly; using System; @@ -14,13 +15,14 @@ namespace Unity.GrantManager.Components { - public class SummaryWidgetTests : GrantManagerWebTestBase + [Collection(WebTestCollection.Name)] + public class SummaryWidgetTests { private readonly IAbpLazyServiceProvider lazyServiceProvider; - public SummaryWidgetTests() + public SummaryWidgetTests(WebTestFixture fixture) { - lazyServiceProvider = GetRequiredService(); + lazyServiceProvider = fixture.Services.GetRequiredService(); } [Fact] diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestBase.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestBase.cs deleted file mode 100644 index 219a06211..000000000 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestBase.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Text.Json; -using System.Text.Json.Serialization; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Shouldly; -using Unity.Modules.Shared.MessageBrokers.RabbitMQ.Interfaces; -using Volo.Abp.AspNetCore.TestBase; - -namespace Unity.GrantManager; - -public abstract class GrantManagerWebTestBase : AbpWebApplicationFactoryIntegratedTest -{ - public static readonly JsonSerializerOptions JsonOptions = new() - { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull - }; - - protected override void ConfigureServices(IServiceCollection services) - { - // - // 🔹 Remove ALL RabbitMQ hosted services (consumers, registrators, etc.) - // - var hostedServices = services - .Where(d => typeof(Microsoft.Extensions.Hosting.IHostedService) - .IsAssignableFrom(d.ServiceType)) - .ToList(); - - foreach (var descriptor in hostedServices) - { - // Only strip RabbitMQ-related hosted services - if (descriptor.ImplementationType?.Namespace?.Contains("RabbitMQ") == true) - { - services.Remove(descriptor); - } - } - -#if WINDOWS - // 🔹 Remove EventLog logger to avoid ObjectDisposedException in tests - services.RemoveAll(); -#endif - - // - // 🔹 Replace real channel provider with fake - // - services.Replace( - ServiceDescriptor.Singleton() - ); - - base.ConfigureServices(services); - } - - protected virtual async Task GetResponseAsObjectAsync( - string url, - HttpStatusCode expectedStatusCode = HttpStatusCode.OK) - { - var strResponse = await GetResponseAsStringAsync(url, expectedStatusCode); - return JsonSerializer.Deserialize(strResponse, JsonOptions); - } - - protected virtual async Task GetResponseAsStringAsync( - string url, - HttpStatusCode expectedStatusCode = HttpStatusCode.OK) - { - var response = await GetResponseAsync(url, expectedStatusCode); - return await response.Content.ReadAsStringAsync(); - } - - protected virtual async Task GetResponseAsync( - string url, - HttpStatusCode expectedStatusCode = HttpStatusCode.OK) - { - var response = await Client.GetAsync(url); - response.StatusCode.ShouldBe(expectedStatusCode); - return response; - } -} diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestModule.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestModule.cs index 7d50f306b..b93bf83e6 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestModule.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestModule.cs @@ -19,7 +19,7 @@ namespace Unity.GrantManager; [DependsOn( typeof(AbpAspNetCoreTestBaseModule), typeof(GrantManagerWebModule), - typeof(GrantManagerApplicationTestModule) + typeof(WebTestInMemoryDbModule) )] public class GrantManagerWebTestModule : AbpModule { diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestStartup.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestStartup.cs deleted file mode 100644 index 913871a3a..000000000 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/GrantManagerWebTestStartup.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; - -namespace Unity.GrantManager; - -public static class GrantManagerWebTestStartup -{ - public static void ConfigureServices(IServiceCollection services) - { - services.AddApplication(); - } - - public static void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) - { - app.InitializeApplication(); - } -} diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Pages/Index_Tests.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Pages/Index_Tests.cs index 367e6cde3..9e1c80056 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Pages/Index_Tests.cs +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Pages/Index_Tests.cs @@ -1,15 +1,27 @@ -using System.Threading.Tasks; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; using Shouldly; using Xunit; namespace Unity.GrantManager.Pages; -public class Index_Tests : GrantManagerWebTestBase +[Collection(WebTestCollection.Name)] +public class Index_Tests { + private readonly HttpClient _client; + + public Index_Tests(WebTestFixture fixture) + { + _client = fixture.CreateClient(); + } + [Fact] public async Task Welcome_Page() { - var response = await GetResponseAsStringAsync("/"); - response.ShouldNotBeNull(); + var response = await _client.GetAsync("/"); + response.StatusCode.ShouldBe(HttpStatusCode.OK); + var content = await response.Content.ReadAsStringAsync(); + content.ShouldNotBeNullOrEmpty(); } } diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Unity.GrantManager.Web.Tests.csproj b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Unity.GrantManager.Web.Tests.csproj index e493fd408..608f44b10 100644 --- a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Unity.GrantManager.Web.Tests.csproj +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/Unity.GrantManager.Web.Tests.csproj @@ -21,6 +21,7 @@ + @@ -29,7 +30,7 @@ - + diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/WebTestFixture.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/WebTestFixture.cs new file mode 100644 index 000000000..1c3cc469b --- /dev/null +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/WebTestFixture.cs @@ -0,0 +1,47 @@ +using System; +using System.Linq; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Hosting; +using Unity.Modules.Shared.MessageBrokers.RabbitMQ.Interfaces; +using Xunit; + +namespace Unity.GrantManager; + +public class WebTestFixture : WebApplicationFactory +{ + protected override void ConfigureWebHost(Microsoft.AspNetCore.Hosting.IWebHostBuilder builder) + { + builder.ConfigureServices(services => + { + var hostedServices = services + .Where(d => typeof(IHostedService) + .IsAssignableFrom(d.ServiceType)) + .ToList(); + + foreach (var descriptor in hostedServices) + { + if (descriptor.ImplementationType?.Namespace?.Contains("RabbitMQ") == true) + { + services.Remove(descriptor); + } + } + +if (OperatingSystem.IsWindows()) + { + services.RemoveAll(); + } + + services.Replace( + ServiceDescriptor.Singleton() + ); + }); + } +} + +[CollectionDefinition(WebTestCollection.Name)] +public class WebTestCollection : ICollectionFixture +{ + public const string Name = "WebTests"; +} diff --git a/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/WebTestInMemoryDbModule.cs b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/WebTestInMemoryDbModule.cs new file mode 100644 index 000000000..85172f8e1 --- /dev/null +++ b/applications/Unity.GrantManager/test/Unity.GrantManager.Web.Tests/WebTestInMemoryDbModule.cs @@ -0,0 +1,51 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Unity.GrantManager.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore.GlobalFilters; +using Volo.Abp.FeatureManagement; +using Volo.Abp.Modularity; +using Volo.Abp.PermissionManagement; +using Volo.Abp.Uow; + +namespace Unity.GrantManager; + +[DependsOn( + typeof(GrantManagerEntityFrameworkCoreModule), + typeof(GrantManagerTestBaseModule) +)] +public class WebTestInMemoryDbModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.SaveStaticFeaturesToDatabase = false; + options.IsDynamicFeatureStoreEnabled = false; + }); + + Configure(options => + { + options.SaveStaticPermissionsToDatabase = false; + options.IsDynamicPermissionStoreEnabled = false; + }); + + Configure(options => + { + options.UseDbFunction = false; + }); + + context.Services.AddAlwaysDisableUnitOfWorkTransaction(); + + var inMemoryDatabaseName = $"WebTests_{System.Guid.NewGuid():N}"; + + Configure(options => + { + options.Configure(abpDbContextConfigurationContext => + { + abpDbContextConfigurationContext.DbContextOptions + .UseInMemoryDatabase(inMemoryDatabaseName); + }); + }); + } +}