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.
61 lines
2.8 KiB
61 lines
2.8 KiB
using System.Collections.Generic;
|
|
using Xunit;
|
|
using adminBlazor.Models;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace TestUnit
|
|
{
|
|
public class UserModel_UT
|
|
{
|
|
[Theory]
|
|
//correct (minimal)
|
|
[InlineData(true, 0, "password", null, "name", null, null, null)]
|
|
//Email correct
|
|
[InlineData(true, 0, "password", "test@example.com", "name", null, null, null)]
|
|
//Surname correct
|
|
[InlineData(true, 0, "password", null, "name", "surname", null, null)]
|
|
//Nickname correct
|
|
[InlineData(true, 0, "password", null, "name", null, "nickname", null)]
|
|
//Group correct
|
|
[InlineData(true, 0, "password", null, "name", null, null, 5)]
|
|
|
|
//Password incorrect (required)
|
|
[InlineData(false, 0, "", null, "name", null, null, null)]
|
|
//Password incorrect (required)
|
|
[InlineData(false, 0, null, null, "name", null, null, null)]
|
|
//Password incorrect (too long)
|
|
[InlineData(false, 0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", null, "name", null, null, null)]
|
|
//Email incorrect (format)
|
|
[InlineData(false, 0, "password", "test", "name", null, null, null)]
|
|
//Name incorrect (required)
|
|
[InlineData(false, 0, "password", null, "", null, null, null)]
|
|
//Name incorrect (required)
|
|
[InlineData(false, 0, "password", null, null, null, null, null)]
|
|
//Name incorrect (too long)
|
|
[InlineData(false, 0, "password", null, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", null, null, null)]
|
|
//Surname incorrect (too long)
|
|
[InlineData(false, 0, "password", null, "name", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", null, null)]
|
|
//Nickname incorrect (too long)
|
|
[InlineData(false, 0, "password", null, "name", null, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", null)]
|
|
//Group incorrect (range)
|
|
[InlineData(false, 0, "password", null, "name", null, null, 5000)]
|
|
|
|
public void UserModel_Validation(bool isValid, int id, string password, string email, string name, string surname, string nickname, int group)
|
|
{
|
|
var userModel = new UserModel { Id = id, Password = password, Email = email, Name = name , Surname = surname, Nickname = nickname, Group = group};
|
|
|
|
Assert.Equal(isValid, ValidateModel(userModel));
|
|
}
|
|
|
|
public static bool ValidateModel(UserModel userModel)
|
|
{
|
|
var validationContext = new ValidationContext(userModel, serviceProvider: null, items: null);
|
|
var validationResults = new List<ValidationResult>();
|
|
|
|
Validator.TryValidateObject(userModel, validationContext, validationResults, validateAllProperties: true);
|
|
|
|
return !validationResults.Any();
|
|
}
|
|
}
|
|
}
|