I have a CustomPasswordValidator.cs file that overrides PasswordValidator
public class CustomPasswordValidator : PasswordValidator
{ //
With Moq you need call .Object
on the mock to get the mocked object. You should also make the test async and await the method under test.
You are also mocking the subject under test which in this case is cause the method under test to return null when called because it would not have been setup appropriately. You are basically testing the mocking framework at that point.
Create an actual instance of the subject under test CustomPasswordValidator
and exercise the test, mocking the explicit dependencies of the subject under test to get the desired behavior.
public async Task Validate_Password() {
//Arrange
var userManagerMock = new GetMockUserManager();
var subjetUnderTest = new CustomPasswordValidator();
var user = new AppUser() {
Name = "user"
};
//set the test password to get flagged by the custom validator
var password = "Thi$user12345";
//Act
IdentityResult result = await subjetUnderTest.ValidateAsync(userManagerMock.Object, user, password);
//...code removed for brevity
}
Read Moq Quickstart to get more familiar with how to use moq.