diff --git a/Sources/BddTests/Program.cs b/Sources/BddTests/Program.cs index fd35a44..afd7f7a 100644 --- a/Sources/BddTests/Program.cs +++ b/Sources/BddTests/Program.cs @@ -14,8 +14,8 @@ var dataMgr = new DataBdd(); List list = dataMgr.ChampionsMgr.GetItems(0, dataMgr.ChampionsMgr.GetNbItems().Result).Result.ToList(); -/* -ChampionContext data = new ChampionContext(); + +/*ChampionContext data = new ChampionContext(); data.Champs.ToList(); List l = data.listChampions();*/ diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index af69a48..9387f8a 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -35,6 +35,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiDePaul", "ApiDePaul\ApiD {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsTresImportants", "TestsTresImportants\TestsTresImportants.csproj", "{4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -73,6 +75,10 @@ Global {245F7BAC-8487-4510-8066-D12B5B2B816B}.Debug|Any CPU.Build.0 = Debug|Any CPU {245F7BAC-8487-4510-8066-D12B5B2B816B}.Release|Any CPU.ActiveCfg = Release|Any CPU {245F7BAC-8487-4510-8066-D12B5B2B816B}.Release|Any CPU.Build.0 = Release|Any CPU + {4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4982C56F-3FB0-4BD0-AE03-CB157F9CAEF8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/Model2/ChampionContext.cs b/Sources/Model2/ChampionContext.cs index f683cd2..3e9419d 100644 --- a/Sources/Model2/ChampionContext.cs +++ b/Sources/Model2/ChampionContext.cs @@ -8,15 +8,16 @@ namespace LibEntityFramework { public class ChampionContext : DbContext { + public ChampionContext() { } + public ChampionContext(DbContextOptions options) : base(options) { } public DbSet Champs { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder options) { - /*if (!options.IsConfigured) + if (!options.IsConfigured) { options.UseSqlite("DataSource=laBdd.db"); - } */ - options.UseSqlite("DataSource=laBdd.db"); + } } } } diff --git a/Sources/TestsTresImportants/TestsTresImportants.csproj b/Sources/TestsTresImportants/TestsTresImportants.csproj new file mode 100644 index 0000000..f3c8e8b --- /dev/null +++ b/Sources/TestsTresImportants/TestsTresImportants.csproj @@ -0,0 +1,30 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + diff --git a/Sources/TestsTresImportants/UTestsChampion.cs b/Sources/TestsTresImportants/UTestsChampion.cs new file mode 100644 index 0000000..66b3891 --- /dev/null +++ b/Sources/TestsTresImportants/UTestsChampion.cs @@ -0,0 +1,43 @@ +using LibEntityFramework; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; +using Model; +using TrucAuMilieu; + +namespace TestsTresImportants +{ + public class UTestsChampion + { + [Fact] + public void Test() + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new ChampionContext(options)) + { + context.Database.EnsureCreated(); + + Champion c1 = new Champion("Joe"); + Champion c2 = new Champion("Billy"); + Champion c3 = new Champion("Robert"); + + context.Champs.Add(c1.ChampToEf()); + context.Champs.Add(c2.ChampToEf()); + context.Champs.Add(c3.ChampToEf()); + context.SaveChanges(); + } + using(var context= new ChampionContext(options)) + { + context.Database.EnsureCreated(); + Assert.Equal(3, context.Champs.Count()); + Assert.Equal("Joe", context.Champs.First().Name); + } + + } + } +} \ No newline at end of file diff --git a/Sources/TestsTresImportants/Usings.cs b/Sources/TestsTresImportants/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/Sources/TestsTresImportants/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/Sources/TrucAuMilieu/DataBdd.Champions.cs b/Sources/TrucAuMilieu/DataBdd.Champions.cs index 394f6aa..02f087c 100644 --- a/Sources/TrucAuMilieu/DataBdd.Champions.cs +++ b/Sources/TrucAuMilieu/DataBdd.Champions.cs @@ -33,29 +33,25 @@ namespace TrucAuMilieu public async Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { - if (descending) + if (orderingPropertyName != null) { - return await Task.FromResult(parent.contextCh.Champs.OrderByDescending(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp())); + if (descending) + { + return await Task.FromResult(parent.contextCh.Champs.OrderByDescending(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp())); + } + else + { + var pap = await Task.FromResult(parent.contextCh.Champs.OrderBy(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp())); + return pap; + //ya une petite betise ça marche pas trop menfin bref c'est a corriger + } } else - { - var hi = parent.contextCh.Champs.OrderBy(c => typeof(ChampionEntity).GetProperty(orderingPropertyName)).Skip(index * count).Take(count).Select(ce => ce.EfToChamp()); - return Task.FromResult(hi); //ya une petite betise ça marche pas trop menfin bref c'est a corriger + { + var pap2= await Task.FromResult(parent.contextCh.Champs.Skip(index*count).Take(count).Select(ce => ce.EfToChamp())); + return pap2; } - } - /* - => parent.contextCh.Champs.Take(count).Skip(index). /* - => parent.contextCh..GetItemsWithFilterAndOrdering( - c => true, - index, count, - orderingPropertyName, descending); - {// hihihi les arguments servent à rien pour l'instant y'a zero arguments utilises oupsi - List lch = parent.contextCh.Champs.Take(count).Skip(index).ToList(); - List items = new List(); - foreach (var c in lch) { items.Add(c.EfToChamp()); } - return items; - }*/ public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) {