Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Replace FluentAssertions with Shouldy #86

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: dotnet build --no-restore

- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test --no-build --verbosity normal --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true" -- RunConfiguration.CollectSourceInformation=true

cd:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MockQueryable.NSubstitute" Version="7.0.3" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using CleanArchitecture.Application.Queries.Tenants.GetAll;
using CleanArchitecture.Application.Tests.Fixtures.Queries.Tenants;
using CleanArchitecture.Application.ViewModels;
using FluentAssertions;
using Shouldly;
using Xunit;

namespace CleanArchitecture.Application.Tests.Queries.Tenants;
Expand All @@ -29,11 +29,15 @@ public async Task Should_Get_Existing_Tenant()

_fixture.VerifyNoDomainNotification();

result.PageSize.Should().Be(query.PageSize);
result.Page.Should().Be(query.Page);
result.Count.Should().Be(1);
result.PageSize.ShouldBe(query.PageSize);
result.Page.ShouldBe(query.Page);
result.Count.ShouldBe(1);

tenant.Should().BeEquivalentTo(result.Items.First());
var checkingTenant = result.Items.First();

tenant.Id.ShouldBe(checkingTenant.Id);
tenant.Name.ShouldBe(checkingTenant.Name);
tenant.Users.Count.ShouldBe(checkingTenant.Users.Count());
}

[Fact]
Expand All @@ -51,10 +55,10 @@ public async Task Should_Not_Get_Deleted_Tenant()
new GetAllTenantsQuery(query, false),
default);

result.PageSize.Should().Be(query.PageSize);
result.Page.Should().Be(query.Page);
result.Count.Should().Be(0);
result.PageSize.ShouldBe(query.PageSize);
result.Page.ShouldBe(query.Page);
result.Count.ShouldBe(0);

result.Items.Should().HaveCount(0);
result.Items.Count.ShouldBe(0);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Linq;
using System.Threading.Tasks;
using CleanArchitecture.Application.Queries.Tenants.GetTenantById;
using CleanArchitecture.Application.Tests.Fixtures.Queries.Tenants;
using CleanArchitecture.Domain.Errors;
using FluentAssertions;
using Shouldly;
using Xunit;

namespace CleanArchitecture.Application.Tests.Queries.Tenants;
Expand All @@ -22,7 +23,9 @@ public async Task Should_Get_Existing_Tenant()

_fixture.VerifyNoDomainNotification();

tenant.Should().BeEquivalentTo(result);
tenant.Id.ShouldBe(result!.Id);
tenant.Name.ShouldBe(result.Name);
tenant.Users.Count.ShouldBe(result.Users.Count());
}

[Fact]
Expand All @@ -38,6 +41,6 @@ public async Task Should_Not_Get_Deleted_Tenant()
nameof(GetTenantByIdQuery),
ErrorCodes.ObjectNotFound,
$"Tenant with id {tenant.Id} could not be found");
result.Should().BeNull();
result.ShouldBeNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using CleanArchitecture.Application.Queries.Users.GetAll;
using CleanArchitecture.Application.Tests.Fixtures.Queries.Users;
using CleanArchitecture.Application.ViewModels;
using FluentAssertions;
using Shouldly;
using Xunit;

namespace CleanArchitecture.Application.Tests.Queries.Users;
Expand All @@ -29,14 +29,14 @@ public async Task Should_Get_All_Users()

_fixture.VerifyNoDomainNotification();

result.PageSize.Should().Be(query.PageSize);
result.Page.Should().Be(query.Page);
result.Count.Should().Be(1);
result.PageSize.ShouldBe(query.PageSize);
result.Page.ShouldBe(query.Page);
result.Count.ShouldBe(1);

var userViewModels = result.Items.ToArray();
userViewModels.Should().NotBeNull();
userViewModels.Should().ContainSingle();
userViewModels.FirstOrDefault()!.Id.Should().Be(_fixture.ExistingUserId);
userViewModels.ShouldNotBeNull();
userViewModels.ShouldHaveSingleItem();
userViewModels.FirstOrDefault()!.Id.ShouldBe(_fixture.ExistingUserId);
}

[Fact]
Expand All @@ -56,10 +56,10 @@ public async Task Should_Not_Get_Deleted_Users()

_fixture.VerifyNoDomainNotification();

result.PageSize.Should().Be(query.PageSize);
result.Page.Should().Be(query.Page);
result.Count.Should().Be(0);
result.PageSize.ShouldBe(query.PageSize);
result.Page.ShouldBe(query.Page);
result.Count.ShouldBe(0);

result.Items.Should().BeEmpty();
result.Items.ShouldBeEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using CleanArchitecture.Application.Queries.Users.GetUserById;
using CleanArchitecture.Application.Tests.Fixtures.Queries.Users;
using CleanArchitecture.Domain.Errors;
using FluentAssertions;
using Shouldly;
using Xunit;

namespace CleanArchitecture.Application.Tests.Queries.Users;
Expand All @@ -23,8 +23,8 @@ public async Task Should_Get_Existing_User()

_fixture.VerifyNoDomainNotification();

result.Should().NotBeNull();
result!.Id.Should().Be(_fixture.ExistingUserId);
result.ShouldNotBeNull();
result!.Id.ShouldBe(_fixture.ExistingUserId);
}

[Fact]
Expand All @@ -42,7 +42,7 @@ public async Task Should_Raise_Notification_For_No_User()
ErrorCodes.ObjectNotFound,
$"User with id {request.Id} could not be found");

result.Should().BeNull();
result.ShouldBeNull();
}

[Fact]
Expand All @@ -59,6 +59,6 @@ public async Task Should_Not_Get_Deleted_User()
ErrorCodes.ObjectNotFound,
$"User with id {_fixture.ExistingUserId} could not be found");

result.Should().BeNull();
result.ShouldBeNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@

<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Threading.Tasks;
using CleanArchitecture.Domain.Commands.Users.LoginUser;
using CleanArchitecture.Domain.Errors;
using FluentAssertions;
using Shouldly;
using Xunit;

namespace CleanArchitecture.Domain.Tests.CommandHandler.User.LoginUser;
Expand All @@ -25,25 +25,25 @@ public async Task Should_Login_User()

_fixture.VerifyNoDomainNotification();

token.Should().NotBeNullOrEmpty();
token.ShouldNotBeNullOrEmpty();

var handler = new JwtSecurityTokenHandler();
var decodedToken = handler.ReadToken(token) as JwtSecurityToken;

var userIdClaim = decodedToken!.Claims
.FirstOrDefault(x => string.Equals(x.Type, ClaimTypes.NameIdentifier));

Guid.Parse(userIdClaim!.Value).Should().Be(user.Id);
Guid.Parse(userIdClaim!.Value).ShouldBe(user.Id);

var userEmailClaim = decodedToken.Claims
.FirstOrDefault(x => string.Equals(x.Type, ClaimTypes.Email));

userEmailClaim!.Value.Should().Be(user.Email);
userEmailClaim!.Value.ShouldBe(user.Email);

var userRoleClaim = decodedToken.Claims
.FirstOrDefault(x => string.Equals(x.Type, ClaimTypes.Role));

userRoleClaim!.Value.Should().Be(user.Role.ToString());
userRoleClaim!.Value.ShouldBe(user.Role.ToString());
}

[Fact]
Expand All @@ -59,7 +59,7 @@ public async Task Should_Not_Login_User_No_User()
ErrorCodes.ObjectNotFound,
$"There is no user with email {command.Email}");

token.Should().BeEmpty();
token.ShouldBeEmpty();
}

[Fact]
Expand All @@ -77,6 +77,6 @@ public async Task Should_Not_Login_User_Incorrect_Password()
DomainErrorCodes.User.PasswordIncorrect,
"The password is incorrect");

token.Should().BeEmpty();
token.ShouldBeEmpty();
}
}
34 changes: 16 additions & 18 deletions CleanArchitecture.Domain.Tests/ValidationTestBase.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using CleanArchitecture.Domain.Commands;
using FluentAssertions;
using FluentValidation;
using Shouldly;

namespace CleanArchitecture.Domain.Tests;

Expand All @@ -21,8 +21,8 @@ protected void ShouldBeValid(TCommand command)
{
var result = _validation.Validate(command);

result.IsValid.Should().BeTrue();
result.Errors.Should().BeEmpty();
result.IsValid.ShouldBeTrue();
result.Errors.ShouldBeEmpty();
}

protected void ShouldHaveSingleError(
Expand All @@ -31,11 +31,11 @@ protected void ShouldHaveSingleError(
{
var result = _validation.Validate(command);

result.IsValid.Should().BeFalse();
result.IsValid.ShouldBeFalse();

result.Errors.Count.Should().Be(1);
result.Errors.Count.ShouldBe(1);

result.Errors.First().ErrorCode.Should().Be(expectedCode);
result.Errors.First().ErrorCode.ShouldBe(expectedCode);
}

protected void ShouldHaveSingleError(
Expand All @@ -45,12 +45,12 @@ protected void ShouldHaveSingleError(
{
var result = _validation.Validate(command);

result.IsValid.Should().BeFalse();
result.IsValid.ShouldBeFalse();

result.Errors.Count.Should().Be(1);
result.Errors.Count.ShouldBe(1);

result.Errors.First().ErrorCode.Should().Be(expectedCode);
result.Errors.First().ErrorMessage.Should().Be(expectedMessage);
result.Errors.First().ErrorCode.ShouldBe(expectedCode);
result.Errors.First().ErrorMessage.ShouldBe(expectedMessage);
}

protected void ShouldHaveExpectedErrors(
Expand All @@ -59,15 +59,14 @@ protected void ShouldHaveExpectedErrors(
{
var result = _validation.Validate(command);

result.IsValid.Should().BeFalse();
result.Errors.Count.Should().Be(expectedErrors.Length);
result.IsValid.ShouldBeFalse();
result.Errors.Count.ShouldBe(expectedErrors.Length);

foreach (var error in expectedErrors)
{
result.Errors
.Count(validation => validation.ErrorCode == error.Key && validation.ErrorMessage == error.Value)
.Should()
.Be(1);
.ShouldBe(1);
}
}

Expand All @@ -77,15 +76,14 @@ protected void ShouldHaveExpectedErrors(
{
var result = _validation.Validate(command);

result.IsValid.Should().BeFalse();
result.Errors.Count.Should().Be(expectedErrors.Length);
result.IsValid.ShouldBeFalse();
result.Errors.Count.ShouldBe(expectedErrors.Length);

foreach (var error in expectedErrors)
{
result.Errors
.Count(validation => validation.ErrorCode == error)
.Should()
.Be(1);
.ShouldBe(1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading
Loading