diff --git a/CleanArchitecture.IntegrationTests/Controller/TenantControllerTests.cs b/CleanArchitecture.IntegrationTests/Controller/TenantControllerTests.cs index d406a4d..79a96eb 100644 --- a/CleanArchitecture.IntegrationTests/Controller/TenantControllerTests.cs +++ b/CleanArchitecture.IntegrationTests/Controller/TenantControllerTests.cs @@ -54,8 +54,37 @@ public async Task Should_Get_All_Tenants() .FirstOrDefault(x => x.Id == _fixture.CreatedTenantId)! .Users.Count().Should().Be(1); } - + [Test, Order(2)] + public async Task Should_Not_Get_Deleted_Tenant_By_Id() + { + var response = await _fixture.ServerClient.GetAsync($"/api/v1/Tenant/{_fixture.DeletedTenantId}"); + + response.StatusCode.Should().Be(HttpStatusCode.NotFound); + + var message = await response.Content.ReadAsJsonAsync(); + + message?.Data.Should().BeNull(); + } + + [Test, Order(3)] + public async Task Should_Get_All_Tenants_Including_Deleted() + { + var response = await _fixture.ServerClient.GetAsync( + "api/v1/Tenant?searchTerm=Test&pageSize=5&page=1&includeDeleted=true"); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + + var message = await response.Content.ReadAsJsonAsync>(); + + message?.Data!.Items.Should().NotBeEmpty(); + message!.Data!.Items.Should().HaveCount(2); + message.Data!.Items + .FirstOrDefault(x => x.Id == _fixture.DeletedTenantId) + .Should().NotBeNull(); + } + + [Test, Order(4)] public async Task Should_Create_Tenant() { var request = new CreateTenantViewModel("Test Tenant 2"); @@ -80,7 +109,7 @@ public async Task Should_Create_Tenant() tenantMessage.Data.Name.Should().Be(request.Name); } - [Test, Order(3)] + [Test, Order(5)] public async Task Should_Update_Tenant() { var request = new UpdateTenantViewModel(_fixture.CreatedTenantId, "Test Tenant 3"); @@ -107,7 +136,7 @@ public async Task Should_Update_Tenant() tenantMessage.Data.Name.Should().Be(request.Name); } - [Test, Order(4)] + [Test, Order(6)] public async Task Should_Delete_Tenant() { var response = await _fixture.ServerClient.DeleteAsync($"/api/v1/Tenant/{_fixture.CreatedTenantId}"); diff --git a/CleanArchitecture.IntegrationTests/Controller/UserControllerTests.cs b/CleanArchitecture.IntegrationTests/Controller/UserControllerTests.cs index 422cae7..5daa08f 100644 --- a/CleanArchitecture.IntegrationTests/Controller/UserControllerTests.cs +++ b/CleanArchitecture.IntegrationTests/Controller/UserControllerTests.cs @@ -61,8 +61,37 @@ public async Task Should_Get_User_By_Id() content.FirstName.Should().Be(TestAuthenticationOptions.FirstName); content.LastName.Should().Be(TestAuthenticationOptions.LastName); } - + [Test, Order(2)] + public async Task Should_Get_All_User_Including_Deleted() + { + var response = await _fixture.ServerClient.GetAsync("/api/v1/user?includeDeleted=true"); + + response.StatusCode.Should().Be(HttpStatusCode.OK); + + var message = await response.Content.ReadAsJsonAsync>(); + + message?.Data.Should().NotBeNull(); + + var content = message!.Data!.Items.ToList(); + + content.Count.Should().Be(3); + + content.FirstOrDefault(x => x.Id == _fixture.DeletedUserId).Should().NotBeNull(); + } + + [Test, Order(3)] + public async Task Should_Not_Get_Deleted_User_By_Id() + { + var response = await _fixture.ServerClient.GetAsync("/api/v1/user/" + _fixture.DeletedUserId); + + response.StatusCode.Should().Be(HttpStatusCode.NotFound); + + var message = await response.Content.ReadAsJsonAsync(); + message?.Data.Should().BeNull(); + } + + [Test, Order(4)] public async Task Should_Create_User() { var user = new CreateUserViewModel( @@ -80,7 +109,7 @@ public async Task Should_Create_User() message?.Data.Should().NotBeEmpty(); } - [Test, Order(3)] + [Test, Order(5)] public async Task Should_Login_User() { var user = new LoginUserViewModel( @@ -95,7 +124,7 @@ public async Task Should_Login_User() message?.Data.Should().NotBeEmpty(); } - [Test, Order(4)] + [Test, Order(6)] public async Task Should_Get_The_Current_Active_Users() { var response = await _fixture.ServerClient.GetAsync("/api/v1/user/me"); @@ -114,7 +143,7 @@ public async Task Should_Get_The_Current_Active_Users() content.LastName.Should().Be(TestAuthenticationOptions.LastName); } - [Test, Order(5)] + [Test, Order(7)] public async Task Should_Update_User() { var user = new UpdateUserViewModel( @@ -155,7 +184,7 @@ public async Task Should_Update_User() userContent.Role.Should().Be(user.Role); } - [Test, Order(6)] + [Test, Order(8)] public async Task Should_Change_User_Password() { var user = new ChangePasswordViewModel( @@ -188,7 +217,7 @@ public async Task Should_Change_User_Password() loginMessage?.Data.Should().NotBeEmpty(); } - [Test, Order(7)] + [Test, Order(9)] public async Task Should_Delete_User() { var response = await _fixture.ServerClient.DeleteAsync("/api/v1/user/" + TestAuthenticationOptions.TestUserId); diff --git a/CleanArchitecture.IntegrationTests/Fixtures/TenantTestFixture.cs b/CleanArchitecture.IntegrationTests/Fixtures/TenantTestFixture.cs index 8418bf9..50f99ae 100644 --- a/CleanArchitecture.IntegrationTests/Fixtures/TenantTestFixture.cs +++ b/CleanArchitecture.IntegrationTests/Fixtures/TenantTestFixture.cs @@ -10,6 +10,7 @@ namespace CleanArchitecture.IntegrationTests.Fixtures; public sealed class TenantTestFixture : TestFixtureBase { public Guid CreatedTenantId { get; } = Guid.NewGuid(); + public Guid DeletedTenantId { get; } = Guid.NewGuid(); public async Task SeedTestData() { @@ -21,9 +22,8 @@ public async Task SeedTestData() CreatedTenantId, "Test Tenant")); - // This tenant should not be included in any queries var deletedTenant = new Tenant( - Guid.NewGuid(), + DeletedTenantId, "Test Tenant2"); deletedTenant.Delete(); context.Tenants.Add(deletedTenant); diff --git a/CleanArchitecture.IntegrationTests/Fixtures/UserTestFixture.cs b/CleanArchitecture.IntegrationTests/Fixtures/UserTestFixture.cs index 05fd349..1131ddb 100644 --- a/CleanArchitecture.IntegrationTests/Fixtures/UserTestFixture.cs +++ b/CleanArchitecture.IntegrationTests/Fixtures/UserTestFixture.cs @@ -11,6 +11,8 @@ namespace CleanArchitecture.IntegrationTests.Fixtures; public sealed class UserTestFixture : TestFixtureBase { + public Guid DeletedUserId { get; } = Guid.NewGuid(); + public async Task SeedTestData() { await GlobalSetupFixture.RespawnDatabaseAsync(); @@ -30,9 +32,8 @@ public async Task SeedTestData() "$2a$12$Blal/uiFIJdYsCLTMUik/egLbfg3XhbnxBC6Sb5IKz2ZYhiU/MzL2", UserRole.Admin)); - // This user should not be included in any queries var deletedUsed = new User( - Guid.NewGuid(), + DeletedUserId, Ids.Seed.TenantId, "admin2@email.com", "Admin2", diff --git a/CleanArchitecture.IntegrationTests/Fixtures/gRPC/GetTenantsByIdsTestFixture.cs b/CleanArchitecture.IntegrationTests/Fixtures/gRPC/GetTenantsByIdsTestFixture.cs index 05c381a..c3fb162 100644 --- a/CleanArchitecture.IntegrationTests/Fixtures/gRPC/GetTenantsByIdsTestFixture.cs +++ b/CleanArchitecture.IntegrationTests/Fixtures/gRPC/GetTenantsByIdsTestFixture.cs @@ -27,6 +27,7 @@ public async Task SeedTestData() using var context = Factory.Services.GetRequiredService(); var tenant = CreateTenant(); + tenant.Delete(); context.Tenants.Add(tenant); await context.SaveChangesAsync(); diff --git a/CleanArchitecture.IntegrationTests/Fixtures/gRPC/GetUsersByIdsTestFixture.cs b/CleanArchitecture.IntegrationTests/Fixtures/gRPC/GetUsersByIdsTestFixture.cs index 0e35906..c20c020 100644 --- a/CleanArchitecture.IntegrationTests/Fixtures/gRPC/GetUsersByIdsTestFixture.cs +++ b/CleanArchitecture.IntegrationTests/Fixtures/gRPC/GetUsersByIdsTestFixture.cs @@ -33,6 +33,7 @@ public async Task SeedTestData() "Admin Tenant")); var user = CreateUser(); + user.Delete(); context.Users.Add(user); await context.SaveChangesAsync(); diff --git a/CleanArchitecture.IntegrationTests/gRPC/GetTenantsByIdsTests.cs b/CleanArchitecture.IntegrationTests/gRPC/GetTenantsByIdsTests.cs index a101f4e..8e87d79 100644 --- a/CleanArchitecture.IntegrationTests/gRPC/GetTenantsByIdsTests.cs +++ b/CleanArchitecture.IntegrationTests/gRPC/GetTenantsByIdsTests.cs @@ -31,5 +31,6 @@ public async Task Should_Get_Tenants_By_Ids() new Guid(tenant.Id).Should().Be(createdTenant.Id); tenant.Name.Should().Be(createdTenant.Name); + tenant.DeletedAt.Should().NotBeNullOrWhiteSpace(); } } \ No newline at end of file diff --git a/CleanArchitecture.IntegrationTests/gRPC/GetUsersByIdsTests.cs b/CleanArchitecture.IntegrationTests/gRPC/GetUsersByIdsTests.cs index ab4a95c..5c91388 100644 --- a/CleanArchitecture.IntegrationTests/gRPC/GetUsersByIdsTests.cs +++ b/CleanArchitecture.IntegrationTests/gRPC/GetUsersByIdsTests.cs @@ -31,5 +31,6 @@ public async Task Should_Get_Users_By_Ids() user.Email.Should().Be(createdUser.Email); user.FirstName.Should().Be(createdUser.FirstName); user.LastName.Should().Be(createdUser.LastName); + user.DeletedAt.Should().NotBeNullOrWhiteSpace(); } } \ No newline at end of file