You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
38 lines
1.2 KiB
using adminBlazor.Models;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace TestUnit
|
|
{
|
|
public class LoginRequest_UT
|
|
{
|
|
[Theory]
|
|
//correct
|
|
[InlineData(true, "password", "username")]
|
|
//password incorrect (required)
|
|
[InlineData(false, null, "username")]
|
|
//password incorrect (required)
|
|
[InlineData(false, "", "username")]
|
|
//username incorrect (required)
|
|
[InlineData(false, "password", null)]
|
|
//username incorrect (required)
|
|
[InlineData(false, "password", "")]
|
|
|
|
public void LoginRequest_Validation(bool isValid, string password, string userName)
|
|
{
|
|
var loginRequest = new LoginRequest { Password = password, UserName = userName };
|
|
|
|
Assert.Equal(isValid, ValidateModel(loginRequest));
|
|
}
|
|
|
|
private static bool ValidateModel(LoginRequest loginRequest)
|
|
{
|
|
var validationContext = new ValidationContext(loginRequest, serviceProvider: null, items: null);
|
|
var validationResults = new List<ValidationResult>();
|
|
|
|
Validator.TryValidateObject(loginRequest, validationContext, validationResults, validateAllProperties: true);
|
|
|
|
return !validationResults.Any();
|
|
}
|
|
}
|
|
}
|