mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 05:00:19 -05:00
[PM-15621] WIP
This commit is contained in:
parent
c08b3d99ab
commit
b0c89ad847
@ -17,6 +17,7 @@ public class DeleteManagedOrganizationUserAccountValidator(
|
|||||||
{
|
{
|
||||||
var invalidResults = new List<Invalid<DeleteUserValidationRequest>>();
|
var invalidResults = new List<Invalid<DeleteUserValidationRequest>>();
|
||||||
var validResults = new List<Valid<DeleteUserValidationRequest>>();
|
var validResults = new List<Valid<DeleteUserValidationRequest>>();
|
||||||
|
|
||||||
foreach (var request in requests)
|
foreach (var request in requests)
|
||||||
{
|
{
|
||||||
// The order of the validators matters.
|
// The order of the validators matters.
|
||||||
@ -87,7 +88,7 @@ public class DeleteManagedOrganizationUserAccountValidator(
|
|||||||
{
|
{
|
||||||
if (request.User == null || request.OrganizationUser == null)
|
if (request.User == null || request.OrganizationUser == null)
|
||||||
{
|
{
|
||||||
return new Invalid<DeleteUserValidationRequest>(new BadRequestError<DeleteUserValidationRequest>("You cannot delete a member with Invited status.", request));
|
return new Invalid<DeleteUserValidationRequest>(new RecordNotFoundError<DeleteUserValidationRequest>("Member not found.", request));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Valid<DeleteUserValidationRequest>();
|
return new Valid<DeleteUserValidationRequest>();
|
||||||
|
@ -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<CommandResult>[]
|
|
||||||
{
|
|
||||||
() => new Success(),
|
|
||||||
() => new Success(),
|
|
||||||
() => new Success()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Act
|
|
||||||
var result = CommandResultValidator.ExecuteValidators(validators);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.IsType<Success>(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<object[]> TestCases()
|
|
||||||
{
|
|
||||||
yield return new object[]
|
|
||||||
{
|
|
||||||
new Func<CommandResult>[]
|
|
||||||
{
|
|
||||||
() => new Failure("First failure"),
|
|
||||||
() => new Success(),
|
|
||||||
() => new Failure("Second failure"),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
yield return new object[]
|
|
||||||
{
|
|
||||||
new Func<CommandResult>[]
|
|
||||||
{
|
|
||||||
() => new Success(),
|
|
||||||
() => new Failure("First failure"),
|
|
||||||
() => new Failure("Second failure"),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
yield return new object[]
|
|
||||||
{
|
|
||||||
new Func<CommandResult>[]
|
|
||||||
{
|
|
||||||
() => new Success(),
|
|
||||||
() => new Success(),
|
|
||||||
() => new Failure("First failure"),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[MemberData(nameof(TestCases))]
|
|
||||||
public void ExecuteValidators_WhenValidatorFails_ReturnsFirstFailure(Func<CommandResult>[] validators)
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var result = CommandResultValidator.ExecuteValidators(validators);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.IsType<Failure>(result);
|
|
||||||
Assert.Equal(["First failure"], ((Failure)result).ErrorMessages);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task ExecuteValidatorAsync_AllSuccess_ReturnsSuccess()
|
|
||||||
{
|
|
||||||
// Arrange
|
|
||||||
var validators = new Func<Task<CommandResult>>[]
|
|
||||||
{
|
|
||||||
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<Success>(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<object[]> AsyncTestCases()
|
|
||||||
{
|
|
||||||
yield return new object[]
|
|
||||||
{
|
|
||||||
new Func<Task<CommandResult>>[]
|
|
||||||
{
|
|
||||||
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<Task<CommandResult>>[]
|
|
||||||
{
|
|
||||||
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<Task<CommandResult>>[]
|
|
||||||
{
|
|
||||||
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<Task<CommandResult>>[] validators)
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var result = await CommandResultValidator.ExecuteValidatorAsync(validators);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.IsType<Failure>(result);
|
|
||||||
Assert.Equal(["First failure"], ((Failure)result).ErrorMessages);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user