|
|
@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
using adminBlazor.Models;
|
|
|
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace TestUnit
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public class RegisterRequest_UT
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
|
|
|
//correct
|
|
|
|
|
|
|
|
[InlineData(true, "password", "password", "username")]
|
|
|
|
|
|
|
|
//password incorrect (required)
|
|
|
|
|
|
|
|
[InlineData(false, null, "password", "username")]
|
|
|
|
|
|
|
|
//password incorrect (required)
|
|
|
|
|
|
|
|
[InlineData(false, "", "password", "username")]
|
|
|
|
|
|
|
|
//password confirm incorrect (required)
|
|
|
|
|
|
|
|
[InlineData(false, "password", null, "username")]
|
|
|
|
|
|
|
|
//password confirm incorrect (required)
|
|
|
|
|
|
|
|
[InlineData(false, "password", "", "username")]
|
|
|
|
|
|
|
|
//password confirm incorrect (compare)
|
|
|
|
|
|
|
|
[InlineData(false, "password", "passwordDifferent", "username")]
|
|
|
|
|
|
|
|
//username incorrect (required)
|
|
|
|
|
|
|
|
[InlineData(false, "password", "password", null)]
|
|
|
|
|
|
|
|
//username incorrect (required)
|
|
|
|
|
|
|
|
[InlineData(false, "password", "password", "")]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void RegisterRequest_Validation(bool isValid, string password, string passwordConfirm, string userName)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var registerRequest = new RegisterRequest { Password = password, PasswordConfirm = passwordConfirm, UserName = userName };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(isValid, ValidateModel(registerRequest));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static bool ValidateModel(RegisterRequest registerRequest)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var validationContext = new ValidationContext(registerRequest, serviceProvider: null, items: null);
|
|
|
|
|
|
|
|
var validationResults = new List<ValidationResult>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Validator.TryValidateObject(registerRequest, validationContext, validationResults, validateAllProperties: true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return !validationResults.Any();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|