diff --git a/Project/adminBlazor/TestUnit/VocListFactory_UT.cs b/Project/adminBlazor/TestUnit/VocListFactory_UT.cs new file mode 100644 index 0000000..4e8dc7d --- /dev/null +++ b/Project/adminBlazor/TestUnit/VocListFactory_UT.cs @@ -0,0 +1,92 @@ +using adminBlazor.Factories; +using adminBlazor.Models; + +namespace TestUnit +{ + public class VocListFactory_UT + { + public static IEnumerable Dataset() + { + yield return new object[] + { + new VocabularyListModel[] + { + new () + { + Id = 0, + Name = "name", + Image = new byte[] { 0x00 }, + Aut = 42, + Translations = new List() + }, + new() + { + Id = 1, + Name = "name2", + Image = new byte[] { 0x00, 0x01 }, + Aut = 50, + Translations = new List() + }, + new() + { + Id = 1, + Name = "name3", + Image = new byte[] { 0x00, 0x01, 0x02 }, + Aut = 60, + Translations = new List() + } + } + }; + } + [Theory] + [MemberData(nameof(Dataset))] + public void Create_Validation(VocabularyListModel[] vocabListMdls) + { + foreach (var vocabListMdl in vocabListMdls) + { + var vocabList = VocListFactory.Create(vocabListMdl); + + Assert.Equal(vocabListMdl.Id, vocabList.Id); + Assert.Equal(vocabListMdl.Name, vocabList.Name); + Assert.Equal(vocabListMdl.Aut, vocabList.Aut); + Assert.Equal(vocabListMdl.Image, vocabList.Image); + } + } + + [Theory] + [MemberData(nameof(Dataset))] + public void Update_Validation(VocabularyListModel[] vocabListMdls) + { + foreach (var vocabListMdl in vocabListMdls) + { + var vocabList = VocListFactory.Create(vocabListMdl); + + vocabListMdl.Name = "a"; + vocabListMdl.Aut = 100; + vocabListMdl.Image = new byte[] { 1, 2, 3 }; + + VocListFactory.Update(vocabList, vocabListMdl); + + Assert.Equal(vocabListMdl.Id, vocabList.Id); + Assert.Equal(vocabListMdl.Name, vocabList.Name); + Assert.Equal(vocabListMdl.Aut, vocabList.Aut); + } + } + + [Theory] + [MemberData(nameof(Dataset))] + public void ToModel_Validation(VocabularyListModel[] vocabListMdls) + { + foreach (var vocabListMdl in vocabListMdls) + { + var vocabList = VocListFactory.Create(vocabListMdl); + var vocabListMdl2 = VocListFactory.ToModel(vocabList, Array.Empty()); + + Assert.Equal(vocabListMdl.Id, vocabListMdl2.Id); + Assert.Equal(vocabListMdl.Name, vocabListMdl2.Name); + Assert.Equal(vocabListMdl.Aut, vocabListMdl2.Aut); + Assert.Equal(vocabListMdl.Image, vocabListMdl2.Image); + } + } + } +} \ No newline at end of file