I have a very strange issue with FluentValidator in that for only one validator I get an exception being thrown as per the image below.
The request comes into my endpoint here
[HttpGet]
public async Task<IActionResult> GetBankTransactions([FromRoute] Guid BankAccountId, [FromQuery] GetBankTransactionRequestModel model)
{
//Ommited
}
As you can see in the image below I hit the breakpoint in the validator and then I get the message as you can see
error CS0103: The name 'request' does not exist in the current context.
I have 6 other validators within the solution at the moment all of which work fine and throw the 400 Bad Request response when validation fails.
I have had a look at the various issues that people have had saying that this is an environmental issue. But if thats the case, why is it only affecting on validator which is in the same namespace as the rest and in the same assembly?
Code as seen in the image is
public class GetBankTransactionModelValidator : AbstractValidator<GetBankTransactionRequestModel>
{
public GetBankTransactionModelValidator()
{
RuleFor(request => request.PageNumber).GreaterThan(0);
}
}
I would be very grateful for any and all help on how to resolve this.
Edit
[Fact]
public async Task ValidatePageNumberGreaterThanZero_ReturnsValid()
{
var request = new GetBankTransactionRequestModel
{
PageNumber = 1
};
var result = await _sut.TestValidateAsync(request);
result.ShouldNotHaveValidationErrorFor(x => x.PageNumber);
}
[Fact]
public async Task ValidatePageNumberGreaterThanZero_ReturnsInvalid()
{
var request = new GetBankTransactionRequestModel
{
};
var result = await _sut.TestValidateAsync(request);
result.ShouldNotHaveValidationErrorFor(x => x.PageNumber);
}
Same thing happens in the unit tests too
