diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1b9bf32..10e329c 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -30,7 +30,7 @@ jobs: run: dotnet restore ${{ env.SOLUTION }} - name: Build - run: dotnet build ${{ env.SOLUTION }} --no-restore + run: dotnet build ${{ env.SOLUTION }} -c Release --no-restore - name: Test - run: dotnet test ${{env.SOLUTION }} --no-build --verbosity normal + run: dotnet test ${{env.SOLUTION }} -c Release --no-build --verbosity normal diff --git a/Directory.Packages.props b/Directory.Packages.props index 90fd0f8..a3a6442 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -37,7 +37,8 @@ + - + \ No newline at end of file diff --git a/TeamUp.sln b/TeamUp.sln index a1b7572..cc03b0f 100644 --- a/TeamUp.sln +++ b/TeamUp.sln @@ -30,6 +30,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.ArchitectureTests", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.EndToEndTests", "tests\TeamUp.EndToEndTests\TeamUp.EndToEndTests.csproj", "{63C1F34E-C706-43AC-A98B-E9530F875FFA}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.PerformanceTests", "tests\TeamUp.PerformanceTests\TeamUp.PerformanceTests.csproj", "{B80B3E02-0B98-4ABA-92A9-74AEEEF76423}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.TestsCommon", "tests\TeamUp.TestsCommon\TeamUp.TestsCommon.csproj", "{A3D136DD-571F-4B1C-83E2-9B538F85C575}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{F77B386C-FDBC-4BB4-AF07-0CF054DBDB7E}" @@ -79,6 +81,10 @@ Global {A3D136DD-571F-4B1C-83E2-9B538F85C575}.Debug|Any CPU.Build.0 = Debug|Any CPU {A3D136DD-571F-4B1C-83E2-9B538F85C575}.Release|Any CPU.ActiveCfg = Release|Any CPU {A3D136DD-571F-4B1C-83E2-9B538F85C575}.Release|Any CPU.Build.0 = Release|Any CPU + {B80B3E02-0B98-4ABA-92A9-74AEEEF76423}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B80B3E02-0B98-4ABA-92A9-74AEEEF76423}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B80B3E02-0B98-4ABA-92A9-74AEEEF76423}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B80B3E02-0B98-4ABA-92A9-74AEEEF76423}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -93,6 +99,7 @@ Global {BFC0159D-37D8-494F-90A6-DA3EA05CFDEF} = {B78B958B-7250-4FEC-96F4-4FE0DE49D916} {63C1F34E-C706-43AC-A98B-E9530F875FFA} = {B78B958B-7250-4FEC-96F4-4FE0DE49D916} {A3D136DD-571F-4B1C-83E2-9B538F85C575} = {B78B958B-7250-4FEC-96F4-4FE0DE49D916} + {B80B3E02-0B98-4ABA-92A9-74AEEEF76423} = {B78B958B-7250-4FEC-96F4-4FE0DE49D916} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {2E9D991D-377D-45D8-9599-801391683CEA} diff --git a/src/TeamUp.Common/Extensions.cs b/src/TeamUp.Common/Extensions.cs new file mode 100644 index 0000000..7e797ff --- /dev/null +++ b/src/TeamUp.Common/Extensions.cs @@ -0,0 +1,6 @@ +namespace TeamUp.Common; + +public static class Extensions +{ + public static TResult Map(this T source, Func transform) => transform(source); +} diff --git a/tests/TeamUp.EndToEndTests/DataGenerators/BaseGenerator.cs b/tests/TeamUp.EndToEndTests/DataGenerators/BaseGenerator.cs deleted file mode 100644 index e4c6ec4..0000000 --- a/tests/TeamUp.EndToEndTests/DataGenerators/BaseGenerator.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace TeamUp.EndToEndTests.DataGenerators; - -public abstract class BaseGenerator -{ - protected static Faker F => FExt.F; -} diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/BaseEndpointTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/BaseEndpointTests.cs index 531614d..ca4784b 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/BaseEndpointTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/BaseEndpointTests.cs @@ -11,8 +11,7 @@ namespace TeamUp.EndToEndTests.EndpointTests; [Collection(nameof(AppCollectionFixture))] public abstract class BaseEndpointTests : IAsyncLifetime { - protected static Faker F => FExt.F; - protected static object EmptyObject { get; } = new { }; + protected static Faker F => FakerExtensions.F; protected TeamApiWebApplicationFactory AppFactory { get; } protected HttpClient Client { get; } @@ -24,7 +23,7 @@ public BaseEndpointTests(TeamApiWebApplicationFactory appFactory) { AppFactory = appFactory; Client = appFactory.CreateClient(); - Client.BaseAddress = new Uri($"https://{Client.BaseAddress?.Host}:8080"); + Client.BaseAddress = new Uri($"https://{Client.BaseAddress?.Host}:{TeamApiWebApplicationFactory.HTTPS_PORT}"); Inbox = appFactory.Services.GetRequiredService(); BackgroundCallback = appFactory.Services.GetRequiredService(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Events/BaseEventTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Events/BaseEventTests.cs index 4fe8dd6..197a3cb 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Events/BaseEventTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Events/BaseEventTests.cs @@ -1,6 +1,4 @@ -using TeamUp.Contracts.Events; - -namespace TeamUp.EndToEndTests.EndpointTests.Events; +namespace TeamUp.EndToEndTests.EndpointTests.Events; public abstract class BaseEventTests : BaseEndpointTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Events/CreateEventTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Events/CreateEventTests.cs index b123c5b..c370eae 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Events/CreateEventTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Events/CreateEventTests.cs @@ -1,7 +1,4 @@ -using TeamUp.Contracts.Events; -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.EndpointTests.Events; +namespace TeamUp.EndToEndTests.EndpointTests.Events; public sealed class CreateEventTests : BaseEventTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Events/GetEventTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Events/GetEventTests.cs index bd31e21..6683624 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Events/GetEventTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Events/GetEventTests.cs @@ -1,7 +1,4 @@ -using TeamUp.Contracts.Events; -using TeamUp.Contracts.Teams; - -using EventResponse = TeamUp.Contracts.Events.EventResponse; +using EventResponse = TeamUp.Contracts.Events.EventResponse; namespace TeamUp.EndToEndTests.EndpointTests.Events; diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Events/GetEventsTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Events/GetEventsTests.cs index 9b5410a..f9398e0 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Events/GetEventsTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Events/GetEventsTests.cs @@ -1,9 +1,4 @@ -using FluentAssertions.Extensions; - -using TeamUp.Contracts.Events; -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.EndpointTests.Events; +namespace TeamUp.EndToEndTests.EndpointTests.Events; public sealed class GetEventsTests : BaseEventTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Events/UpsertEventReplyTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Events/UpsertEventReplyTests.cs index b561eda..842ae5e 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Events/UpsertEventReplyTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Events/UpsertEventReplyTests.cs @@ -1,8 +1,5 @@ using Microsoft.EntityFrameworkCore; -using TeamUp.Contracts.Events; -using TeamUp.Contracts.Teams; - using EventResponse = TeamUp.Domain.Aggregates.Events.EventResponse; namespace TeamUp.EndToEndTests.EndpointTests.Events; diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/HttpsRedirectionTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/HttpsRedirectionTests.cs index 05a5046..53cf82b 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/HttpsRedirectionTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/HttpsRedirectionTests.cs @@ -11,8 +11,6 @@ namespace TeamUp.EndToEndTests.EndpointTests; [Collection(nameof(AppCollectionFixture))] public sealed class HttpsRedirectionTests : IAsyncLifetime { - private static Faker F => FExt.F; - private readonly TeamApiWebApplicationFactory _appFactory; private readonly HttpClient _client; @@ -44,7 +42,7 @@ private void Authenticate(User user) public async Task HttpRequest_ToHealthCheckEndpoint_Should_RedirectToHttps() { //arrange - var expectedLocation = $"https://{_client.BaseAddress?.Host}:8080/_health"; + var expectedLocation = $"https://{_client.BaseAddress?.Host}:{TeamApiWebApplicationFactory.HTTPS_PORT}/_health"; //act var response = await _client.GetAsync("/_health"); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/AcceptInvitationTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/AcceptInvitationTests.cs index 06df1d4..33c0f7f 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/AcceptInvitationTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/AcceptInvitationTests.cs @@ -1,8 +1,5 @@ using Microsoft.EntityFrameworkCore; -using TeamUp.Contracts.Invitations; -using TeamUp.Contracts.Teams; - namespace TeamUp.EndToEndTests.EndpointTests.Invitations; public sealed class AcceptInvitationTests : BaseInvitationTests diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetMyInvitationsTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetMyInvitationsTests.cs index c7d0305..d2c3a57 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetMyInvitationsTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetMyInvitationsTests.cs @@ -1,6 +1,4 @@ -using TeamUp.Contracts.Invitations; - -namespace TeamUp.EndToEndTests.EndpointTests.Invitations; +namespace TeamUp.EndToEndTests.EndpointTests.Invitations; public sealed class GetMyInvitationsTests : BaseInvitationTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetTeamInvitationsTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetTeamInvitationsTests.cs index 6b0e037..d572b88 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetTeamInvitationsTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/GetTeamInvitationsTests.cs @@ -1,7 +1,4 @@ -using TeamUp.Contracts.Invitations; -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.EndpointTests.Invitations; +namespace TeamUp.EndToEndTests.EndpointTests.Invitations; public sealed class GetTeamInvitationsTests : BaseInvitationTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/InviteUserTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/InviteUserTests.cs index e65aa6b..da7f4a5 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/InviteUserTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/InviteUserTests.cs @@ -1,8 +1,4 @@ -using TeamUp.Contracts.Invitations; -using TeamUp.Contracts.Teams; -using TeamUp.Contracts.Users; - -namespace TeamUp.EndToEndTests.EndpointTests.Invitations; +namespace TeamUp.EndToEndTests.EndpointTests.Invitations; public sealed class InviteUserTests : BaseInvitationTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/RemoveInvitationTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/RemoveInvitationTests.cs index 984024e..f2a904b 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/RemoveInvitationTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Invitations/RemoveInvitationTests.cs @@ -1,7 +1,4 @@ -using TeamUp.Contracts.Invitations; -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.EndpointTests.Invitations; +namespace TeamUp.EndToEndTests.EndpointTests.Invitations; public sealed class RemoveInvitationTests : BaseInvitationTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeNicknameTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeNicknameTests.cs index 088fbbd..15898d4 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeNicknameTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeNicknameTests.cs @@ -1,7 +1,5 @@ using Microsoft.EntityFrameworkCore; -using TeamUp.Contracts.Teams; - namespace TeamUp.EndToEndTests.EndpointTests.Teams; public sealed class ChangeNicknameTests : BaseTeamTests diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeOwnershipTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeOwnershipTests.cs index 691bf41..028cbcf 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeOwnershipTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/ChangeOwnershipTests.cs @@ -1,7 +1,5 @@ using Microsoft.EntityFrameworkCore; -using TeamUp.Contracts.Teams; - namespace TeamUp.EndToEndTests.EndpointTests.Teams; public sealed class ChangeOwnershipTests : BaseTeamTests diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateEventTypeTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateEventTypeTests.cs index 5e35892..e4903c5 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateEventTypeTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateEventTypeTests.cs @@ -1,6 +1,4 @@ -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.EndpointTests.Teams; +namespace TeamUp.EndToEndTests.EndpointTests.Teams; public sealed class CreateEventTypeTests : BaseTeamTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateTeamTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateTeamTests.cs index 955322b..e58ef63 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateTeamTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/CreateTeamTests.cs @@ -1,7 +1,5 @@ using Microsoft.EntityFrameworkCore; -using TeamUp.Contracts.Teams; - namespace TeamUp.EndToEndTests.EndpointTests.Teams; public sealed class CreateTeamTests : BaseTeamTests diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/DeleteTeamTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/DeleteTeamTests.cs index efa3c57..e670322 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/DeleteTeamTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/DeleteTeamTests.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore; -using TeamUp.Contracts.Teams; +using EventResponse = TeamUp.Domain.Aggregates.Events.EventResponse; namespace TeamUp.EndToEndTests.EndpointTests.Teams; diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/GetTeamTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/GetTeamTests.cs index 1a1374d..f35da17 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/GetTeamTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/GetTeamTests.cs @@ -1,6 +1,4 @@ -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.EndpointTests.Teams; +namespace TeamUp.EndToEndTests.EndpointTests.Teams; public sealed class GetTeamTests : BaseTeamTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/RemoveTeamMemberTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/RemoveTeamMemberTests.cs index 489a108..e6f03a7 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/RemoveTeamMemberTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/RemoveTeamMemberTests.cs @@ -1,6 +1,4 @@ -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.EndpointTests.Teams; +namespace TeamUp.EndToEndTests.EndpointTests.Teams; public sealed class RemoveTeamMemberTests : BaseTeamTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamMemberRoleTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamMemberRoleTests.cs index dd906dd..30c4ae8 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamMemberRoleTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamMemberRoleTests.cs @@ -1,7 +1,5 @@ using Microsoft.EntityFrameworkCore; -using TeamUp.Contracts.Teams; - namespace TeamUp.EndToEndTests.EndpointTests.Teams; public sealed class UpdateTeamMemberRoleTests : BaseTeamTests diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamNameTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamNameTests.cs index ae6f0d3..bc3115a 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamNameTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/Teams/UpdateTeamNameTests.cs @@ -1,6 +1,4 @@ -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.EndpointTests.Teams; +namespace TeamUp.EndToEndTests.EndpointTests.Teams; public sealed class UpdateTeamNameTests : BaseTeamTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/ActivateAccountTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/ActivateAccountTests.cs index c905793..49d3a85 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/ActivateAccountTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/ActivateAccountTests.cs @@ -1,6 +1,4 @@ -using TeamUp.Contracts.Users; - -namespace TeamUp.EndToEndTests.EndpointTests.UserAccess; +namespace TeamUp.EndToEndTests.EndpointTests.UserAccess; public sealed class ActivateAccountTests : BaseUserAccessTests { @@ -22,7 +20,7 @@ await UseDbContextAsync(dbContext => }); //act - var response = await Client.PostAsJsonAsync(GetUrl(user.Id), EmptyObject); + var response = await Client.PostAsync(GetUrl(user.Id), null); //assert response.Should().Be200Ok(); diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyAccountDetailsTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyAccountDetailsTests.cs index 47a29c1..93edfee 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyAccountDetailsTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/GetMyAccountDetailsTests.cs @@ -1,6 +1,4 @@ -using TeamUp.Contracts.Users; - -namespace TeamUp.EndToEndTests.EndpointTests.UserAccess; +namespace TeamUp.EndToEndTests.EndpointTests.UserAccess; public sealed class GetMyAccountDetailsTests : BaseUserAccessTests { diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/LoginTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/LoginTests.cs index 8e8ec53..f88661e 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/LoginTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/LoginTests.cs @@ -2,7 +2,6 @@ using System.Security.Claims; using TeamUp.Application.Users; -using TeamUp.Contracts.Users; namespace TeamUp.EndToEndTests.EndpointTests.UserAccess; diff --git a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/RegisterUserTests.cs b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/RegisterUserTests.cs index b4c319a..18a4d6a 100644 --- a/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/RegisterUserTests.cs +++ b/tests/TeamUp.EndToEndTests/EndpointTests/UserAccess/RegisterUserTests.cs @@ -1,6 +1,4 @@ -using TeamUp.Contracts.Users; - -namespace TeamUp.EndToEndTests.EndpointTests.UserAccess; +namespace TeamUp.EndToEndTests.EndpointTests.UserAccess; public sealed class RegisterUserTests : BaseUserAccessTests { diff --git a/tests/TeamUp.EndToEndTests/GlobalUsings.cs b/tests/TeamUp.EndToEndTests/GlobalUsings.cs index ac1775c..961e823 100644 --- a/tests/TeamUp.EndToEndTests/GlobalUsings.cs +++ b/tests/TeamUp.EndToEndTests/GlobalUsings.cs @@ -3,19 +3,22 @@ global using Bogus; global using FluentAssertions; +global using FluentAssertions.Extensions; global using Microsoft.AspNetCore.Mvc; global using Microsoft.Extensions.DependencyInjection; +global using TeamUp.Contracts.Events; +global using TeamUp.Contracts.Invitations; +global using TeamUp.Contracts.Teams; +global using TeamUp.Contracts.Users; global using TeamUp.Domain.Aggregates.Events; global using TeamUp.Domain.Aggregates.Invitations; global using TeamUp.Domain.Aggregates.Teams; global using TeamUp.Domain.Aggregates.Users; -global using TeamUp.EndToEndTests.DataGenerators; global using TeamUp.EndToEndTests.Extensions; global using TeamUp.Infrastructure.Persistence; -global using TeamUp.TestsCommon; +global using TeamUp.TestsCommon.DataGenerators; +global using TeamUp.TestsCommon.Extensions; global using Xunit; - -global using FExt = TeamUp.TestsCommon.FakerExtensions; diff --git a/tests/TeamUp.EndToEndTests/Mocks/BackgroundCallback.cs b/tests/TeamUp.EndToEndTests/Mocks/BackgroundCallback.cs index 1f95027..cc4180b 100644 --- a/tests/TeamUp.EndToEndTests/Mocks/BackgroundCallback.cs +++ b/tests/TeamUp.EndToEndTests/Mocks/BackgroundCallback.cs @@ -1,5 +1,4 @@ - -namespace TeamUp.EndToEndTests.Mocks; +namespace TeamUp.EndToEndTests.Mocks; internal abstract class BackgroundCallback { diff --git a/tests/TeamUp.EndToEndTests/TeamApiWebApplicationFactory.cs b/tests/TeamUp.EndToEndTests/TeamApiWebApplicationFactory.cs index a28cd5c..bf5be5e 100644 --- a/tests/TeamUp.EndToEndTests/TeamApiWebApplicationFactory.cs +++ b/tests/TeamUp.EndToEndTests/TeamApiWebApplicationFactory.cs @@ -21,6 +21,8 @@ public sealed class AppCollectionFixture : ICollectionFixture, IAsyncLifetime { + public const string HTTPS_PORT = "8181"; + private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder() .WithDatabase("POSTGRES") .WithUsername("POSTGRES") @@ -76,7 +78,7 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) }); builder.UseEnvironment(Environments.Production); - builder.UseSetting("https_port", "8080"); + builder.UseSetting("https_port", HTTPS_PORT); } public new Task DisposeAsync() => _dbContainer.StopAsync(); diff --git a/tests/TeamUp.PerformanceTests/BasePerformanceTests.cs b/tests/TeamUp.PerformanceTests/BasePerformanceTests.cs new file mode 100644 index 0000000..f0992f6 --- /dev/null +++ b/tests/TeamUp.PerformanceTests/BasePerformanceTests.cs @@ -0,0 +1,89 @@ +using System.Diagnostics; +using System.Net.Http.Headers; + +using Npgsql; + +using TeamUp.Application.Users; +using TeamUp.Infrastructure.Persistence; + +using Xunit.Abstractions; + +namespace TeamUp.EndToEndTests.EndpointTests; + +[Collection(nameof(AppCollectionFixture))] +public abstract class BasePerformanceTests : IAsyncLifetime +{ + protected static Faker F => FakerExtensions.F; + + protected TeamApiWebApplicationFactory AppFactory { get; } + protected ITestOutputHelper Output { get; } + protected HttpClient Client { get; } + + public BasePerformanceTests(TeamApiWebApplicationFactory appFactory, ITestOutputHelper output) + { + AppFactory = appFactory; + Output = output; + + Client = appFactory.CreateClient(); + Client.BaseAddress = new Uri($"https://{Client.BaseAddress?.Host}:{TeamApiWebApplicationFactory.HTTPS_PORT}"); + } + + public async Task InitializeAsync() + { + await using var connection = new NpgsqlConnection(AppFactory.ConnectionString); + await connection.OpenAsync(); + await AppFactory.Respawner.ResetAsync(connection); + } + + public void Authenticate(User user) + { + var tokenService = AppFactory.Services.GetRequiredService(); + var jwt = tokenService.GenerateToken(user); + + Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt); + } + + protected async Task UseDbContextAsync(Func apply) + { + await using var scope = AppFactory.Services.CreateAsyncScope(); + + await using var dbContext = scope.ServiceProvider.GetRequiredService(); + await apply(dbContext); + + await scope.DisposeAsync(); + } + + protected async ValueTask UseDbContextAsync(Func> apply) + { + await using var scope = AppFactory.Services.CreateAsyncScope(); + + await using var dbContext = scope.ServiceProvider.GetRequiredService(); + var result = await apply(dbContext); + + await scope.DisposeAsync(); + return result; + } + + protected async Task UseDbContextAsync(Func> apply) + { + await using var scope = AppFactory.Services.CreateAsyncScope(); + + await using var dbContext = scope.ServiceProvider.GetRequiredService(); + var result = await apply(dbContext); + + await scope.DisposeAsync(); + return result; + } + + public async Task RunTestAsync(HttpRequestMessage message) + { + var timestamp = Stopwatch.GetTimestamp(); + var response = await Client.SendAsync(message); + var elapsed = Stopwatch.GetElapsedTime(timestamp); + + response.Should().Be200Ok(); + return elapsed; + } + + public Task DisposeAsync() => Task.CompletedTask; +} diff --git a/tests/TeamUp.PerformanceTests/GlobalUsings.cs b/tests/TeamUp.PerformanceTests/GlobalUsings.cs new file mode 100644 index 0000000..3fcce51 --- /dev/null +++ b/tests/TeamUp.PerformanceTests/GlobalUsings.cs @@ -0,0 +1,22 @@ +global using System.Net.Http.Json; + +global using Bogus; + +global using FluentAssertions; +global using FluentAssertions.Extensions; + +global using Microsoft.AspNetCore.Mvc; +global using Microsoft.Extensions.DependencyInjection; + +global using TeamUp.Contracts.Events; +global using TeamUp.Contracts.Invitations; +global using TeamUp.Contracts.Teams; +global using TeamUp.Contracts.Users; +global using TeamUp.Domain.Aggregates.Events; +global using TeamUp.Domain.Aggregates.Invitations; +global using TeamUp.Domain.Aggregates.Teams; +global using TeamUp.Domain.Aggregates.Users; +global using TeamUp.TestsCommon.DataGenerators; +global using TeamUp.TestsCommon.Extensions; + +global using Xunit; diff --git a/tests/TeamUp.PerformanceTests/SmokeTests/EventsSmokeTests.cs b/tests/TeamUp.PerformanceTests/SmokeTests/EventsSmokeTests.cs new file mode 100644 index 0000000..25d0ffd --- /dev/null +++ b/tests/TeamUp.PerformanceTests/SmokeTests/EventsSmokeTests.cs @@ -0,0 +1,125 @@ +using TeamUp.EndToEndTests; +using TeamUp.EndToEndTests.EndpointTests; + +using Xunit.Abstractions; + +namespace TeamUp.PerformanceTests.SmokeTests; + +public sealed class EventsSmokeTests : BasePerformanceTests +{ + public EventsSmokeTests(TeamApiWebApplicationFactory appFactory, ITestOutputHelper output) : base(appFactory, output) { } + + [Fact] + public async Task GetEvents_SmokeTest() + { + //arrange + var users = UserGenerators.ActivatedUser.Generate(2000); + var teams = TeamGenerators.Team + .WithRandomMembers(30, users) + .WithEventTypes(5) + .Generate(100); + var events = teams + .Select(team => EventGenerators.Event + .ForTeam(team.Id) + .WithEventType(team.EventTypes[0].Id) + .WithStatus(EventStatus.Open) + .WithRandomEventResponses(team.Members) + .Generate(50)) + .SelectMany(teamEvents => teamEvents) + .ToList(); + + await UseDbContextAsync(dbContext => + { + dbContext.Users.AddRange(users); + dbContext.Teams.AddRange(teams); + dbContext.Events.AddRange(events); + return dbContext.SaveChangesAsync(); + }); + + var iterations = 8; + var runs = new TimeSpan[iterations]; + + //act + for (int i = 0; i < iterations; i++) + { + var targetTeam = F.PickRandom(teams); + var initiatorMember = F.PickRandomFromReadOnlyList(targetTeam.Members); + var initiatorUser = users.First(user => user.Id == initiatorMember.UserId); + + Authenticate(initiatorUser); + + var request = new HttpRequestMessage(HttpMethod.Get, $"/api/v1/teams/{targetTeam.Id.Value}/events"); + + //act + runs[i] = await RunTestAsync(request); + + Output.WriteLine($"{i}. iteration: {runs[i]} ({runs[i].TotalMilliseconds} ms)"); + } + + //assert + var firstRun = runs[0]; + var avg = TimeSpan.FromTicks((long)runs[1..].Average(x => x.Ticks)); + + Output.WriteLine($"average time without first run: {avg} ({avg.TotalMilliseconds} ms)"); + + avg.Should().BeLessThan(TimeSpan.FromMilliseconds(15)); + firstRun.Should().BeLessThan(TimeSpan.FromMilliseconds(200)); + } + + [Fact] + public async Task GetEvent_SmokeTest() + { + var users = UserGenerators.ActivatedUser.Generate(2000); + var teams = TeamGenerators.Team + .WithRandomMembers(30, users) + .WithEventTypes(5) + .Generate(100); + var events = teams + .Select(team => EventGenerators.Event + .ForTeam(team.Id) + .WithEventType(team.EventTypes[0].Id) + .WithStatus(EventStatus.Open) + .WithRandomEventResponses(team.Members) + .Generate(50)) + .SelectMany(teamEvents => teamEvents) + .ToList(); + + await UseDbContextAsync(dbContext => + { + dbContext.Users.AddRange(users); + dbContext.Teams.AddRange(teams); + dbContext.Events.AddRange(events); + return dbContext.SaveChangesAsync(); + }); + + var iterations = 8; + var runs = new TimeSpan[iterations]; + + //act + for (int i = 0; i < iterations; i++) + { + var targetTeam = F.PickRandom(teams); + var initiatorMember = F.PickRandomFromReadOnlyList(targetTeam.Members); + var initiatorUser = users.First(user => user.Id == initiatorMember.UserId); + var targetEvent = F.PickRandom(events.Where(e => e.TeamId == targetTeam.Id)); + + Authenticate(initiatorUser); + + var request = new HttpRequestMessage(HttpMethod.Get, $"/api/v1/teams/{targetTeam.Id.Value}/events/{targetEvent.Id.Value}"); + + //act + runs[i] = await RunTestAsync(request); + + Output.WriteLine($"{i}. iteration: {runs[i]} ({runs[i].TotalMilliseconds} ms)"); + } + + //assert + var firstRun = runs[0]; + var avg = TimeSpan.FromTicks((long)runs[1..].Average(x => x.Ticks)); + + Output.WriteLine($"average time without first run: {avg} ({avg.TotalMilliseconds} ms)"); + + avg.Should().BeLessThan(TimeSpan.FromMilliseconds(15)); + firstRun.Should().BeLessThan(TimeSpan.FromMilliseconds(800)); + } +} diff --git a/tests/TeamUp.PerformanceTests/TeamApiWebApplicationFactory.cs b/tests/TeamUp.PerformanceTests/TeamApiWebApplicationFactory.cs new file mode 100644 index 0000000..c6e7edc --- /dev/null +++ b/tests/TeamUp.PerformanceTests/TeamApiWebApplicationFactory.cs @@ -0,0 +1,72 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Hosting; + +using Npgsql; + +using Respawn; + +using TeamUp.Infrastructure.Persistence; + +using Testcontainers.PostgreSql; + +namespace TeamUp.EndToEndTests; + +[CollectionDefinition(nameof(AppCollectionFixture))] +public sealed class AppCollectionFixture : ICollectionFixture; + +public sealed class TeamApiWebApplicationFactory : WebApplicationFactory, IAsyncLifetime +{ + public const string HTTPS_PORT = "8181"; + + private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder() + .WithDatabase("POSTGRES") + .WithUsername("POSTGRES") + .WithPassword("DEVPASS") + .Build(); + + public string ConnectionString => _dbContainer.GetConnectionString(); + public Respawner Respawner { get; set; } = null!; + + public async Task InitializeAsync() + { + await _dbContainer.StartAsync(); + + Randomizer.Seed = new Random(420_069); + Faker.DefaultStrictMode = true; + + await using var scope = Server.Services.CreateAsyncScope(); + await using var dbContext = scope.ServiceProvider.GetRequiredService(); + await dbContext.Database.MigrateAsync(); + + await using var connection = new NpgsqlConnection(ConnectionString); + await connection.OpenAsync(); + + Respawner = await Respawner.CreateAsync(connection, new() + { + DbAdapter = DbAdapter.Postgres + }); + } + + protected override void ConfigureWebHost(IWebHostBuilder builder) + { + builder.ConfigureServices(services => + { + //db context + services.RemoveAll(); + services.RemoveAll>(); + services.RemoveAll(); + services.AddDbContext(options => + { + options.UseNpgsql(ConnectionString); + }); + }); + + builder.UseEnvironment(Environments.Production); + builder.UseSetting("https_port", HTTPS_PORT); + } + + public new Task DisposeAsync() => _dbContainer.StopAsync(); +} diff --git a/tests/TeamUp.PerformanceTests/TeamUp.PerformanceTests.csproj b/tests/TeamUp.PerformanceTests/TeamUp.PerformanceTests.csproj new file mode 100644 index 0000000..a714c9e --- /dev/null +++ b/tests/TeamUp.PerformanceTests/TeamUp.PerformanceTests.csproj @@ -0,0 +1,28 @@ + + + + false + true + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + diff --git a/tests/TeamUp.TestsCommon/DataGenerators/BaseGenerator.cs b/tests/TeamUp.TestsCommon/DataGenerators/BaseGenerator.cs new file mode 100644 index 0000000..529f362 --- /dev/null +++ b/tests/TeamUp.TestsCommon/DataGenerators/BaseGenerator.cs @@ -0,0 +1,6 @@ +namespace TeamUp.TestsCommon.DataGenerators; + +public abstract class BaseGenerator +{ + protected static Faker F => FakerExtensions.F; +} diff --git a/tests/TeamUp.EndToEndTests/DataGenerators/EventGeneratorExtensions.cs b/tests/TeamUp.TestsCommon/DataGenerators/EventGeneratorExtensions.cs similarity index 96% rename from tests/TeamUp.EndToEndTests/DataGenerators/EventGeneratorExtensions.cs rename to tests/TeamUp.TestsCommon/DataGenerators/EventGeneratorExtensions.cs index faf6b05..d634454 100644 --- a/tests/TeamUp.EndToEndTests/DataGenerators/EventGeneratorExtensions.cs +++ b/tests/TeamUp.TestsCommon/DataGenerators/EventGeneratorExtensions.cs @@ -1,9 +1,6 @@ using FluentAssertions.Extensions; -using TeamUp.Contracts.Events; -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.DataGenerators; +namespace TeamUp.TestsCommon.DataGenerators; public static class EventGeneratorExtensions { diff --git a/tests/TeamUp.EndToEndTests/DataGenerators/EventGenerators.cs b/tests/TeamUp.TestsCommon/DataGenerators/EventGenerators.cs similarity index 98% rename from tests/TeamUp.EndToEndTests/DataGenerators/EventGenerators.cs rename to tests/TeamUp.TestsCommon/DataGenerators/EventGenerators.cs index e5e4216..5dcd588 100644 --- a/tests/TeamUp.EndToEndTests/DataGenerators/EventGenerators.cs +++ b/tests/TeamUp.TestsCommon/DataGenerators/EventGenerators.cs @@ -3,10 +3,7 @@ using FluentAssertions.Extensions; -using TeamUp.Contracts.Events; -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.DataGenerators; +namespace TeamUp.TestsCommon.DataGenerators; public sealed class EventGenerators : BaseGenerator { diff --git a/tests/TeamUp.EndToEndTests/DataGenerators/InvalidRequest.cs b/tests/TeamUp.TestsCommon/DataGenerators/InvalidRequest.cs similarity index 93% rename from tests/TeamUp.EndToEndTests/DataGenerators/InvalidRequest.cs rename to tests/TeamUp.TestsCommon/DataGenerators/InvalidRequest.cs index f4199a6..bb98a41 100644 --- a/tests/TeamUp.EndToEndTests/DataGenerators/InvalidRequest.cs +++ b/tests/TeamUp.TestsCommon/DataGenerators/InvalidRequest.cs @@ -1,7 +1,7 @@ using System.Linq.Expressions; using System.Reflection; -namespace TeamUp.EndToEndTests.DataGenerators; +namespace TeamUp.TestsCommon.DataGenerators; public sealed class InvalidRequest { diff --git a/tests/TeamUp.EndToEndTests/DataGenerators/InvitationGenerators.cs b/tests/TeamUp.TestsCommon/DataGenerators/InvitationGenerators.cs similarity index 94% rename from tests/TeamUp.EndToEndTests/DataGenerators/InvitationGenerators.cs rename to tests/TeamUp.TestsCommon/DataGenerators/InvitationGenerators.cs index 9289e35..0f86801 100644 --- a/tests/TeamUp.EndToEndTests/DataGenerators/InvitationGenerators.cs +++ b/tests/TeamUp.TestsCommon/DataGenerators/InvitationGenerators.cs @@ -1,10 +1,6 @@ global using InvitationGenerator = Bogus.Faker; -using TeamUp.Contracts.Invitations; -using TeamUp.Contracts.Teams; -using TeamUp.Contracts.Users; - -namespace TeamUp.EndToEndTests.DataGenerators; +namespace TeamUp.TestsCommon.DataGenerators; public sealed class InvitationGenerators : BaseGenerator { diff --git a/tests/TeamUp.EndToEndTests/DataGenerators/TeamGeneratorExtensions.cs b/tests/TeamUp.TestsCommon/DataGenerators/TeamGeneratorExtensions.cs similarity index 81% rename from tests/TeamUp.EndToEndTests/DataGenerators/TeamGeneratorExtensions.cs rename to tests/TeamUp.TestsCommon/DataGenerators/TeamGeneratorExtensions.cs index a764c0a..7866f74 100644 --- a/tests/TeamUp.EndToEndTests/DataGenerators/TeamGeneratorExtensions.cs +++ b/tests/TeamUp.TestsCommon/DataGenerators/TeamGeneratorExtensions.cs @@ -1,6 +1,6 @@ -using TeamUp.Contracts.Teams; +using TeamUp.Common; -namespace TeamUp.EndToEndTests.DataGenerators; +namespace TeamUp.TestsCommon.DataGenerators; public static class TeamGeneratorExtensions { @@ -36,6 +36,24 @@ public static TeamGenerator WithMembers(this TeamGenerator teamGenerator, User o return teamGenerator.GetTeamGeneratorWithMembers(members, userMembersWithOwner); } + public static TeamGenerator WithRandomMembers(this TeamGenerator teamGenerator, int count, List pot) + { + count.Should().BeGreaterThan(0); + pot.Should().HaveCountGreaterThanOrEqualTo(1); + + return teamGenerator + .RuleFor(TeamGenerators.TEAM_MEMBERS_FIELD, (f, t) => f + .Make(count, index => f.PickRandom(pot) + .Map(user => TeamGenerators.TeamMember + .RuleForBackingField(tm => tm.TeamId, t.Id) + .RuleForBackingField(tm => tm.UserId, user.Id) + .RuleFor(tm => tm.Nickname, user.Name) + .RuleFor(tm => tm.Role, index == 0 ? TeamRole.Owner : TeamRole.Member) + .Generate())) + .ToHashSet() + .ToList()); + } + public static TeamGenerator WithMembers(this TeamGenerator teamGenerator, List members, params (User User, TeamRole Role)[] userMembers) { userMembers.Where(x => x.Role == TeamRole.Owner).Should().ContainSingle("team has to have exactly 1 owner"); diff --git a/tests/TeamUp.EndToEndTests/DataGenerators/TeamGenerators.cs b/tests/TeamUp.TestsCommon/DataGenerators/TeamGenerators.cs similarity index 97% rename from tests/TeamUp.EndToEndTests/DataGenerators/TeamGenerators.cs rename to tests/TeamUp.TestsCommon/DataGenerators/TeamGenerators.cs index 7688a46..28813b5 100644 --- a/tests/TeamUp.EndToEndTests/DataGenerators/TeamGenerators.cs +++ b/tests/TeamUp.TestsCommon/DataGenerators/TeamGenerators.cs @@ -1,8 +1,6 @@ global using TeamGenerator = Bogus.Faker; -using TeamUp.Contracts.Teams; - -namespace TeamUp.EndToEndTests.DataGenerators; +namespace TeamUp.TestsCommon.DataGenerators; public sealed class TeamGenerators : BaseGenerator { diff --git a/tests/TeamUp.EndToEndTests/DataGenerators/UserGenerators.cs b/tests/TeamUp.TestsCommon/DataGenerators/UserGenerators.cs similarity index 94% rename from tests/TeamUp.EndToEndTests/DataGenerators/UserGenerators.cs rename to tests/TeamUp.TestsCommon/DataGenerators/UserGenerators.cs index 222f550..fd31169 100644 --- a/tests/TeamUp.EndToEndTests/DataGenerators/UserGenerators.cs +++ b/tests/TeamUp.TestsCommon/DataGenerators/UserGenerators.cs @@ -1,7 +1,4 @@ -using TeamUp.Contracts.Teams; -using TeamUp.Contracts.Users; - -namespace TeamUp.EndToEndTests.DataGenerators; +namespace TeamUp.TestsCommon.DataGenerators; public sealed class UserGenerators : BaseGenerator { diff --git a/tests/TeamUp.TestsCommon/AssertionExtensions.cs b/tests/TeamUp.TestsCommon/Extensions/AssertionExtensions.cs similarity index 94% rename from tests/TeamUp.TestsCommon/AssertionExtensions.cs rename to tests/TeamUp.TestsCommon/Extensions/AssertionExtensions.cs index 45d25d1..2062a37 100644 --- a/tests/TeamUp.TestsCommon/AssertionExtensions.cs +++ b/tests/TeamUp.TestsCommon/Extensions/AssertionExtensions.cs @@ -1,11 +1,10 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -using FluentAssertions; using FluentAssertions.Execution; using FluentAssertions.Primitives; -namespace TeamUp.TestsCommon; +namespace TeamUp.TestsCommon.Extensions; public static class AssertionExtensions { diff --git a/tests/TeamUp.TestsCommon/FakerExtensions.cs b/tests/TeamUp.TestsCommon/Extensions/FakerExtensions.cs similarity index 86% rename from tests/TeamUp.TestsCommon/FakerExtensions.cs rename to tests/TeamUp.TestsCommon/Extensions/FakerExtensions.cs index 1a51051..2064406 100644 --- a/tests/TeamUp.TestsCommon/FakerExtensions.cs +++ b/tests/TeamUp.TestsCommon/Extensions/FakerExtensions.cs @@ -1,14 +1,18 @@ using System.Linq.Expressions; using System.Reflection; -using Bogus; - -namespace TeamUp.TestsCommon; +namespace TeamUp.TestsCommon.Extensions; public static class FakerExtensions { public static readonly Faker F = new(); + public static T PickRandomFromReadOnlyList(this Faker faker, IReadOnlyList list) where T : class + { + var index = faker.Random.Int(0, list.Count - 1); + return list[index]; + } + public static Faker UsePrivateConstructor(this Faker faker) where T : class => faker.CustomInstantiator(f => (Activator.CreateInstance(typeof(T), nonPublic: true) as T)!); diff --git a/tests/TeamUp.TestsCommon/RandomizerExtensions.cs b/tests/TeamUp.TestsCommon/Extensions/RandomizerExtensions.cs similarity index 80% rename from tests/TeamUp.TestsCommon/RandomizerExtensions.cs rename to tests/TeamUp.TestsCommon/Extensions/RandomizerExtensions.cs index 122202f..898bbf1 100644 --- a/tests/TeamUp.TestsCommon/RandomizerExtensions.cs +++ b/tests/TeamUp.TestsCommon/Extensions/RandomizerExtensions.cs @@ -1,6 +1,4 @@ -using Bogus; - -namespace TeamUp.TestsCommon; +namespace TeamUp.TestsCommon.Extensions; public static class RandomizerExtensions { diff --git a/tests/TeamUp.EndToEndTests/Extensions/TheoryDataExtensions.cs b/tests/TeamUp.TestsCommon/Extensions/TheoryDataExtensions.cs similarity index 88% rename from tests/TeamUp.EndToEndTests/Extensions/TheoryDataExtensions.cs rename to tests/TeamUp.TestsCommon/Extensions/TheoryDataExtensions.cs index e98b9d3..74588ae 100644 --- a/tests/TeamUp.EndToEndTests/Extensions/TheoryDataExtensions.cs +++ b/tests/TeamUp.TestsCommon/Extensions/TheoryDataExtensions.cs @@ -1,6 +1,6 @@ using System.Linq.Expressions; -namespace TeamUp.EndToEndTests.Extensions; +namespace TeamUp.TestsCommon.Extensions; public static class TheoryDataExtensions { diff --git a/tests/TeamUp.EndToEndTests/Extensions/TimeExtensions.cs b/tests/TeamUp.TestsCommon/Extensions/TimeExtensions.cs similarity index 90% rename from tests/TeamUp.EndToEndTests/Extensions/TimeExtensions.cs rename to tests/TeamUp.TestsCommon/Extensions/TimeExtensions.cs index 0d86a06..7774b83 100644 --- a/tests/TeamUp.EndToEndTests/Extensions/TimeExtensions.cs +++ b/tests/TeamUp.TestsCommon/Extensions/TimeExtensions.cs @@ -1,4 +1,4 @@ -namespace TeamUp.EndToEndTests.Extensions; +namespace TeamUp.TestsCommon.Extensions; public static class TimeExtensions { diff --git a/tests/TeamUp.TestsCommon/GlobalUsings.cs b/tests/TeamUp.TestsCommon/GlobalUsings.cs new file mode 100644 index 0000000..9728a89 --- /dev/null +++ b/tests/TeamUp.TestsCommon/GlobalUsings.cs @@ -0,0 +1,16 @@ +global using Bogus; + +global using FluentAssertions; + +global using TeamUp.Contracts.Events; +global using TeamUp.Contracts.Invitations; +global using TeamUp.Contracts.Teams; +global using TeamUp.Contracts.Users; +global using TeamUp.Domain.Aggregates.Events; +global using TeamUp.Domain.Aggregates.Invitations; +global using TeamUp.Domain.Aggregates.Teams; +global using TeamUp.Domain.Aggregates.Users; +global using TeamUp.TestsCommon.DataGenerators; +global using TeamUp.TestsCommon.Extensions; + +global using Xunit; diff --git a/tests/TeamUp.TestsCommon/TeamUp.TestsCommon.csproj b/tests/TeamUp.TestsCommon/TeamUp.TestsCommon.csproj index 8e4cf39..6fe8662 100644 --- a/tests/TeamUp.TestsCommon/TeamUp.TestsCommon.csproj +++ b/tests/TeamUp.TestsCommon/TeamUp.TestsCommon.csproj @@ -3,6 +3,12 @@ + + + + + +