|
|
|
@ -0,0 +1,46 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using adminBlazor.Models;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
|
|
namespace TestUnit
|
|
|
|
|
{
|
|
|
|
|
public class UserModel_UT
|
|
|
|
|
{
|
|
|
|
|
[Theory]
|
|
|
|
|
// user correct
|
|
|
|
|
[InlineData(true, 0, "Password", "test@example.com", "Name", "Surname", "Nickname")]
|
|
|
|
|
//Password incorrect (too long)
|
|
|
|
|
[InlineData(false, 1, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "test@example.com", "Name", "Surname", "Nickname")]
|
|
|
|
|
//Email incorrect (format)
|
|
|
|
|
[InlineData(false, 2, "Password", "test", "Name", "Surname", "Nickname")]
|
|
|
|
|
//Name incorrect (required)
|
|
|
|
|
[InlineData(false, 3, "Password", "test", null, "Surname", "Nickname")]
|
|
|
|
|
//Name incorrect (required)
|
|
|
|
|
[InlineData(false, 4, "Password", "test", "", "Surname", "Nickname")]
|
|
|
|
|
//Name incorrect (too long)
|
|
|
|
|
[InlineData(false, 5, "Password", "test", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "Surname", "Nickname")]
|
|
|
|
|
//Surname incorrect (too long)
|
|
|
|
|
[InlineData(false, 6, "Password", "test@example.com", "Name", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "Nickname")]
|
|
|
|
|
//Nickname incorreect (too long)
|
|
|
|
|
[InlineData(false, 7, "Password", "test@example.com", "Name", "Surname", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void UserModel_Validation(bool isValid, int id, string password, string email, string name, string surname, string nickname)
|
|
|
|
|
{
|
|
|
|
|
var userModel = new UserModel { Id = id, Password = password, Email = email, Name = name , Surname = surname, Nickname = nickname};
|
|
|
|
|
|
|
|
|
|
Assert.Equal(isValid, ValidateModel(userModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private 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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|