Skip to content

Commit

Permalink
Tests Refactoring (#37)
Browse files Browse the repository at this point in the history
* renamed test project
* renamed endpoint test files to prefix with group and suffix with endpoint
* fixed generating guids and typed ids for testing (removed generating using Bogus.Faker)
* changed dotnet test CI pipeline verbosity to minimal
* fixed performance test namespaces
* fixed generating distinct users for testing
* added EF Core Relational package reference for possible query adjustment (AsSplitQuery ...)
  • Loading branch information
skrasekmichael authored Mar 9, 2024
1 parent c8bf3ef commit 9b251d5
Show file tree
Hide file tree
Showing 76 changed files with 172 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
run: dotnet build ${{ env.SOLUTION }} -c Release --no-restore

- name: Test
run: dotnet test ${{env.SOLUTION }} -c Release --no-build --verbosity normal
run: dotnet test ${{env.SOLUTION }} -c Release --no-build --verbosity minimal
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Identity.Stores" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
Expand Down
18 changes: 9 additions & 9 deletions TeamUp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{B78B958B-7250-4FEC-96F4-4FE0DE49D916}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.ArchitectureTests", "tests\TeamUp.ArchitectureTests\TeamUp.ArchitectureTests.csproj", "{BFC0159D-37D8-494F-90A6-DA3EA05CFDEF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.Tests.Architecture", "tests\TeamUp.Tests.Architecture\TeamUp.Tests.Architecture.csproj", "{BFC0159D-37D8-494F-90A6-DA3EA05CFDEF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.EndToEndTests", "tests\TeamUp.EndToEndTests\TeamUp.EndToEndTests.csproj", "{63C1F34E-C706-43AC-A98B-E9530F875FFA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.Tests.EndToEnd", "tests\TeamUp.Tests.EndToEnd\TeamUp.Tests.EndToEnd.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}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.Tests.Performance", "tests\TeamUp.Tests.Performance\TeamUp.Tests.Performance.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}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamUp.Tests.Common", "tests\TeamUp.Tests.Common\TeamUp.Tests.Common.csproj", "{A3D136DD-571F-4B1C-83E2-9B538F85C575}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{F77B386C-FDBC-4BB4-AF07-0CF054DBDB7E}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -77,14 +77,14 @@ Global
{63C1F34E-C706-43AC-A98B-E9530F875FFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63C1F34E-C706-43AC-A98B-E9530F875FFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63C1F34E-C706-43AC-A98B-E9530F875FFA}.Release|Any CPU.Build.0 = Release|Any CPU
{A3D136DD-571F-4B1C-83E2-9B538F85C575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
{A3D136DD-571F-4B1C-83E2-9B538F85C575}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -98,8 +98,8 @@ Global
{34E8F682-1BBF-44E8-979C-23A523FEA846} = {2565E01A-0189-44D1-B8EF-24490DB68608}
{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}
{A3D136DD-571F-4B1C-83E2-9B538F85C575} = {B78B958B-7250-4FEC-96F4-4FE0DE49D916}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2E9D991D-377D-45D8-9599-801391683CEA}
Expand Down
1 change: 1 addition & 0 deletions src/TeamUp.Application/TeamUp.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" />
<PackageReference Include="Riok.Mapperly" />
</ItemGroup>

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using TeamUp.Application.Abstractions;

namespace TeamUp.ArchitectureTests.Application;
namespace TeamUp.Tests.Architecture.Application;

public sealed class AppQueryContextTests : BaseTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Reflection;

namespace TeamUp.ArchitectureTests;
namespace TeamUp.Tests.Architecture;

public abstract class BaseTests
{
public static readonly Assembly DomainAssembly = typeof(TeamUp.Domain.ServiceCollectionExtensions).Assembly;
public static readonly Assembly ApplicationAssembly = typeof(TeamUp.Application.ServiceCollectionExtensions).Assembly;
public static readonly Assembly InfrastructureAssembly = typeof(Infrastructure.ServiceCollectionExtensions).Assembly;
public static readonly Assembly InfrastructureAssembly = typeof(TeamUp.Infrastructure.ServiceCollectionExtensions).Assembly;
public static readonly Assembly ContractsAssembly = typeof(TeamUp.Contracts.Abstractions.IRequestBody).Assembly;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TeamUp.Contracts.Abstractions;

namespace TeamUp.ArchitectureTests.Contracts;
namespace TeamUp.Tests.Architecture.Contracts;

public sealed class ClassesTests : BaseTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using TeamUp.Contracts.Abstractions;

namespace TeamUp.ArchitectureTests.Contracts;
namespace TeamUp.Tests.Architecture.Contracts;

public sealed class RequestTests : BaseTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamUp.ArchitectureTests;
namespace TeamUp.Tests.Architecture;

public sealed class DependencyTests : BaseTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TeamUp.Domain.Abstractions;

namespace TeamUp.ArchitectureTests.Domain;
namespace TeamUp.Tests.Architecture.Domain;

public sealed class DomainEventTests : BaseTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using TeamUp.Domain.Abstractions;

namespace TeamUp.ArchitectureTests.Domain;
namespace TeamUp.Tests.Architecture.Domain;

public sealed class EntityTests : BaseTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using TeamUp.Domain.Abstractions;

namespace TeamUp.ArchitectureTests.Domain;
namespace TeamUp.Tests.Architecture.Domain;

public sealed class ValueObjectTests : BaseTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamUp.TestsCommon.DataGenerators;
namespace TeamUp.Tests.Common.DataGenerators;

public abstract class BaseGenerator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FluentAssertions.Extensions;

namespace TeamUp.TestsCommon.DataGenerators;
namespace TeamUp.Tests.Common.DataGenerators;

public static class EventGeneratorExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using FluentAssertions.Extensions;

namespace TeamUp.TestsCommon.DataGenerators;
namespace TeamUp.Tests.Common.DataGenerators;

public sealed class EventGenerators : BaseGenerator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq.Expressions;
using System.Reflection;

namespace TeamUp.TestsCommon.DataGenerators;
namespace TeamUp.Tests.Common.DataGenerators;

public sealed class InvalidRequest<TRequest>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
global using InvitationGenerator = Bogus.Faker<TeamUp.Domain.Aggregates.Invitations.Invitation>;

namespace TeamUp.TestsCommon.DataGenerators;
namespace TeamUp.Tests.Common.DataGenerators;

public sealed class InvitationGenerators : BaseGenerator
{
Expand Down Expand Up @@ -50,31 +50,31 @@ public InvalidInviteUserRequest()
{
this.Add(x => x.Email, new InviteUserRequest
{
TeamId = TeamId.FromGuid(F.Random.Guid()),
TeamId = TeamId.New(),
Email = ""
});

this.Add(x => x.Email, new InviteUserRequest
{
TeamId = TeamId.FromGuid(F.Random.Guid()),
TeamId = TeamId.New(),
Email = "@@"
});

this.Add(x => x.Email, new InviteUserRequest
{
TeamId = TeamId.FromGuid(F.Random.Guid()),
TeamId = TeamId.New(),
Email = "invalid email"
});

this.Add(x => x.Email, new InviteUserRequest
{
TeamId = TeamId.FromGuid(F.Random.Guid()),
TeamId = TeamId.New(),
Email = "missing.domain@"
});

this.Add(x => x.Email, new InviteUserRequest
{
TeamId = TeamId.FromGuid(F.Random.Guid()),
TeamId = TeamId.New(),
Email = "@missing.username"
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TeamUp.Common;

namespace TeamUp.TestsCommon.DataGenerators;
namespace TeamUp.Tests.Common.DataGenerators;

public static class TeamGeneratorExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
global using TeamGenerator = Bogus.Faker<TeamUp.Domain.Aggregates.Teams.Team>;

namespace TeamUp.TestsCommon.DataGenerators;
namespace TeamUp.Tests.Common.DataGenerators;

public sealed class TeamGenerators : BaseGenerator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamUp.TestsCommon.DataGenerators;
namespace TeamUp.Tests.Common.DataGenerators;

public sealed class UserGenerators : BaseGenerator
{
Expand All @@ -21,6 +21,14 @@ public sealed class UserGenerators : BaseGenerator
.RuleFor(u => u.Password, new Password())
.RuleFor(u => u.Status, UserStatus.NotActivated);

public static readonly Faker<User> DistinctUser = new Faker<User>()
.UsePrivateConstructor()
.RuleFor(u => u.Id, f => UserId.FromGuid(f.Random.Guid()))
.RuleFor(u => u.Email, f => f.Internet.Email(uniqueSuffix: f.Random.Guid().ToString()))
.RuleFor(u => u.Name, f => f.Internet.UserName())
.RuleFor(u => u.Password, new Password())
.RuleFor(u => u.Status, UserStatus.Activated);

public static User GenerateUser(Password password, UserStatus status)
{
return User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using FluentAssertions.Execution;
using FluentAssertions.Primitives;

namespace TeamUp.TestsCommon.Extensions;
namespace TeamUp.Tests.Common.Extensions;

public static class AssertionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Linq.Expressions;
using System.Reflection;

namespace TeamUp.TestsCommon.Extensions;
namespace TeamUp.Tests.Common.Extensions;

public static class FakerExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamUp.TestsCommon.Extensions;
namespace TeamUp.Tests.Common.Extensions;

public static class RandomizerExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Linq.Expressions;

namespace TeamUp.TestsCommon.Extensions;
namespace TeamUp.Tests.Common.Extensions;

public static class TheoryDataExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeamUp.TestsCommon.Extensions;
namespace TeamUp.Tests.Common.Extensions;

public static class TimeExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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 TeamUp.Tests.Common.DataGenerators;
global using TeamUp.Tests.Common.Extensions;

global using Xunit;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;

namespace TeamUp.TestsCommon;
namespace TeamUp.Tests.Common;

public sealed class PrivateBinder : Bogus.Binder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

using TeamUp.Application.Users;
using TeamUp.Common.Abstractions;
using TeamUp.EndToEndTests.Mocks;
using TeamUp.Tests.EndToEnd.Mocks;

namespace TeamUp.EndToEndTests.EndpointTests;
namespace TeamUp.Tests.EndToEnd.EndpointTests;

[Collection(nameof(AppCollectionFixture))]
public abstract class BaseEndpointTests : IAsyncLifetime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace TeamUp.EndToEndTests.EndpointTests.Events;
namespace TeamUp.Tests.EndToEnd.EndpointTests.Events;

public sealed class CreateEventTests : BaseEventTests
public sealed class CreateEventTests : EventTests
{
public CreateEventTests(TeamApiWebApplicationFactory appFactory) : base(appFactory) { }

Expand Down Expand Up @@ -130,8 +130,8 @@ public async Task CreateEvent_ForUnExistingTeam_Should_ResultInNotFound()
{
//arrange
var initiatorUser = UserGenerators.ActivatedUser.Generate();
var teamId = F.Random.Guid();
var eventTypeId = EventTypeId.FromGuid(F.Random.Guid());
var teamId = Guid.NewGuid();
var eventTypeId = EventTypeId.New();

await UseDbContextAsync(dbContext =>
{
Expand Down Expand Up @@ -179,7 +179,7 @@ await UseDbContextAsync(dbContext =>
Authenticate(initiatorUser);

var request = EventGenerators.ValidCreateEventRequest
.WithEventType(EventTypeId.FromGuid(F.Random.Guid()))
.WithEventType(EventTypeId.New())
.WithTime(DateTime.UtcNow.AddDays(4), DateTime.UtcNow.AddDays(4).AddHours(1))
.Generate();

Expand Down
Loading

0 comments on commit 9b251d5

Please # to comment.