Skip to content

Commit

Permalink
refactored tests to have common data generators, added smoke tests, f…
Browse files Browse the repository at this point in the history
…ixed to test under Release configuration
  • Loading branch information
skrasekmichael committed Mar 8, 2024
1 parent e63ab65 commit 0c1d9d5
Show file tree
Hide file tree
Showing 53 changed files with 449 additions and 126 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
<PackageVersion Include="Testcontainers" Version="3.7.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="3.7.0" />
<PackageVersion Include="xunit" Version="2.6.6" />
<PackageVersion Include="xunit.extensibility.core" Version="2.6.6" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
</ItemGroup>
</Project>
</Project>
7 changes: 7 additions & 0 deletions TeamUp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
6 changes: 6 additions & 0 deletions src/TeamUp.Common/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace TeamUp.Common;

public static class Extensions
{
public static TResult Map<T, TResult>(this T source, Func<T, TResult> transform) => transform(source);
}
6 changes: 0 additions & 6 deletions tests/TeamUp.EndToEndTests/DataGenerators/BaseGenerator.cs

This file was deleted.

5 changes: 2 additions & 3 deletions tests/TeamUp.EndToEndTests/EndpointTests/BaseEndpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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<MailInbox>();
BackgroundCallback = appFactory.Services.GetRequiredService<OutboxBackgroundCallback>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TeamUp.Contracts.Events;

namespace TeamUp.EndToEndTests.EndpointTests.Events;
namespace TeamUp.EndToEndTests.EndpointTests.Events;

public abstract class BaseEventTests : BaseEndpointTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TeamUp.Contracts.Invitations;

namespace TeamUp.EndToEndTests.EndpointTests.Invitations;
namespace TeamUp.EndToEndTests.EndpointTests.Invitations;

public sealed class GetMyInvitationsTests : BaseInvitationTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Microsoft.EntityFrameworkCore;

using TeamUp.Contracts.Teams;

namespace TeamUp.EndToEndTests.EndpointTests.Teams;

public sealed class ChangeNicknameTests : BaseTeamTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Microsoft.EntityFrameworkCore;

using TeamUp.Contracts.Teams;

namespace TeamUp.EndToEndTests.EndpointTests.Teams;

public sealed class ChangeOwnershipTests : BaseTeamTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TeamUp.Contracts.Teams;

namespace TeamUp.EndToEndTests.EndpointTests.Teams;
namespace TeamUp.EndToEndTests.EndpointTests.Teams;

public sealed class CreateEventTypeTests : BaseTeamTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Microsoft.EntityFrameworkCore;

using TeamUp.Contracts.Teams;

namespace TeamUp.EndToEndTests.EndpointTests.Teams;

public sealed class CreateTeamTests : BaseTeamTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore;

using TeamUp.Contracts.Teams;
using EventResponse = TeamUp.Domain.Aggregates.Events.EventResponse;

namespace TeamUp.EndToEndTests.EndpointTests.Teams;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TeamUp.Contracts.Teams;

namespace TeamUp.EndToEndTests.EndpointTests.Teams;
namespace TeamUp.EndToEndTests.EndpointTests.Teams;

public sealed class GetTeamTests : BaseTeamTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TeamUp.Contracts.Teams;

namespace TeamUp.EndToEndTests.EndpointTests.Teams;
namespace TeamUp.EndToEndTests.EndpointTests.Teams;

public sealed class RemoveTeamMemberTests : BaseTeamTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Microsoft.EntityFrameworkCore;

using TeamUp.Contracts.Teams;

namespace TeamUp.EndToEndTests.EndpointTests.Teams;

public sealed class UpdateTeamMemberRoleTests : BaseTeamTests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TeamUp.Contracts.Teams;

namespace TeamUp.EndToEndTests.EndpointTests.Teams;
namespace TeamUp.EndToEndTests.EndpointTests.Teams;

public sealed class UpdateTeamNameTests : BaseTeamTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TeamUp.Contracts.Users;

namespace TeamUp.EndToEndTests.EndpointTests.UserAccess;
namespace TeamUp.EndToEndTests.EndpointTests.UserAccess;

public sealed class ActivateAccountTests : BaseUserAccessTests
{
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TeamUp.Contracts.Users;

namespace TeamUp.EndToEndTests.EndpointTests.UserAccess;
namespace TeamUp.EndToEndTests.EndpointTests.UserAccess;

public sealed class GetMyAccountDetailsTests : BaseUserAccessTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Security.Claims;

using TeamUp.Application.Users;
using TeamUp.Contracts.Users;

namespace TeamUp.EndToEndTests.EndpointTests.UserAccess;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using TeamUp.Contracts.Users;

namespace TeamUp.EndToEndTests.EndpointTests.UserAccess;
namespace TeamUp.EndToEndTests.EndpointTests.UserAccess;

public sealed class RegisterUserTests : BaseUserAccessTests
{
Expand Down
11 changes: 7 additions & 4 deletions tests/TeamUp.EndToEndTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 1 addition & 2 deletions tests/TeamUp.EndToEndTests/Mocks/BackgroundCallback.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

namespace TeamUp.EndToEndTests.Mocks;
namespace TeamUp.EndToEndTests.Mocks;

internal abstract class BackgroundCallback
{
Expand Down
4 changes: 3 additions & 1 deletion tests/TeamUp.EndToEndTests/TeamApiWebApplicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public sealed class AppCollectionFixture : ICollectionFixture<TeamApiWebApplicat

public sealed class TeamApiWebApplicationFactory : WebApplicationFactory<Program>, IAsyncLifetime
{
public const string HTTPS_PORT = "8181";

private readonly PostgreSqlContainer _dbContainer = new PostgreSqlBuilder()
.WithDatabase("POSTGRES")
.WithUsername("POSTGRES")
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 0c1d9d5

Please sign in to comment.