From b0c89ad847699226e5844bad78d5a9fb8970f618 Mon Sep 17 00:00:00 2001 From: Jimmy Vo Date: Fri, 4 Apr 2025 08:47:43 -0400 Subject: [PATCH] [PM-15621] WIP --- ...ManagedOrganizationUserAccountValidator.cs | 3 +- .../Validators/CommandResultValidatorTests.cs | 130 ------------------ 2 files changed, 2 insertions(+), 131 deletions(-) delete mode 100644 test/Core.Test/Validators/CommandResultValidatorTests.cs diff --git a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/RestoreUser/DeleteManagedOrganizationUserAccountValidator.cs b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/RestoreUser/DeleteManagedOrganizationUserAccountValidator.cs index f635b1c2ee..e19f0619c0 100644 --- a/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/RestoreUser/DeleteManagedOrganizationUserAccountValidator.cs +++ b/src/Core/AdminConsole/OrganizationFeatures/OrganizationUsers/RestoreUser/DeleteManagedOrganizationUserAccountValidator.cs @@ -17,6 +17,7 @@ public class DeleteManagedOrganizationUserAccountValidator( { var invalidResults = new List>(); var validResults = new List>(); + foreach (var request in requests) { // The order of the validators matters. @@ -87,7 +88,7 @@ public class DeleteManagedOrganizationUserAccountValidator( { if (request.User == null || request.OrganizationUser == null) { - return new Invalid(new BadRequestError("You cannot delete a member with Invited status.", request)); + return new Invalid(new RecordNotFoundError("Member not found.", request)); } return new Valid(); diff --git a/test/Core.Test/Validators/CommandResultValidatorTests.cs b/test/Core.Test/Validators/CommandResultValidatorTests.cs deleted file mode 100644 index c41c9bbdff..0000000000 --- a/test/Core.Test/Validators/CommandResultValidatorTests.cs +++ /dev/null @@ -1,130 +0,0 @@ -using Bit.Core.Models.Commands; -using Bit.Core.Validators; -using Xunit; - -namespace Bit.Core.Test.Validators; - -public class CommandResultValidatorTests -{ - [Fact] - public void ExecuteValidators_AllSuccess_ReturnsSuccess() - { - // Arrange - var validators = new Func[] - { - () => new Success(), - () => new Success(), - () => new Success() - }; - - // Act - var result = CommandResultValidator.ExecuteValidators(validators); - - // Assert - Assert.IsType(result); - } - - public static IEnumerable TestCases() - { - yield return new object[] - { - new Func[] - { - () => new Failure("First failure"), - () => new Success(), - () => new Failure("Second failure"), - } - }; - yield return new object[] - { - new Func[] - { - () => new Success(), - () => new Failure("First failure"), - () => new Failure("Second failure"), - } - }; - yield return new object[] - { - new Func[] - { - () => new Success(), - () => new Success(), - () => new Failure("First failure"), - } - }; - } - - [Theory] - [MemberData(nameof(TestCases))] - public void ExecuteValidators_WhenValidatorFails_ReturnsFirstFailure(Func[] validators) - { - // Act - var result = CommandResultValidator.ExecuteValidators(validators); - - // Assert - Assert.IsType(result); - Assert.Equal(["First failure"], ((Failure)result).ErrorMessages); - } - - [Fact] - public async Task ExecuteValidatorAsync_AllSuccess_ReturnsSuccess() - { - // Arrange - var validators = new Func>[] - { - async () => await Task.FromResult(new Success()), - async () => await Task.FromResult(new Success()), - async () => await Task.FromResult(new Success()) - }; - - // Act - var result = await CommandResultValidator.ExecuteValidatorAsync(validators); - - // Assert - Assert.IsType(result); - } - - public static IEnumerable AsyncTestCases() - { - yield return new object[] - { - new Func>[] - { - async () => await Task.FromResult(new Failure("First failure")), - async () => await Task.FromResult(new Success()), - async () => await Task.FromResult(new Failure("Second failure")), - } - }; - yield return new object[] - { - new Func>[] - { - async () => await Task.FromResult(new Success()), - async () => await Task.FromResult(new Failure("First failure")), - async () => await Task.FromResult(new Failure("Second failure")), - } - }; - yield return new object[] - { - new Func>[] - { - async () => await Task.FromResult(new Success()), - async () => await Task.FromResult(new Success()), - async () => await Task.FromResult(new Failure("First failure")), - } - }; - } - - [Theory] - [MemberData(nameof(AsyncTestCases))] - public async Task ExecuteValidatorAsync_WhenValidatorFails_ReturnsFirstFailure(Func>[] validators) - { - // Act - var result = await CommandResultValidator.ExecuteValidatorAsync(validators); - - // Assert - Assert.IsType(result); - Assert.Equal(["First failure"], ((Failure)result).ErrorMessages); - } -}