From 30006c2a05601e8186b38281ca02391fc55ebb93 Mon Sep 17 00:00:00 2001 From: Louison PARANT Date: Sun, 26 Mar 2023 18:22:10 +0200 Subject: [PATCH] merge EF master --- Sources/APILOL/APILOL.csproj | 2 + Sources/APILOL/Mapper/SkillMapper.cs | 15 + Sources/DTO/DTO.csproj | 2 + .../EntityFrameworkLOL.csproj | 2 + Sources/LeagueOfLegends.sln | 8 +- Sources/ManagersEF/ManagersEF.csproj | 5 + Sources/Model/Model.csproj | 2 + Sources/Shared/Shared.csproj | 2 + Sources/StubLib/StubLib.csproj | 2 + Sources/TestEF/TestChampions.cs | 189 ++++++++++++ Sources/TestEF/TestEF.csproj | 19 ++ Sources/TestEF/TestRunePages.cs | 277 ++++++++++++++++++ Sources/TestEF/TestRunes.cs | 154 ++++++++++ Sources/TestEF/TestSkins.cs | 182 ++++++++++++ Sources/TestUnitaire/TestUnitaire.csproj | 2 + .../Tests/ConsoleTests/ConsoleTests.csproj | 2 + .../Controllers/WeatherForecastController.cs | 33 +++ Sources/TestsEF/Program.cs | 25 ++ .../TestsEF/Properties/launchSettings.json | 31 ++ Sources/TestsEF/TestsEF.csproj | 13 + Sources/TestsEF/WeatherForecast.cs | 13 + Sources/TestsEF/appsettings.Development.json | 8 + Sources/TestsEF/appsettings.json | 9 + 23 files changed, 996 insertions(+), 1 deletion(-) create mode 100644 Sources/TestEF/TestChampions.cs create mode 100644 Sources/TestEF/TestEF.csproj create mode 100644 Sources/TestEF/TestRunePages.cs create mode 100644 Sources/TestEF/TestRunes.cs create mode 100644 Sources/TestEF/TestSkins.cs create mode 100644 Sources/TestsEF/Controllers/WeatherForecastController.cs create mode 100644 Sources/TestsEF/Program.cs create mode 100644 Sources/TestsEF/Properties/launchSettings.json create mode 100644 Sources/TestsEF/TestsEF.csproj create mode 100644 Sources/TestsEF/WeatherForecast.cs create mode 100644 Sources/TestsEF/appsettings.Development.json create mode 100644 Sources/TestsEF/appsettings.json diff --git a/Sources/APILOL/APILOL.csproj b/Sources/APILOL/APILOL.csproj index 73a3b44..d31ccf0 100644 --- a/Sources/APILOL/APILOL.csproj +++ b/Sources/APILOL/APILOL.csproj @@ -19,6 +19,8 @@ + + diff --git a/Sources/APILOL/Mapper/SkillMapper.cs b/Sources/APILOL/Mapper/SkillMapper.cs index 3101b6a..0a6eb24 100644 --- a/Sources/APILOL/Mapper/SkillMapper.cs +++ b/Sources/APILOL/Mapper/SkillMapper.cs @@ -27,5 +27,20 @@ namespace APILOL.Mapper public static Skill ToModel(this SkillEntity entity) => new(entity.Name, entity.Type, entity.Description); + + public static SkillDTO ToDto(this Skill skill) + { + return new SkillDTO() + { + Type = skill.Type, + Name = skill.Name, + Description = skill.Description + }; + } + + public static Skill ToModel(this SkillDTO skill) + { + return new Skill(skill.Name, skill.Type, skill.Description); + } } } diff --git a/Sources/DTO/DTO.csproj b/Sources/DTO/DTO.csproj index 5c5bf12..1e9c418 100644 --- a/Sources/DTO/DTO.csproj +++ b/Sources/DTO/DTO.csproj @@ -14,6 +14,8 @@ + + diff --git a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj index 9c01959..cf05703 100644 --- a/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj +++ b/Sources/EntityFrameworkLOL/EntityFrameworkLOL.csproj @@ -19,6 +19,8 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index ae1d2ac..cc1494e 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -23,7 +23,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkLOL", "Entit EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUnitaire", "TestUnitaire\TestUnitaire.csproj", "{D24FBC48-F9C3-45CA-8D51-A851559C307F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagersEF", "ManagersEF\ManagersEF.csproj", "{A8685E74-67E4-4382-AF91-38045AC0014B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ManagersEF", "ManagersEF\ManagersEF.csproj", "{A8685E74-67E4-4382-AF91-38045AC0014B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestEF", "TestEF\TestEF.csproj", "{81CEA57F-3CCB-4CF8-8315-2B5BC403E0FD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -67,6 +69,10 @@ Global {A8685E74-67E4-4382-AF91-38045AC0014B}.Debug|Any CPU.Build.0 = Debug|Any CPU {A8685E74-67E4-4382-AF91-38045AC0014B}.Release|Any CPU.ActiveCfg = Release|Any CPU {A8685E74-67E4-4382-AF91-38045AC0014B}.Release|Any CPU.Build.0 = Release|Any CPU + {81CEA57F-3CCB-4CF8-8315-2B5BC403E0FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {81CEA57F-3CCB-4CF8-8315-2B5BC403E0FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {81CEA57F-3CCB-4CF8-8315-2B5BC403E0FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {81CEA57F-3CCB-4CF8-8315-2B5BC403E0FD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/ManagersEF/ManagersEF.csproj b/Sources/ManagersEF/ManagersEF.csproj index 2b6d57c..9b8aa9f 100644 --- a/Sources/ManagersEF/ManagersEF.csproj +++ b/Sources/ManagersEF/ManagersEF.csproj @@ -6,6 +6,11 @@ enable + + + + + diff --git a/Sources/Model/Model.csproj b/Sources/Model/Model.csproj index 4eb62df..8ab99d0 100644 --- a/Sources/Model/Model.csproj +++ b/Sources/Model/Model.csproj @@ -20,6 +20,8 @@ + + diff --git a/Sources/Shared/Shared.csproj b/Sources/Shared/Shared.csproj index 94a926e..88548eb 100644 --- a/Sources/Shared/Shared.csproj +++ b/Sources/Shared/Shared.csproj @@ -14,6 +14,8 @@ + + diff --git a/Sources/StubLib/StubLib.csproj b/Sources/StubLib/StubLib.csproj index a3c6686..6a5b346 100644 --- a/Sources/StubLib/StubLib.csproj +++ b/Sources/StubLib/StubLib.csproj @@ -14,6 +14,8 @@ + + diff --git a/Sources/TestEF/TestChampions.cs b/Sources/TestEF/TestChampions.cs new file mode 100644 index 0000000..720a0fb --- /dev/null +++ b/Sources/TestEF/TestChampions.cs @@ -0,0 +1,189 @@ +using EntityFrameworkLOL.Entities; +using EntityFrameworkLOL.DBContexts; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Model; +using Shared; +using System.Xml.Linq; +using Xunit.Abstractions; +using Xunit; +using ManagersEF; + +namespace TestEF +{ + public class TestChampions + { + + [Fact] + public async void Test_Add() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + Champion batman = new("Batman", ChampionClass.Assassin, "icon_1", "image_1", "L'ombre de la nuit"); + batman.AddSkill(new("Bat-signal", SkillType.Basic, "Envoie le signal")); + batman.AddCharacteristics(new[] { + Tuple.Create("Force", 150), + Tuple.Create("Agilité", 500) + }); + Champion endeavor = new("Endeavor", ChampionClass.Tank, "icon_2", "image_2", "Feu brûlant énernel"); + endeavor.AddSkill(new("Final flames", SkillType.Ultimate, "Dernière flamme d'un héro")); + endeavor.AddCharacteristics(new[] { + Tuple.Create("Force", 200), + Tuple.Create("Défense", 300), + Tuple.Create("Alter", 800) + }); + + + Champion escanor = new("Escanor", ChampionClass.Fighter, "icon_3", "image_3", "1, 2, 3, Soleil"); + escanor.AddSkill(new("Croissance solaire", SkillType.Passive, "Le soleil rends plus fort !")); + escanor.AddCharacteristics(new[] { + Tuple.Create("Force", 500), + Tuple.Create("Défense", 500) + }); + + await manager.AddItem(batman); + await manager.AddItem(endeavor); + await manager.AddItem(escanor); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + var nbItems = await manager.GetNbItems(); + Assert.Equal(3, nbItems); + + var items = await manager.GetItemsByName("Batman", 0, nbItems); + Assert.Equal("Batman", items.First().Name); + + + Assert.Equal(2, await manager.GetNbItemsByName("E")); + + items = await manager.GetItemsBySkill("Croissance solaire", 0, nbItems); + Assert.Equal("Escanor", items.First().Name); + + items = await manager.GetItemsBySkill(new Skill("Final flames", SkillType.Ultimate, "Dernière flamme d'un héro"), + 0, nbItems); + Assert.Equal("Endeavor", items.First().Name); + + items = await manager.GetItemsByCharacteristic("Alter", 0, nbItems); + Assert.Equal("Endeavor", items.First().Name); + + Assert.Equal(2, await manager.GetNbItemsByCharacteristic("Défense")); + } + + } + + [Fact] + public async void Test_Update() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + Champion batman = new("Batman", ChampionClass.Assassin, "icon_1", "image_1", "L'ombre de la nuit"); + Champion endeavor = new("Endeavor", ChampionClass.Tank, "icon_2", "image_2", "Feu brûlant énernel"); + Champion escanor = new("Escanor", ChampionClass.Fighter, "icon_3", "image_3", "1, 2, 3, Soleil"); + + await manager.AddItem(batman); + await manager.AddItem(endeavor); + await manager.AddItem(escanor); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + + var items = await manager.GetItemsByName("E", 0, 3); + Assert.Equal(2, items.Count()); + + var escanor = context.Champion.Where(n => n.Name.Contains("Esc")).First(); + escanor.Class = ChampionClass.Tank; + context.SaveChanges(); + + items = await manager.GetItemsByClass(ChampionClass.Tank, 0, 3); + Assert.Contains("Escanor", items.Select(x => x.Name)); + + Assert.Equal(2, await manager.GetNbItemsByClass(ChampionClass.Tank)); + + } + } + + [Fact] + public async void Test_Delete() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + + Champion batman = new("Batman", ChampionClass.Assassin, "icon_1", "image_1", "L'ombre de la nuit"); + batman.AddSkill(new("Charge", SkillType.Basic, "Coup de base")); + batman.AddSkill(new("Double Saut", SkillType.Basic, "")); + + Champion endeavor = new("Endeavor", ChampionClass.Tank, "icon_2", "image_2", "Feu brûlant énernel"); + endeavor.AddSkill(new("Charge", SkillType.Basic, "Coup de base")); + + Champion escanor = new("Escanor", ChampionClass.Fighter, "icon_3", "image_3", "1, 2, 3, Soleil"); + escanor.AddSkill(new("Charge", SkillType.Basic, "Coup de base")); + batman.AddSkill(new("Double Saut", SkillType.Basic, "")); + + await manager.AddItem(batman); + await manager.AddItem(endeavor); + await manager.AddItem(escanor); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + var endeavor = (await manager.GetItemsByName("Endeavor", 0, 3)).First(); + + var itemsByName = await manager.DeleteItem(endeavor); + Assert.Equal(2, await manager.GetNbItems()); + + var items = await manager.GetItems(0, await manager.GetNbItems()); + Assert.DoesNotContain("Endeavor", items.Select(x => x.Name)); + + Assert.Equal(1, await manager.GetNbItemsBySkill(new Skill("Double Saut", SkillType.Basic, ""))); + Assert.Equal(2, await manager.GetNbItemsBySkill("Charge")); + } + } + } +} \ No newline at end of file diff --git a/Sources/TestEF/TestEF.csproj b/Sources/TestEF/TestEF.csproj new file mode 100644 index 0000000..3152529 --- /dev/null +++ b/Sources/TestEF/TestEF.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/Sources/TestEF/TestRunePages.cs b/Sources/TestEF/TestRunePages.cs new file mode 100644 index 0000000..c44ed44 --- /dev/null +++ b/Sources/TestEF/TestRunePages.cs @@ -0,0 +1,277 @@ +using ManagersEF; +using EntityFrameworkLOL.Entities; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Model; +using Shared; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static Model.RunePage; +using System.Xml.Linq; +using Xunit; +using EntityFrameworkLOL.DBContexts; + +namespace TestEF +{ + public class TestRunePages + { + [Fact] + public async void Test_Add() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunePagesMgr; + var runeManager = new EFManager(context).RunesMgr; + var championManager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + Model.Rune rune1 = new("Sanglante", RuneFamily.Domination); + Model.Rune rune2 = new("Oeil de l'esprit", RuneFamily.Precision); + Model.Rune rune3 = new("Concrétisation", RuneFamily.Unknown); + Model.Rune rune4 = new("The moon", RuneFamily.Unknown); + Model.Rune rune5 = new("Radiance", RuneFamily.Domination); + Model.Rune rune6 = new("Bullseye", RuneFamily.Precision); + + RunePage runepage1 = new("Damages"); + runepage1[Category.Major] = rune1; + runepage1[Category.Minor1] = rune2; + runepage1[Category.Minor2] = rune5; + + RunePage runepage2 = new("Hawk"); + + runepage2[Category.Major] = rune6; + runepage2[Category.Minor1] = rune2; + + RunePage runepage3 = new("Juggler"); + runepage3[Category.Major] = rune5; + runepage3[Category.Minor1] = rune3; + runepage3[Category.Minor2] = rune2; + + await runeManager.AddItem(rune1); + await runeManager.AddItem(rune2); + await runeManager.AddItem(rune3); + await runeManager.AddItem(rune4); + await runeManager.AddItem(rune5); + await runeManager.AddItem(rune6); + + await manager.AddItem(runepage1); + await manager.AddItem(runepage2); + await manager.AddItem(runepage3); + + Champion batman = new("Batman", ChampionClass.Assassin, "icon_1", "image_1", "L'ombre de la nuit"); + Champion endeavor = new("Endeavor", ChampionClass.Tank, "icon_2", "image_2", "Feu brûlant énernel"); + Champion escanor = new("Escanor", ChampionClass.Fighter, "icon_3", "image_3", "1, 2, 3, Soleil"); + + await championManager.AddItem(batman); + await championManager.AddItem(endeavor); + await championManager.AddItem(escanor); + + + var runepage_entities = context.RunePage; + var champion_entities = context.Champion; + + var damages = runepage_entities.Find("Damages"); + var hawk = runepage_entities.Find("Hawk"); + var juggler = runepage_entities.Find("Juggler"); + + champion_entities.Find("Batman")!.RunePages = new List() { hawk, juggler }; + champion_entities.Find("Endeavor")!.RunePages = new List() { damages }; + champion_entities.Find("Escanor")!.RunePages = new List() { damages }; + context.SaveChanges(); + + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunePagesMgr; + var championManager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + Model.Rune rune5 = new("Radiance", RuneFamily.Domination); + Model.Rune rune1 = new("Sanglante", RuneFamily.Domination); + + Champion batman = new("Batman", ChampionClass.Assassin, "icon_1", "image_1", "L'ombre de la nuit"); + Champion endeavor = new("Endeavor", ChampionClass.Tank, "icon_2", "image_2", "Feu brûlant énernel"); + + + var nbItems = await manager.GetNbItems(); + Assert.Equal(3, nbItems); + + var items = await manager.GetItemsByName("Ha", 0, nbItems); + Assert.Equal("Hawk", items.First().Name); + + Assert.Equal(2, await manager.GetNbItemsByName("a")); + + Assert.Equal(1, await manager.GetNbItemsByRune(rune5)); + + items = await manager.GetItemsByRune(rune1, 0, nbItems); + Assert.Equal("Damages", items.First().Name); + + Assert.Equal(2, await manager.GetNbItemsByChampion(batman)); + Assert.Equal("Damages", (await manager.GetItemsByChampion(endeavor, 0, 3)).First()!.Name); + + Assert.Equal(2, await championManager.GetNbItemsByRunePage(new("Damages"))); + Assert.Equal("Batman", (await championManager.GetItemsByRunePage(new("Juggler"), 0, 3)).First()!.Name); + + } + } + + [Fact] + public async void Test_Update() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunePagesMgr; + var runeManager = new EFManager(context).RunesMgr; + + context.Database.EnsureCreated(); + + Model.Rune rune1 = new("Sanglante", RuneFamily.Domination); + Model.Rune rune2 = new("Oeil de l'esprit", RuneFamily.Precision); + Model.Rune rune3 = new("Concrétisation", RuneFamily.Unknown); + Model.Rune rune4 = new("The moon", RuneFamily.Unknown); + Model.Rune rune5 = new("Radiance", RuneFamily.Domination); + Model.Rune rune6 = new("Bullseye", RuneFamily.Precision); + + RunePage runepage1 = new("Damages"); + runepage1[Category.Major] = rune1; + runepage1[Category.Minor1] = rune2; + runepage1[Category.Minor2] = rune5; + + RunePage runepage2 = new("Hawk"); + runepage2[Category.Major] = rune6; + runepage2[Category.Minor1] = rune2; + + RunePage runepage3 = new("Juggler"); + runepage3[Category.Major] = rune5; + runepage3[Category.Minor1] = rune3; + runepage3[Category.Minor2] = rune2; + + await runeManager.AddItem(rune1); + await runeManager.AddItem(rune2); + await runeManager.AddItem(rune3); + await runeManager.AddItem(rune4); + await runeManager.AddItem(rune5); + await runeManager.AddItem(rune6); + + await manager.AddItem(runepage1); + await manager.AddItem(runepage2); + await manager.AddItem(runepage3); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunePagesMgr; + Model.Rune rune1 = new("Sanglante", RuneFamily.Domination); + Model.Rune rune6 = new("Bullseye", RuneFamily.Precision); + + context.Database.EnsureCreated(); + + Assert.Equal(1, await manager.GetNbItemsByRune(rune1)); + Assert.Equal(1, await manager.GetNbItemsByRune(rune6)); + + RunePage after = new("Hawk"); + after[Category.Major] = rune1; + + await manager.UpdateItem(new("Hawk"), after); + + Assert.Equal(2, await manager.GetNbItemsByRune(rune1)); + Assert.Equal(0, await manager.GetNbItemsByRune(rune6)); + + context.SaveChanges(); + } + } + + [Fact] + public async void Test_Delete() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunePagesMgr; + var runeManager = new EFManager(context).RunesMgr; + + context.Database.EnsureCreated(); + + Model.Rune rune1 = new("Sanglante", RuneFamily.Domination); + Model.Rune rune2 = new("Oeil de l'esprit", RuneFamily.Precision); + Model.Rune rune3 = new("Concrétisation", RuneFamily.Unknown); + Model.Rune rune4 = new("The moon", RuneFamily.Unknown); + Model.Rune rune5 = new("Radiance", RuneFamily.Domination); + Model.Rune rune6 = new("Bullseye", RuneFamily.Precision); + + RunePage runepage1 = new("Damages"); + runepage1[Category.Major] = rune1; + runepage1[Category.Minor1] = rune2; + runepage1[Category.Minor2] = rune5; + + RunePage runepage2 = new("Hawk"); + + runepage2[Category.Major] = rune6; + runepage2[Category.Minor1] = rune2; + + RunePage runepage3 = new("Juggler"); + runepage3[Category.Major] = rune5; + runepage3[Category.Minor1] = rune3; + runepage3[Category.Minor2] = rune2; + + await runeManager.AddItem(rune1); + await runeManager.AddItem(rune2); + await runeManager.AddItem(rune3); + await runeManager.AddItem(rune4); + await runeManager.AddItem(rune5); + await runeManager.AddItem(rune6); + + await manager.AddItem(runepage1); + await manager.AddItem(runepage2); + await manager.AddItem(runepage3); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunePagesMgr; + + Model.Rune rune2 = new("Oeil de l'esprit", RuneFamily.Precision); + + + context.Database.EnsureCreated(); + + Assert.Equal(3, await manager.GetNbItems()); + + await manager.DeleteItem(new("Juggler")); + + Assert.Equal(2, await manager.GetNbItems()); + + Assert.Equal(1, await manager.GetNbItemsByName("e")); + + Assert.Equal(1, await manager.GetNbItemsByRune(rune2)); + } + } + } +} diff --git a/Sources/TestEF/TestRunes.cs b/Sources/TestEF/TestRunes.cs new file mode 100644 index 0000000..f9c54f8 --- /dev/null +++ b/Sources/TestEF/TestRunes.cs @@ -0,0 +1,154 @@ +using ManagersEF; +using EntityFrameworkLOL.Entities; +using EntityFrameworkLOL.DBContexts; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Model; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using Xunit; + +namespace TestEF +{ + public class TestRunes + { + + [Fact] + public async void Test_Add() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunesMgr; + + context.Database.EnsureCreated(); + + Model.Rune rune1 = new("Sanglante", RuneFamily.Domination); + Model.Rune rune2 = new("Oeil de l'esprit", RuneFamily.Precision); + Model.Rune rune3 = new("Concrétisation", RuneFamily.Unknown); + + await manager.AddItem(rune1); + await manager.AddItem(rune2); + await manager.AddItem(rune3); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunesMgr; + + context.Database.EnsureCreated(); + + var nbItems = await manager.GetNbItems(); + Assert.Equal(3, nbItems); + + var items = await manager.GetItemsByName("Sanglante", 0, nbItems); + Assert.Equal("Sanglante", items.First().Name); + + Assert.Equal(1, await manager.GetNbItemsByName("Concrétisation")); + + items = await manager.GetItemsByFamily(RuneFamily.Precision, 0, nbItems); + Assert.Equal("Oeil de l'esprit", items.First().Name); + + Assert.Equal(1, await manager.GetNbItemsByFamily(RuneFamily.Unknown)); + } + } + + + [Fact] + public async void Test_Update() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunesMgr; + + context.Database.EnsureCreated(); + + + Model.Rune rune1 = new("Sanglante", RuneFamily.Domination); + Model.Rune rune2 = new("Oeil de l'esprit", RuneFamily.Precision); + Model.Rune rune3 = new("Concrétisation", RuneFamily.Unknown); + + await manager.AddItem(rune1); + await manager.AddItem(rune2); + await manager.AddItem(rune3); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunesMgr; + + context.Database.EnsureCreated(); + + Assert.Equal(1, await manager.GetNbItemsByFamily(RuneFamily.Precision)); + + Model.Rune before = new("Concrétisation", RuneFamily.Unknown); + Model.Rune after = new("Concrétisation", RuneFamily.Precision); + + await manager.UpdateItem(before, after); + + Assert.Equal(2, await manager.GetNbItemsByFamily(RuneFamily.Precision)); + + context.SaveChanges(); + } + } + + [Fact] + public async void Test_Delete() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunesMgr; + + context.Database.EnsureCreated(); + + Model.Rune rune1 = new("Sanglante", RuneFamily.Domination); + Model.Rune rune2 = new("Oeil de l'esprit", RuneFamily.Precision); + Model.Rune rune3 = new("Concrétisation", RuneFamily.Unknown); + + await manager.AddItem(rune1); + await manager.AddItem(rune2); + await manager.AddItem(rune3); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).RunesMgr; + + context.Database.EnsureCreated(); + + Assert.Equal(3, await manager.GetNbItems()); + + await manager.DeleteItem(new("Concrétisation", RuneFamily.Unknown)); + + Assert.Equal(2, await manager.GetNbItems()); + + Assert.Equal(0, await manager.GetNbItemsByName("Concrétisation")); + } + } + } +} \ No newline at end of file diff --git a/Sources/TestEF/TestSkins.cs b/Sources/TestEF/TestSkins.cs new file mode 100644 index 0000000..04789fe --- /dev/null +++ b/Sources/TestEF/TestSkins.cs @@ -0,0 +1,182 @@ +using ManagersEF; +using EntityFrameworkLOL.Entities; +using EntityFrameworkLOL.DBContexts; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Model; +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using Xunit; + +namespace TestEF +{ + public class TestSkins + { + [Fact] + public async void Test_Add() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).SkinsMgr; + var championManager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + Champion batman = new("Batman", ChampionClass.Assassin); + Champion endeavor = new("Endeavor", ChampionClass.Tank); + await championManager.AddItem(batman); + await championManager.AddItem(endeavor); + + Skin batman_skin_1 = new("Batman de glace", batman); + Skin batman_skin_2 = new("Batman gold", batman); + Skin batman_skin_3 = new("L'homme araignée", batman); + Skin endeavor_skin_1 = new("L'abominable Endeavor", endeavor); + + await manager.AddItem(batman_skin_1); + await manager.AddItem(batman_skin_2); + await manager.AddItem(batman_skin_3); + await manager.AddItem(endeavor_skin_1); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).SkinsMgr; + + context.Database.EnsureCreated(); + + var nbItems = await manager.GetNbItems(); + Assert.Equal(4, nbItems); + Assert.Equal(4, (await manager.GetItems(0, nbItems)).Count()); + + var items = await manager.GetItemsByName("Batman", 0, nbItems); + Assert.Equal(2, items.Count()); + + Champion batman = new("Batman", ChampionClass.Assassin); + items = await manager.GetItemsByChampion(batman, 0, nbItems); + Assert.Equal(3, items.Count()); + } + + } + + [Fact] + public async void Test_Update() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).SkinsMgr; + var championManager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + Champion batman = new("Batman", ChampionClass.Assassin); + Champion endeavor = new("Endeavor", ChampionClass.Tank); + await championManager.AddItem(batman); + await championManager.AddItem(endeavor); + + Skin batman_skin_1 = new("Batman de glace", batman); + Skin batman_skin_2 = new("Batman gold", batman); + Skin batman_skin_3 = new("L'homme araignée", batman); + Skin endeavor_skin_1 = new("L'abominable Endeavor", endeavor); + + await manager.AddItem(batman_skin_1); + await manager.AddItem(batman_skin_2); + await manager.AddItem(batman_skin_3); + await manager.AddItem(endeavor_skin_1); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).SkinsMgr; + + context.Database.EnsureCreated(); + + + Champion batman = new("Batman", ChampionClass.Assassin); + Champion endeavor = new("Endeavor", ChampionClass.Tank); + + var itemsByName = await manager.GetItemsByChampion(batman, 0, 4); + Assert.Equal(3, itemsByName.Count()); + + Skin batman_skin = new("L'homme araignée", batman); + Skin endeavor_skin = new("L'homme araignée", endeavor); + + await manager.UpdateItem(batman_skin, endeavor_skin); + + itemsByName = await manager.GetItemsByChampion(batman, 0, 4); + Assert.Equal(2, itemsByName.Count()); + + context.SaveChanges(); + } + } + + [Fact] + public async void Test_Delete() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).SkinsMgr; + var championManager = new EFManager(context).ChampionsMgr; + + context.Database.EnsureCreated(); + + Champion batman = new("Batman", ChampionClass.Assassin); + Champion endeavor = new("Endeavor", ChampionClass.Tank); + await championManager.AddItem(batman); + await championManager.AddItem(endeavor); + + Skin batman_skin_1 = new("Batman de glace", batman); + Skin batman_skin_2 = new("Batman gold", batman); + Skin batman_skin_3 = new("L'homme araignée", batman); + Skin endeavor_skin_1 = new("L'abominable Endeavor", endeavor); + + await manager.AddItem(batman_skin_1); + await manager.AddItem(batman_skin_2); + await manager.AddItem(batman_skin_3); + await manager.AddItem(endeavor_skin_1); + } + + using (var context = new SQLiteContext(options)) + { + var manager = new EFManager(context).SkinsMgr; + + context.Database.EnsureCreated(); + + await manager.DeleteItem((await manager.GetItemsByName("L'", 0, 4)).First()); + await manager.DeleteItem((await manager.GetItemsByName("L'", 0, 3)).First()); + + Assert.Equal(2, await manager.GetNbItems()); + + Assert.Equal(2, await manager.GetNbItemsByName("Batman")); + + Champion batman = new("Batman", ChampionClass.Assassin); + Assert.Equal(2, await manager.GetNbItemsByChampion(batman)); + } + } + } +} \ No newline at end of file diff --git a/Sources/TestUnitaire/TestUnitaire.csproj b/Sources/TestUnitaire/TestUnitaire.csproj index f3e7145..ddaeab6 100644 --- a/Sources/TestUnitaire/TestUnitaire.csproj +++ b/Sources/TestUnitaire/TestUnitaire.csproj @@ -14,6 +14,8 @@ + + diff --git a/Sources/Tests/ConsoleTests/ConsoleTests.csproj b/Sources/Tests/ConsoleTests/ConsoleTests.csproj index c805564..c165d20 100644 --- a/Sources/Tests/ConsoleTests/ConsoleTests.csproj +++ b/Sources/Tests/ConsoleTests/ConsoleTests.csproj @@ -23,5 +23,7 @@ + + diff --git a/Sources/TestsEF/Controllers/WeatherForecastController.cs b/Sources/TestsEF/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..3887f40 --- /dev/null +++ b/Sources/TestsEF/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace TestsEF.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} \ No newline at end of file diff --git a/Sources/TestsEF/Program.cs b/Sources/TestsEF/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/Sources/TestsEF/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Sources/TestsEF/Properties/launchSettings.json b/Sources/TestsEF/Properties/launchSettings.json new file mode 100644 index 0000000..f502d8f --- /dev/null +++ b/Sources/TestsEF/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:59431", + "sslPort": 44385 + } + }, + "profiles": { + "TestsEF": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7027;http://localhost:5041", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Sources/TestsEF/TestsEF.csproj b/Sources/TestsEF/TestsEF.csproj new file mode 100644 index 0000000..60bf9ea --- /dev/null +++ b/Sources/TestsEF/TestsEF.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Sources/TestsEF/WeatherForecast.cs b/Sources/TestsEF/WeatherForecast.cs new file mode 100644 index 0000000..4f2305e --- /dev/null +++ b/Sources/TestsEF/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace TestsEF +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} \ No newline at end of file diff --git a/Sources/TestsEF/appsettings.Development.json b/Sources/TestsEF/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Sources/TestsEF/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Sources/TestsEF/appsettings.json b/Sources/TestsEF/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Sources/TestsEF/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}