|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
namespace Tests;
|
|
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
using DataManagers;
|
|
|
|
|
using EFLib;
|
|
|
|
|
using Microsoft.Data.Sqlite;
|
|
|
|
@ -10,8 +11,11 @@ using Model;
|
|
|
|
|
public class DbChampionManager_UT
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Add_TestAsync()
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(true, true, 8, "Aurelien", ChampionClass.Tank, "tro bo le type")]
|
|
|
|
|
[InlineData(true, false, 8, "Marche sans ID", ChampionClass.Tank, "tro bo le type")]
|
|
|
|
|
[InlineData(false, true, 8, "Marche pas", ChampionClass.Tank, "tro bo le type")]
|
|
|
|
|
public async Task Add_TestAsync(bool isValid, bool hasId,int id, string name, ChampionClass championClass, string bio)
|
|
|
|
|
{
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
connection.Open();
|
|
|
|
@ -23,28 +27,32 @@ public class DbChampionManager_UT
|
|
|
|
|
|
|
|
|
|
using (var db = new DbDataManager(new EFLib.LolContext(options)))
|
|
|
|
|
{
|
|
|
|
|
db.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
Champion champion = new Champion("Aurelien", ChampionClass.Tank, "tro bo le type");
|
|
|
|
|
Champion champion2 = new Champion("Croissant", ChampionClass.Assassin, "tro bon le type");
|
|
|
|
|
Champion champion3 = new Champion("Mathilde", ChampionClass.Fighter, "Chut mathilde");
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion);
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion2);
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var db = new DbDataManager(new EFLib.LolContext(options)))
|
|
|
|
|
{
|
|
|
|
|
db.EnsureCreated();
|
|
|
|
|
Assert.Equal(3, await db.ChampionsMgr.GetNbItems());
|
|
|
|
|
Assert.Null(await db.ChampionsMgr.AddItem(new Champion("Aurelien", ChampionClass.Tank, "tro bo le type")));
|
|
|
|
|
await db.EnsureCreatedAsync();
|
|
|
|
|
|
|
|
|
|
Champion champion = new Champion(name, championClass, bio);
|
|
|
|
|
if (hasId)
|
|
|
|
|
{
|
|
|
|
|
champion = new Champion(id, name, championClass, bio);
|
|
|
|
|
}
|
|
|
|
|
Champion? c = await db.ChampionsMgr.AddItem(champion);
|
|
|
|
|
|
|
|
|
|
if (isValid)
|
|
|
|
|
{
|
|
|
|
|
Assert.NotNull(c);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Champion? c1 = await db.ChampionsMgr.AddItem(champion);
|
|
|
|
|
Assert.Null(c1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Delete_TestAsync()
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(true, true, 18, "Aurelien", ChampionClass.Tank, "tro bo le type")]
|
|
|
|
|
[InlineData(true, false, 19, "Marche sans Id", ChampionClass.Tank, "tro bo le type")]
|
|
|
|
|
[InlineData(false, true, 20, "Marche pas", ChampionClass.Tank, "tro bo le type")]
|
|
|
|
|
public async Task Delete_TestAsync(bool isValid, bool hasId, int id, string name, ChampionClass championClass, string bio)
|
|
|
|
|
{
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
connection.Open();
|
|
|
|
@ -55,32 +63,71 @@ public class DbChampionManager_UT
|
|
|
|
|
|
|
|
|
|
using (var db = new DbDataManager(new EFLib.LolContext(options)))
|
|
|
|
|
{
|
|
|
|
|
db.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
Champion champion = new Champion("Aurelien", ChampionClass.Tank, "tro bo le type");
|
|
|
|
|
Champion champion2 = new Champion("Croissant", ChampionClass.Assassin, "tro bon le type");
|
|
|
|
|
Champion champion3 = new Champion("Mathilde", ChampionClass.Fighter, "Chut mathilde");
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion);
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion2);
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion3);
|
|
|
|
|
await db.Context.Database.EnsureCreatedAsync();
|
|
|
|
|
|
|
|
|
|
Champion champion = new Champion(name, championClass, bio);
|
|
|
|
|
if (hasId)
|
|
|
|
|
{
|
|
|
|
|
champion = new Champion(id, name, championClass, bio);
|
|
|
|
|
}
|
|
|
|
|
if (isValid)
|
|
|
|
|
{
|
|
|
|
|
Champion? c = await db.ChampionsMgr.AddItem(champion);
|
|
|
|
|
var retour = await db.ChampionsMgr.DeleteItem(champion);
|
|
|
|
|
Assert.True(retour);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var retour = await db.ChampionsMgr.DeleteItem(champion);
|
|
|
|
|
Assert.False(retour);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var db = new DbDataManager(new EFLib.LolContext(options)))
|
|
|
|
|
{
|
|
|
|
|
db.EnsureCreated();
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(true, true, 18, "Aurelien", ChampionClass.Tank, "tro bo le type")]
|
|
|
|
|
[InlineData(true, false, 19, "Marche sans Id", ChampionClass.Tank, "tro bo le type")]
|
|
|
|
|
[InlineData(false, true, 20, "Marche pas", ChampionClass.Tank, "tro bo le type")]
|
|
|
|
|
public async Task Modify_TestAsync(bool isValid, bool hasId, int id, string name, ChampionClass championClass, string bio)
|
|
|
|
|
{
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
connection.Open();
|
|
|
|
|
|
|
|
|
|
string nameToFind = "Croissant";
|
|
|
|
|
IEnumerable<Champion> champ = await db.ChampionsMgr.GetItemsByName(nameToFind, 0, 15, "name");
|
|
|
|
|
Champion c = champ.First();
|
|
|
|
|
Assert.Equal("Croissant", c.Name);
|
|
|
|
|
await db.ChampionsMgr.DeleteItem(champ.First());
|
|
|
|
|
var options = new DbContextOptionsBuilder<LolContext>()
|
|
|
|
|
.UseSqlite(connection)
|
|
|
|
|
.Options;
|
|
|
|
|
|
|
|
|
|
Assert.Equal(2, await db.ChampionsMgr.GetNbItems());
|
|
|
|
|
using (var db = new DbDataManager(new EFLib.LolContext(options)))
|
|
|
|
|
{
|
|
|
|
|
await db.Context.Database.EnsureCreatedAsync();
|
|
|
|
|
|
|
|
|
|
Champion champion = new Champion(name, championClass, bio);
|
|
|
|
|
if (hasId)
|
|
|
|
|
{
|
|
|
|
|
champion = new Champion(id, name, championClass, bio);
|
|
|
|
|
}
|
|
|
|
|
if (isValid)
|
|
|
|
|
{
|
|
|
|
|
Champion? c = await db.ChampionsMgr.AddItem(champion);
|
|
|
|
|
var retour = await db.ChampionsMgr.UpdateItem(c, new Champion(champion.Id, champion.Name, bio: "blabla"));
|
|
|
|
|
Assert.Equal("blabla", retour.Bio);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var retour = await db.ChampionsMgr.UpdateItem(champion, new Champion(champion.Id, champion.Name, bio: "blabla"));
|
|
|
|
|
Assert.Null(retour);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Modify_TestAsync()
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("name", false)]
|
|
|
|
|
[InlineData("bio", false)]
|
|
|
|
|
[InlineData("class", false)]
|
|
|
|
|
[InlineData("name", true)]
|
|
|
|
|
[InlineData("bio", true)]
|
|
|
|
|
[InlineData("class", true)]
|
|
|
|
|
public async Task GetItems_TestAsync(string orderingProperty, bool reverse)
|
|
|
|
|
{
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
connection.Open();
|
|
|
|
@ -91,35 +138,27 @@ public class DbChampionManager_UT
|
|
|
|
|
|
|
|
|
|
using (var db = new DbDataManager(new EFLib.LolContext(options)))
|
|
|
|
|
{
|
|
|
|
|
db.EnsureCreated();
|
|
|
|
|
await db.Context.Database.EnsureCreatedAsync();
|
|
|
|
|
|
|
|
|
|
Champion champion = new Champion("test1", ChampionClass.Unknown, "test1");
|
|
|
|
|
Champion champion1 = new Champion("test2", ChampionClass.Assassin, "test2");
|
|
|
|
|
Champion champion2 = new Champion("test3", ChampionClass.Fighter, "test3");
|
|
|
|
|
|
|
|
|
|
Champion champion = new Champion("Aurelien", ChampionClass.Tank, "tro bo le type");
|
|
|
|
|
Champion champion2 = new Champion("Croissant", ChampionClass.Assassin, "tro bon le type");
|
|
|
|
|
Champion champion3 = new Champion("Mathilde", ChampionClass.Fighter, "Chut mathilde");
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion);
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion1);
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion2);
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion3);
|
|
|
|
|
}
|
|
|
|
|
using (var db = new DbDataManager(new EFLib.LolContext(options)))
|
|
|
|
|
{
|
|
|
|
|
db.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
string nameToFind = "Croissant";
|
|
|
|
|
IEnumerable<Champion> champ = await db.ChampionsMgr.GetItemsByName(nameToFind, 0, 15, "name");
|
|
|
|
|
Champion c = champ.First();
|
|
|
|
|
Assert.Equal("Croissant", c.Name);
|
|
|
|
|
Champion c1 = new Champion("Test", c.Class, c.Icon, bio: c.Bio);
|
|
|
|
|
await db.ChampionsMgr.UpdateItem(c, c1);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(3, await db.ChampionsMgr.GetNbItems());
|
|
|
|
|
champ = await db.ChampionsMgr.GetItemsByName("Test", 0, 15, "name");
|
|
|
|
|
var list = await db.ChampionsMgr.GetItems(0, 10, orderingProperty, reverse);
|
|
|
|
|
|
|
|
|
|
Assert.Equal("Test", champ.First().Name);
|
|
|
|
|
Assert.Equal(3, list.Count());
|
|
|
|
|
//if (reverse) Assert.Equal("test3", list.First().Name);
|
|
|
|
|
//else Assert.Equal("test1", list.First().Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task GetItems_TestAsync()
|
|
|
|
|
public async Task getNbItems_TestASync()
|
|
|
|
|
{
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
connection.Open();
|
|
|
|
@ -130,32 +169,9 @@ public class DbChampionManager_UT
|
|
|
|
|
|
|
|
|
|
using (var db = new DbDataManager(new EFLib.LolContext(options)))
|
|
|
|
|
{
|
|
|
|
|
db.EnsureCreated();
|
|
|
|
|
|
|
|
|
|
Champion champion = new Champion("Aurelien", ChampionClass.Tank, "hey bo le type");
|
|
|
|
|
Champion champion2 = new Champion("Croissant", ChampionClass.Assassin, "Ztro bon le type");
|
|
|
|
|
Champion champion3 = new Champion("Mathilde", ChampionClass.Fighter, "ah mathilde");
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion);
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion2);
|
|
|
|
|
await db.ChampionsMgr.AddItem(champion3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var db = new DbDataManager(new EFLib.LolContext(options)))
|
|
|
|
|
{
|
|
|
|
|
db.EnsureCreated();
|
|
|
|
|
var list = await db.ChampionsMgr.GetItems(0, 10, "bio", false);
|
|
|
|
|
Assert.Equal(3, list.Count());
|
|
|
|
|
list = await db.ChampionsMgr.GetItems(0, 3, "autre", true);
|
|
|
|
|
Assert.Equal("Aurelien", list.Last().Name);
|
|
|
|
|
list = await db.ChampionsMgr.GetItems(0, 3, "class", true);
|
|
|
|
|
Assert.Equal("Aurelien", list.First().Name);
|
|
|
|
|
list = await db.ChampionsMgr.GetItemsByClass(ChampionClass.Assassin, 0, 10);
|
|
|
|
|
Assert.Equal(1, list.Count());
|
|
|
|
|
Assert.Equal("Croissant", list.First().Name);
|
|
|
|
|
|
|
|
|
|
await db.Context.Database.EnsureCreatedAsync();
|
|
|
|
|
Assert.Equal(3, await db.ChampionsMgr.GetNbItems());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|