Compare commits
47 Commits
master
...
blazor-tes
@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\adminBlazor\adminBlazor.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,157 @@
|
||||
using adminBlazor.Factories;
|
||||
using adminBlazor.Models;
|
||||
|
||||
namespace TestUnit
|
||||
{
|
||||
public class UserFactory_UT
|
||||
{
|
||||
public static IEnumerable<object[]> Dataset()
|
||||
{
|
||||
yield return new object[]
|
||||
{
|
||||
new UserModel[]
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 0,
|
||||
Password = "password",
|
||||
Email = "email",
|
||||
Name = "name",
|
||||
Surname = "surname",
|
||||
Nickname = "nickname",
|
||||
ExtraTime = false,
|
||||
Group = 5,
|
||||
Roles = new List<string>() { "student" }
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Password = "password2",
|
||||
Email = "email2",
|
||||
Name = "name2",
|
||||
Surname = "surname2",
|
||||
Nickname = "nickname2",
|
||||
ExtraTime = true,
|
||||
Group = 10,
|
||||
Roles = new List<string>() {"teacher"},
|
||||
Image = new byte[] {3, 4, 5}
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
Password = "password3",
|
||||
Email = "email3",
|
||||
Name = "name3",
|
||||
Surname = "surname3",
|
||||
Nickname = "nickname3",
|
||||
ExtraTime = false,
|
||||
Group = 15,
|
||||
Roles = new List<string>() {"admin"},
|
||||
Image = new byte[] {6, 7, 8}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
[Theory]
|
||||
[MemberData(nameof(Dataset))]
|
||||
public void Create_Validation(UserModel[] userMdls)
|
||||
{
|
||||
foreach (var userMdl in userMdls)
|
||||
{
|
||||
var user = UserFactory.Create(userMdl);
|
||||
|
||||
Assert.Equal(userMdl.Id, user.Id);
|
||||
Assert.Equal(userMdl.Password, user.Password);
|
||||
Assert.Equal(userMdl.Email, user.Email);
|
||||
Assert.Equal(userMdl.Name, user.Name);
|
||||
Assert.Equal(userMdl.Surname, user.Surname);
|
||||
Assert.Equal(userMdl.Nickname, user.Nickname);
|
||||
Assert.Equal(userMdl.ExtraTime, user.ExtraTime);
|
||||
Assert.Equal(userMdl.Group, user.Group);
|
||||
if (userMdl.Image != null)
|
||||
{
|
||||
Assert.Equal(Convert.ToBase64String(userMdl.Image), user.ImageBase64);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Null(user.ImageBase64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Dataset))]
|
||||
public void Update_Validation(UserModel[] userMdls)
|
||||
{
|
||||
foreach (var userMdl in userMdls)
|
||||
{
|
||||
if (userMdl.Image != null)
|
||||
{
|
||||
userMdl.ImageBase64 = Convert.ToBase64String(userMdl.Image);
|
||||
}
|
||||
|
||||
var user = UserFactory.Create(userMdl);
|
||||
|
||||
userMdl.Password = "a";
|
||||
userMdl.Email = "a.a@a.com";
|
||||
userMdl.Name = "a";
|
||||
userMdl.Surname = "a";
|
||||
userMdl.Nickname = "a";
|
||||
userMdl.ExtraTime = true;
|
||||
userMdl.Group = 50;
|
||||
|
||||
UserFactory.Update(user, userMdl);
|
||||
|
||||
Assert.Equal(userMdl.Password, user.Password);
|
||||
Assert.Equal(userMdl.Email, user.Email);
|
||||
Assert.Equal(userMdl.Name, user.Name);
|
||||
Assert.Equal(userMdl.Surname, user.Surname);
|
||||
Assert.Equal(userMdl.Nickname, user.Nickname);
|
||||
Assert.Equal(userMdl.ExtraTime, user.ExtraTime);
|
||||
Assert.Equal(userMdl.Group, user.Group);
|
||||
for (int i=0;i<user.Roles.Count;i++)
|
||||
{
|
||||
user.Roles[i] = user.Roles[i].ToLower();
|
||||
}
|
||||
Assert.True(userMdl.Roles.SequenceEqual(user.Roles));
|
||||
|
||||
if(userMdl.Image != null)
|
||||
{
|
||||
Assert.Equal(userMdl.ImageBase64, user.ImageBase64);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Null(user.ImageBase64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Dataset))]
|
||||
public void ToModel_Validation(UserModel[] userMdls)
|
||||
{
|
||||
foreach (var userMdl in userMdls)
|
||||
{
|
||||
var user = UserFactory.Create(userMdl);
|
||||
var userMdl2 = UserFactory.ToModel(user, Array.Empty<byte>());
|
||||
|
||||
Assert.Equal(userMdl.Password, userMdl2.Password);
|
||||
Assert.Equal(userMdl.Email, userMdl2.Email);
|
||||
Assert.Equal(userMdl.Name, userMdl2.Name);
|
||||
Assert.Equal(userMdl.Surname, userMdl2.Surname);
|
||||
Assert.Equal(userMdl.Nickname, userMdl2.Nickname);
|
||||
Assert.Equal(userMdl.ExtraTime, userMdl2.ExtraTime);
|
||||
Assert.Equal(userMdl.Group, userMdl2.Group);
|
||||
|
||||
if (user.ImageBase64 != null)
|
||||
{
|
||||
Assert.Equal(user.ImageBase64, userMdl2.ImageBase64);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal("", userMdl2.ImageBase64);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
using adminBlazor.Factories;
|
||||
using adminBlazor.Models;
|
||||
using adminBlazor.Pages;
|
||||
|
||||
namespace TestUnit
|
||||
{
|
||||
public class VocListFactory_UT
|
||||
{
|
||||
public static IEnumerable<object[]> Dataset()
|
||||
{
|
||||
yield return new object[]
|
||||
{
|
||||
new VocabularyListModel[]
|
||||
{
|
||||
new ()
|
||||
{
|
||||
Id = 0,
|
||||
Name = "name",
|
||||
Image = new byte[] { 0x00 },
|
||||
Aut = 42,
|
||||
Translations = new List<TranslationModel>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
FirstWord = "firstword",
|
||||
SecondWord = "secondword"
|
||||
}
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Name = "name2",
|
||||
Aut = 50,
|
||||
Translations = new List<TranslationModel>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 2,
|
||||
FirstWord = "firstword2",
|
||||
SecondWord = "secondword2"
|
||||
}
|
||||
}
|
||||
},
|
||||
new()
|
||||
{
|
||||
Id = 1,
|
||||
Name = "name3",
|
||||
Image = new byte[] { 0x00, 0x01, 0x02 },
|
||||
Aut = 60,
|
||||
Translations = new List<TranslationModel>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Id = 3,
|
||||
FirstWord = "firstword3",
|
||||
SecondWord = "secondword3"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
[Theory]
|
||||
[MemberData(nameof(Dataset))]
|
||||
public void Create_Validation(VocabularyListModel[] vocabListMdls)
|
||||
{
|
||||
foreach (var vocabListMdl in vocabListMdls)
|
||||
{
|
||||
if (vocabListMdl.Image != null)
|
||||
{
|
||||
vocabListMdl.ImageBase64 = Convert.ToBase64String(vocabListMdl.Image);
|
||||
}
|
||||
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);
|
||||
if (vocabList.Translations != null)
|
||||
{
|
||||
Assert.Single(vocabList.Translations);
|
||||
}
|
||||
if (vocabListMdl.Image != null)
|
||||
{
|
||||
Assert.Equal(vocabListMdl.ImageBase64, vocabList.ImageBase64);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Null(vocabList.ImageBase64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Dataset))]
|
||||
public void Update_Validation(VocabularyListModel[] vocabListMdls)
|
||||
{
|
||||
foreach (var vocabListMdl in vocabListMdls)
|
||||
{
|
||||
if (vocabListMdl.Image != null)
|
||||
{
|
||||
vocabListMdl.ImageBase64 = Convert.ToBase64String(vocabListMdl.Image);
|
||||
}
|
||||
var vocabList = VocListFactory.Create(vocabListMdl);
|
||||
|
||||
vocabListMdl.Name = "a";
|
||||
vocabListMdl.Aut = 100;
|
||||
|
||||
VocListFactory.Update(vocabList, vocabListMdl);
|
||||
|
||||
Assert.Equal(vocabListMdl.Id, vocabList.Id);
|
||||
Assert.Equal(vocabListMdl.Name, vocabList.Name);
|
||||
Assert.Equal(vocabListMdl.Aut, vocabList.Aut);
|
||||
if (vocabList.Translations != null)
|
||||
{
|
||||
Assert.Single(vocabList.Translations);
|
||||
}
|
||||
if (vocabListMdl.Image != null)
|
||||
{
|
||||
Assert.Equal(vocabListMdl.ImageBase64, vocabList.ImageBase64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Dataset))]
|
||||
public void ToModel_Validation(VocabularyListModel[] vocabListMdls)
|
||||
{
|
||||
foreach (var vocabListMdl in vocabListMdls)
|
||||
{
|
||||
if (vocabListMdl.Image != null)
|
||||
{
|
||||
vocabListMdl.ImageBase64 = Convert.ToBase64String(vocabListMdl.Image);
|
||||
}
|
||||
var vocabList = VocListFactory.Create(vocabListMdl);
|
||||
var vocabListMdl2 = VocListFactory.ToModel(vocabList, Array.Empty<byte>());
|
||||
|
||||
Assert.Equal(vocabListMdl.Id, vocabListMdl2.Id);
|
||||
Assert.Equal(vocabListMdl.Name, vocabListMdl2.Name);
|
||||
Assert.Equal(vocabListMdl.Aut, vocabListMdl2.Aut);
|
||||
Assert.Equal(vocabListMdl.Image, vocabListMdl2.Image);
|
||||
if (vocabListMdl2.Translations != null)
|
||||
{
|
||||
Assert.Single(vocabListMdl2.Translations);
|
||||
}
|
||||
if (vocabList.ImageBase64 != null)
|
||||
{
|
||||
Assert.Equal(vocabList.ImageBase64, vocabListMdl2.ImageBase64);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal("", vocabListMdl2.ImageBase64);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,35 @@
|
||||
using adminBlazor.Models;
|
||||
|
||||
namespace adminBlazor.Factories;
|
||||
|
||||
public class TranslationFactory
|
||||
{
|
||||
public static Translation Create(TranslationModel model)
|
||||
{
|
||||
return new Translation
|
||||
{
|
||||
Id = model.Id,
|
||||
FirstWord = model.FirstWord,
|
||||
SecondWord = model.SecondWord
|
||||
};
|
||||
}
|
||||
|
||||
public static TranslationModel ToModel(Translation translation)
|
||||
{
|
||||
return new TranslationModel
|
||||
{
|
||||
Id = translation.Id,
|
||||
FirstWord = translation.FirstWord,
|
||||
SecondWord = translation.SecondWord
|
||||
};
|
||||
}
|
||||
|
||||
public static void Update(Translation item, TranslationModel model)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(model.FirstWord))
|
||||
item.FirstWord = model.FirstWord;
|
||||
|
||||
if (!string.IsNullOrEmpty(model.SecondWord))
|
||||
item.SecondWord = model.SecondWord;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
@page "/add"
|
||||
@page "/addUser"
|
||||
@attribute [Authorize(Roles = "admin")]
|
||||
@using adminBlazor.Models
|
||||
<h3>Add</h3>
|
||||
|
||||
<EditForm Model="@user" OnValidSubmit="@HandleValidSubmit">
|
@ -0,0 +1,44 @@
|
||||
@page "/addVoc"
|
||||
@attribute [Authorize(Roles = "teacher")]
|
||||
@using adminBlazor.Models
|
||||
@using Blazorise.Extensions
|
||||
<h3>Add Vocabulary List</h3>
|
||||
|
||||
<EditForm Model="@voc" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<p>
|
||||
<label for="name">
|
||||
Name:
|
||||
<InputText id="name" @bind-Value="voc.Name" />
|
||||
<ValidationMessage For="@(() => voc.Name)"/>
|
||||
</label>
|
||||
</p>
|
||||
<h4>Words:</h4>
|
||||
@if (voc.Translations.IsNullOrEmpty() == false)
|
||||
{
|
||||
foreach (var word in voc.Translations)
|
||||
{
|
||||
{
|
||||
<div class="word-container">
|
||||
<label>
|
||||
First Word:
|
||||
<InputText @bind-Value="word.FirstWord"/>
|
||||
</label>
|
||||
<label>
|
||||
Second Word:
|
||||
<InputText @bind-Value="word.SecondWord"/>
|
||||
</label>
|
||||
</div>
|
||||
<button type="button" @onclick="() => RemoveWord(word)">Remove Word</button>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>No words</p>
|
||||
}
|
||||
<button type="button" @onclick="AddWord">Add Word</button>
|
||||
<button type="submit">Submit</button>
|
||||
</EditForm>
|
@ -1,29 +1,55 @@
|
||||
@page "/editVoc/{Id:int}"
|
||||
@attribute [Authorize(Roles = "teacher")]
|
||||
@using adminBlazor.Models
|
||||
@using Blazorise.Extensions
|
||||
|
||||
|
||||
<h3>Edit</h3>
|
||||
<h4>Voc id : @Id</h4>
|
||||
<EditForm Model="@voc" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
@if (voc != null)
|
||||
{
|
||||
<EditForm Model="@voc" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<p>
|
||||
<label for="name">
|
||||
Name:
|
||||
<InputText id="name" @bind-Value="voc.Name" />
|
||||
<ValidationMessage For="@(() => voc.Name)" />
|
||||
</label>
|
||||
|
||||
<p>
|
||||
<label for="name">
|
||||
Name:
|
||||
<InputText id="name" @bind-Value="voc.Name" />
|
||||
<ValidationMessage For="@(() => voc.Name)" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="image">
|
||||
Image:
|
||||
<InputText id="image" @bind-Value="voc.Image" />
|
||||
<ValidationMessage For="@(() => voc.Image)" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<button type="submit">Submit</button>
|
||||
</EditForm>
|
||||
</p>
|
||||
|
||||
<h4>Words:</h4>
|
||||
@if (voc.Translations.IsNullOrEmpty() == false)
|
||||
{
|
||||
foreach (var word in voc.Translations)
|
||||
{
|
||||
{
|
||||
<div class="word-container">
|
||||
<label>
|
||||
First Word:
|
||||
<InputText @bind-Value="word.FirstWord"/>
|
||||
</label>
|
||||
<label>
|
||||
Second Word:
|
||||
<InputText @bind-Value="word.SecondWord"/>
|
||||
</label>
|
||||
</div>
|
||||
<button type="button" @onclick="() => RemoveWord(word)">Remove Word</button>
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>No words</p>
|
||||
}
|
||||
<button type="button" @onclick="AddWord">Add Word</button>
|
||||
<button type="submit">Submit</button>
|
||||
</EditForm>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
After Width: | Height: | Size: 156 KiB |
Loading…
Reference in new issue