0
0
mirror of https://github.com/alex289/CleanArchitecture.git synced 2025-06-30 18:42:56 +00:00

Add query handler tests for deleted users

This commit is contained in:
Alexander Konietzko 2023-03-16 20:09:31 +01:00
parent 28c9212391
commit 156e5d1048
No known key found for this signature in database
GPG Key ID: BA6905F37AEC2B5B
9 changed files with 70 additions and 25 deletions

View File

@ -36,4 +36,22 @@ public sealed class GetAllUsersTestFixture : QueryHandlerBaseFixture
.Setup(x => x.GetAllNoTracking()) .Setup(x => x.GetAllNoTracking())
.Returns(query); .Returns(query);
} }
public void SetupDeletedUserAsync()
{
var user = new Mock<User>(() =>
new User(
ExistingUserId,
"max@mustermann.com",
"Max",
"Mustermann"));
user.Object.Delete();
var query = new[] { user.Object }.AsQueryable().BuildMock();
UserRepository
.Setup(x => x.GetAllNoTracking())
.Returns(query);
}
} }

View File

@ -36,4 +36,22 @@ public sealed class GetUserByIdTestFixture : QueryHandlerBaseFixture
.Setup(x => x.GetAllNoTracking()) .Setup(x => x.GetAllNoTracking())
.Returns(query); .Returns(query);
} }
public void SetupDeletedUserAsync()
{
var user = new Mock<User>(() =>
new User(
ExistingUserId,
"max@mustermann.com",
"Max",
"Mustermann"));
user.Object.Delete();
var query = new[] { user.Object }.AsQueryable().BuildMock();
UserRepository
.Setup(x => x.GetAllNoTracking())
.Returns(query);
}
} }

View File

@ -1,6 +0,0 @@
namespace CleanArchitecture.Application.Tests.Fixtures.Services;
public sealed class UserServiceTestFixture
{
}

View File

@ -26,5 +26,17 @@ public sealed class GetAllUsersQueryHandlerTests
result.FirstOrDefault()!.Id.Should().Be(_fixture.ExistingUserId); result.FirstOrDefault()!.Id.Should().Be(_fixture.ExistingUserId);
} }
// Add Test for deleted user [Fact]
public async Task Should_Not_Get_Deleted_Users()
{
_fixture.SetupDeletedUserAsync();
var result = await _fixture.Handler.Handle(
new(),
default);
_fixture.VerifyNoDomainNotification();
result.Should().BeEmpty();
}
} }

View File

@ -45,5 +45,20 @@ public sealed class GetUserByIdQueryHandlerTests
result.Should().BeNull(); result.Should().BeNull();
} }
// Add Test for deleted user [Fact]
public async Task Should_Not_Get_Deleted_User()
{
_fixture.SetupDeletedUserAsync();
var result = await _fixture.Handler.Handle(
new(_fixture.ExistingUserId, false),
default);
_fixture.VerifyExistingNotification(
nameof(GetUserByIdQuery),
ErrorCodes.ObjectNotFound,
$"User with id {_fixture.ExistingUserId} could not be found");
result.Should().BeNull();
}
} }

View File

@ -1,6 +0,0 @@
namespace CleanArchitecture.Application.Tests.Services;
public sealed class UserServiceTests
{
}

View File

@ -31,8 +31,4 @@
<ProjectReference Include="..\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj" /> <ProjectReference Include="..\CleanArchitecture.Infrastructure\CleanArchitecture.Infrastructure.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="UtilityTests\" />
</ItemGroup>
</Project> </Project>

View File

@ -6,19 +6,19 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="Users\Models.proto"/> <None Remove="Users\Models.proto" />
<None Remove="Users\UsersApi.proto"/> <None Remove="Users\UsersApi.proto" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Protobuf Include="Users\Models.proto" GrpcServices="Both"/> <Protobuf Include="Users\Models.proto" GrpcServices="Both" />
<Protobuf Include="Users\UsersApi.proto" GrpcServices="Both"/> <Protobuf Include="Users\UsersApi.proto" GrpcServices="Both" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.22.1" /> <PackageReference Include="Google.Protobuf" Version="3.22.1" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.22.1" /> <PackageReference Include="Google.Protobuf.Tools" Version="3.22.1" />
<PackageReference Include="Grpc.AspNetCore" Version="2.51.0" /> <PackageReference Include="Grpc.AspNetCore" Version="2.52.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,4 +1,2 @@
- Remove warnings and apply suggestions - Remove warnings and apply suggestions
- Add authentication and authorization - Add authentication and authorization
- Utility integration tests
- Queryhandler tests for deleted users