diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index b397831..96adf52 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -139,7 +139,7 @@ namespace API_LoL.Controllers else { var champ = await ChampionsManager.GetItemsByName(champion.Name, 0, 1); - if(champ.FirstOrDefault().Name == champion.Name) + if(champ.Count() != 0 && champ.FirstOrDefault().Name == champion.Name) { return Conflict(champion); } diff --git a/Sources/API_LoL/champion.db-shm b/Sources/API_LoL/champion.db-shm deleted file mode 100644 index bc92bf7..0000000 Binary files a/Sources/API_LoL/champion.db-shm and /dev/null differ diff --git a/Sources/API_LoL/champion.db-wal b/Sources/API_LoL/champion.db-wal deleted file mode 100644 index 8456db7..0000000 Binary files a/Sources/API_LoL/champion.db-wal and /dev/null differ diff --git a/Sources/Api_UT/ChampionControllerTest.cs b/Sources/Api_UT/ChampionControllerTest.cs index 787899f..09c7875 100644 --- a/Sources/Api_UT/ChampionControllerTest.cs +++ b/Sources/Api_UT/ChampionControllerTest.cs @@ -76,9 +76,11 @@ namespace Api_UT { ChampionsController api = new ChampionsController(new StubData()); IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin","")); + var action = (CreatedAtActionResult)a; + var champAction = action.Value as IEnumerable; Assert.IsNotNull(a); ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin", ""); - Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value)); + Assert.IsTrue(champ.equals(other: (ChampionDTO)((CreatedAtActionResult)a).Value)); } } diff --git a/Sources/EF_UT/EFDataManagerChampionTest.cs b/Sources/EF_UT/EFDataManagerChampionTest.cs index 80f34af..07e3ca2 100644 --- a/Sources/EF_UT/EFDataManagerChampionTest.cs +++ b/Sources/EF_UT/EFDataManagerChampionTest.cs @@ -2,7 +2,9 @@ using EntityFramework.Manager; using FluentAssertions; using FluentAssertions.Primitives; +using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; using Model; using System; using System.Collections.Generic; @@ -24,16 +26,28 @@ namespace EF_UT var champ = championsManager.AddItem(new Champion("test")); } - //[TestMethod] - //public async Task GetItemsByName_DefaultChamp_One() - //{ - // IDataManager dataManager = new EFDataManager(); - // IChampionsManager championsManager = dataManager.ChampionsMgr; - - // var ak = (await championsManager.GetItemsByName("A",0,1)).First(); - - // Assert.IsNotNull(ak); - // //Assert.AreEqual("Akali", ak.Name); - //} + [TestMethod] + public async Task GetItemsByName_DefaultChamp_One() + { + var builder = WebApplication.CreateBuilder(); + + builder.Services.AddDbContext(); + + var app = builder.Build(); + + using (var scope = app.Services.CreateScope()) + { + var context = scope.ServiceProvider.GetService(); + context.Database.EnsureCreated(); + } + + IDataManager dataManager = new EFDataManager(); + IChampionsManager championsManager = dataManager.ChampionsMgr; + + var ak = (await championsManager.GetItemsByName("A", 0, 1)).First(); + + Assert.IsNotNull(ak); + //Assert.AreEqual("Akali", ak.Name); + } } }