|
|
|
@ -0,0 +1,38 @@
|
|
|
|
|
using adminBlazor.Models;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
|
|
namespace TestUnit
|
|
|
|
|
{
|
|
|
|
|
public class VocabularyListModel_UT
|
|
|
|
|
{
|
|
|
|
|
[Theory]
|
|
|
|
|
//correct
|
|
|
|
|
[InlineData(true, 0, "name")]
|
|
|
|
|
|
|
|
|
|
//Id incorrect (required)
|
|
|
|
|
[InlineData(true, null, "name")]
|
|
|
|
|
//Name incorrect (required)
|
|
|
|
|
[InlineData(true, 0, "")]
|
|
|
|
|
//Name incorrect (required)
|
|
|
|
|
[InlineData(true, 0, null)]
|
|
|
|
|
//Name incorrect (too long)
|
|
|
|
|
[InlineData(true, 0, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")]
|
|
|
|
|
|
|
|
|
|
public void VocabularyListModel_Validation(bool isValid, int id, string name)
|
|
|
|
|
{
|
|
|
|
|
var vocabularyListModel = new VocabularyListModel { Id = id, Name = name };
|
|
|
|
|
|
|
|
|
|
Assert.Equal(isValid, ValidateModel(vocabularyListModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool ValidateModel(VocabularyListModel vocabularyListModel)
|
|
|
|
|
{
|
|
|
|
|
var validationContext = new ValidationContext(vocabularyListModel, serviceProvider: null, items: null);
|
|
|
|
|
var validationResults = new List<ValidationResult>();
|
|
|
|
|
|
|
|
|
|
Validator.TryValidateObject(vocabularyListModel, validationContext, validationResults, validateAllProperties: true);
|
|
|
|
|
|
|
|
|
|
return !validationResults.Any();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|