From 6ea4c2733e60625a3288d30a537751a6f7b0483e Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Wed, 22 Feb 2023 17:35:11 +0100 Subject: [PATCH 1/6] Create new Class --- .vs/LolProject/v17/.suo | Bin 13824 -> 12800 bytes .../Sources/MyFlib/DataBase.db | Bin 24576 -> 24576 bytes .../Sources/MyFlib/Entities/ChampionEntity.cs | 8 +++-- .../MyFlib/Entities/LargeImageEntity.cs | 16 ++++++++++ .../Sources/MyFlib/Entities/SkillEntity.cs | 24 ++++++++++++++ .../Sources/MyFlib/Entities/SkinEntity.cs | 25 +++++++++++++++ .../enums/ChampionClassEntity.cs | 0 .../MyFlib/Entities/enums/SkillTypeEntity.cs | 16 ++++++++++ .../Sources/MyFlib/LolDbContext.cs | 30 ++++++++++++++---- .../Sources/MyFlib/Program.cs | 11 +++++-- .../Sources/Tests/UT_EF/ChampionsTest.cs | 6 +++- 11 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs rename src/EntityFramework_LoL/Sources/MyFlib/{ => Entities}/enums/ChampionClassEntity.cs (100%) create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/SkillTypeEntity.cs diff --git a/.vs/LolProject/v17/.suo b/.vs/LolProject/v17/.suo index cb24cbd2ddbc7d4364303b162eecfeb1a9ccf79e..d1429b741d17900fbbefb3831fac48667ed298ac 100644 GIT binary patch delta 1096 zcmZq3X-L`N!^FrwS&>Pevq0Yc#A&yijAD~Zna)ic z4+N7LB~>PWVb*Zr1`7NG3J60b1b{RL5c5F!AjN_}HZPP9QVRp(Krv1r-Wa%maT1dc z)CCP!U5Ix9yNU-F)MSvUd_cAklrIXTL9PJV2(uleh94>qVuR$6U9pMFgM|a+B#^$lYfeO^DqNhvQT9ZC1U4!89|8+l+X|w#r=7~i5-*?V4{gKkCW zoQ3`Xe}I~Gv7#Wj(26TJuKWcuLbIvfGjm5KT}T%lINW=`bMN`icg~sKYH$5jQy^ZL z6i$!rt-XEuW9&ekZi2tWJzinNR_9JhG! zCjZ>@Z^rAA*Gbw^Lwzm9gE5^rwnkqIY7^JsvH!Y^VJ0{UI*rQ`?EBlt5QfaaAli_z zaE=-~r&wE-I3u##DaBd}L6M>>7odqf83m@?;GD{Omu$)>7?^ZBdZ$?G$tHXdRG_J+ zM(&2CF5|vKb6*sz(BUEU+%0d~1sD;DL|_p7WDScdNd5g#NI0Xflyz;kR8Y&EPNAY# zwZih1Qn{e5RA+U)qgG}r9VkS<8QA~?aupfJ<%r}sKu#?DWAoKD6RLPo^tKF}LwYOWu{yPle2(YIj#h9?2LwZd_ zu?j;Iz^l+VFUrKo*P$*>0nM_T#~|ub!|I#6AwWZR)vZC83X|Z%^g@wpUE0+sz4u_P e+eHcex#F(qTh;XC&2@T*-ruN}r~AI*FYzz-aLTj* diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db index 2553478a6f1132b671abf415c17cf66a8a22b24f..f1405c5c7719449496b283a6c631ae5013545dc4 100644 GIT binary patch delta 515 zcma)&F;Buk7>0WkC^fW&2q6IngA5EFxx4n-YfOx7xrPPe!c2$~WdIV;860#*om~9` z#`F&`8jUM)cJ@bjP24n*FL}228J=&k0*e(`R`OLzlG1|Y54*SfW~wSRYK!O7oh(R4 zSJ_qq$kD3~!FD{#2qaAajJ0H}qkQhoIFRZv*DJP0U8js+>BA+&sCL!Sf~a?fNa#FouGuGZx) zusII6M+4}ZmMexXg3LxP=u}%CjAst|-+*_vN&_ z3bgoUwV48$_|1Y~EeT~MiYWp1La`Td&Uv+GEt78nRTKy!6cNNRryh2X2iN=kvtj45 ze{t?rQI#aBoMcT(lHApP78n~9RT%&K_pN;T(dt=D=8M*t7<#*8nx^4L#Alcj=!t+q z=0-mB5$DkL>H(U6;m`@?A7kM4}G^jyW5FU6nk46DH=!~vLnfU#Pf~P&lS&`ov s)>N@R?GO9ezKfmBTWh>TU1M8qFV!)d1b Skills { get; set; } } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs new file mode 100644 index 0000000..8492da0 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + public class LargeImageEntity + { + [Key] + public string Base64 { get; set; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs new file mode 100644 index 0000000..fa87c23 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + public class SkillEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + + [Required] + [MaxLength(500)] + public string Description { get; set; } + + [Required] + public SkillTypeEntity Type { get; set; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs new file mode 100644 index 0000000..772e162 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + public class SkinEntity + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + [Required] + [MaxLength(500)] + public string Description { get; set; } + [Required] + public string Icon { get; set; } + [Required] + public float Price { get; set; } + public LargeImageEntity Image { get; set; } + + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/enums/ChampionClassEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/ChampionClassEntity.cs similarity index 100% rename from src/EntityFramework_LoL/Sources/MyFlib/enums/ChampionClassEntity.cs rename to src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/ChampionClassEntity.cs diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/SkillTypeEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/SkillTypeEntity.cs new file mode 100644 index 0000000..73c36e5 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/SkillTypeEntity.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + public enum SkillTypeEntity + { + Unknown, + Basic, + Passive, + Ultimate + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index 5ff7132..abe8c71 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -10,6 +10,9 @@ namespace MyFlib public class LolDbContext : DbContext { public DbSet Champions { get; set; } + public DbSet Skills { get; set; } + public DbSet Skins { get; set; } + public DbSet Images { get; set; } public LolDbContext() { } @@ -28,12 +31,27 @@ namespace MyFlib modelBuilder.Entity().HasKey(e => e.Id); modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); modelBuilder.Entity().HasData( - new ChampionEntity { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = "" } + new ChampionEntity { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, + new ChampionEntity { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } } + ); + + modelBuilder.Entity().HasData( + new SkillEntity { Name = "Boule de feu", Description = "Fire!", Type = SkillTypeEntity.Basic }, + new SkillEntity { Name = "White Star", Description = "Random damage", Type = SkillTypeEntity.Ultimate } + ); + + modelBuilder.Entity().HasData( + new LargeImageEntity { Base64 = "empty" }, + new LargeImageEntity { Base64 = "empty2" } + ); + + modelBuilder.Entity().HasData( + new SkinEntity { Name = "Yone fleur spirituelle", Description = "Spirit Blossom", Icon = "empty", Price = 975, Image = new LargeImageEntity { Base64 = "empty" } }, + new SkinEntity { Name = "Yasuo Lune de sang", Description = "Blood Moon", Icon = "empty", Price = 975, Image = new LargeImageEntity { Base64 = "empty" } } ); } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Program.cs b/src/EntityFramework_LoL/Sources/MyFlib/Program.cs index 0da5a3c..00d8f3d 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Program.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Program.cs @@ -1,20 +1,25 @@ // See https://aka.ms/new-console-template for more information using MyFlib; +using static System.Console; using (var context = new LolDbContext()) { foreach (var c in context.Champions) { - Console.WriteLine($"{c.Name} - {c.Class}"); + WriteLine($"{c.Name} - {c.Class}"); } - Console.WriteLine("\nWith new Champions :\n"); + WriteLine("\nWith new Champions :\n"); DataSeeder.SeedData(context); foreach (var c in context.Champions) { - Console.WriteLine($"{c.Name} - {c.Class}"); + WriteLine($"{c.Name} - {c.Class}"); + foreach (var s in c.Skills) + { + WriteLine($"\t\t{s.Name} - {s.Description}"); + } } context.SaveChangesAsync(); // or context.SaveChangesAsync diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs index fd66059..ed24a8f 100644 --- a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs @@ -19,7 +19,11 @@ namespace UT_EF ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }; ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; - context.Champions.AddRange(sylas, hecarim, yuumi); + // test contrainte + ChampionEntity errorName = new ChampionEntity { Name = "c1832f35-f909-422d-a1fb-e0b79a62f562-fa7c5fe2-89b7-432e-9e0f-a5736445b381-3f75c0f8-de2e-4cf4-82d2-3d24411f6422-6b7e9196-3664-4813-b971-e9cc08a4b255-c1832f35-f909-422d-a1fb-e0b79a62f562-fa7c5fe2-89b7-432e-9e0f-a5736445b381-3f75c0f8-de2e-4cf4-82d2-3d24411f6422-6b7e9196-3664-4813-b971-e9cc08a4b255" + , Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; + + context.Champions.AddRange(sylas, hecarim, yuumi, errorName); context.SaveChanges(); } From 315229112056ec6dd568fab3921ec537a6ba3885 Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Wed, 1 Mar 2023 14:30:28 +0100 Subject: [PATCH 2/6] Correct error --- .../Sources/MyFlib/Entities/ChampionEntity.cs | 2 +- .../MyFlib/Entities/LargeImageEntity.cs | 2 ++ .../Sources/MyFlib/LolDbContext.cs | 35 ++++++++++--------- .../Sources/Tests/UT_EF/ChampionsTest.cs | 6 +--- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs index 166bf36..a7755f7 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs @@ -20,7 +20,7 @@ namespace MyFlib [MaxLength(255)] public string Bio { get; set; } public string Icon { get; set; } - public LargeImageEntity Image { get; set; } + public string Image { get; set; } [Required] public ChampionClassEntity Class { get; set; } public ICollection Skills { get; set; } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs index 8492da0..6fa04cf 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs @@ -9,7 +9,9 @@ namespace MyFlib { public class LargeImageEntity { + [Key] + public int ImageId { get; set; } public string Base64 { get; set; } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index abe8c71..e507575 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -10,9 +10,8 @@ namespace MyFlib public class LolDbContext : DbContext { public DbSet Champions { get; set; } - public DbSet Skills { get; set; } + public DbSet Skills { get; set; } public DbSet Skins { get; set; } - public DbSet Images { get; set; } public LolDbContext() { } @@ -28,30 +27,32 @@ namespace MyFlib } protected override void OnModelCreating(ModelBuilder modelBuilder) { + var image1 = new LargeImageEntity { ImageId = 1, Base64 = "image1" }; + var image2 = new LargeImageEntity { ImageId = 2, Base64 = "image2" }; + + modelBuilder.Entity().HasData(image1, image2); + + modelBuilder.Entity().Property("ImageId"); + modelBuilder.Entity().HasKey(e => e.Id); modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); modelBuilder.Entity().HasData( - new ChampionEntity { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, - new ChampionEntity { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, - new ChampionEntity { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, - new ChampionEntity { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, - new ChampionEntity { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } }, - new ChampionEntity { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = new LargeImageEntity { Base64 = "empty" } } + new { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "empty" }, + new { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "empty" }, + new { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "empty" }, + new { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = "empty" }, + new { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", Image = "empty" }, + new { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = "empty" } ); modelBuilder.Entity().HasData( - new SkillEntity { Name = "Boule de feu", Description = "Fire!", Type = SkillTypeEntity.Basic }, - new SkillEntity { Name = "White Star", Description = "Random damage", Type = SkillTypeEntity.Ultimate } - ); - - modelBuilder.Entity().HasData( - new LargeImageEntity { Base64 = "empty" }, - new LargeImageEntity { Base64 = "empty2" } + new { Name = "Boule de feu", Description = "Fire!", Type = SkillTypeEntity.Basic }, + new { Name = "White Star", Description = "Random damage", Type = SkillTypeEntity.Ultimate } ); modelBuilder.Entity().HasData( - new SkinEntity { Name = "Yone fleur spirituelle", Description = "Spirit Blossom", Icon = "empty", Price = 975, Image = new LargeImageEntity { Base64 = "empty" } }, - new SkinEntity { Name = "Yasuo Lune de sang", Description = "Blood Moon", Icon = "empty", Price = 975, Image = new LargeImageEntity { Base64 = "empty" } } + new SkinEntity { Name = "Yone fleur spirituelle", Description = "Spirit Blossom", Icon = "empty", Price = 975, ImageId = 1 }, + new SkinEntity { Name = "Yasuo Lune de sang", Description = "Blood Moon", Icon = "empty", Price = 975, ImageId = 2 } ); } diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs index ed24a8f..fd66059 100644 --- a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs @@ -19,11 +19,7 @@ namespace UT_EF ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }; ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; - // test contrainte - ChampionEntity errorName = new ChampionEntity { Name = "c1832f35-f909-422d-a1fb-e0b79a62f562-fa7c5fe2-89b7-432e-9e0f-a5736445b381-3f75c0f8-de2e-4cf4-82d2-3d24411f6422-6b7e9196-3664-4813-b971-e9cc08a4b255-c1832f35-f909-422d-a1fb-e0b79a62f562-fa7c5fe2-89b7-432e-9e0f-a5736445b381-3f75c0f8-de2e-4cf4-82d2-3d24411f6422-6b7e9196-3664-4813-b971-e9cc08a4b255" - , Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; - - context.Champions.AddRange(sylas, hecarim, yuumi, errorName); + context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); } From 854129fe139b636c0922da24de6a658b5a58804c Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Wed, 1 Mar 2023 17:41:50 +0100 Subject: [PATCH 3/6] Add new Entity and relation (Foreign Key) --- .../Mapper/enums/ChampionClassMapper.cs | 69 +++++++++++++++++- .../Sources/MyFlib/DataBase.db | Bin 24576 -> 57344 bytes .../Sources/MyFlib/DataSeeder.cs | 10 ++- .../Sources/MyFlib/Entities/ChampionEntity.cs | 5 +- .../MyFlib/Entities/LargeImageEntity.cs | 2 +- .../Sources/MyFlib/Entities/Rune.cs | 26 +++++++ .../Sources/MyFlib/Entities/SkinEntity.cs | 4 + .../MyFlib/Entities/enums/RuneFamilyEntity.cs | 15 ++++ .../Sources/MyFlib/LolDbContext.cs | 19 +++-- .../Sources/Tests/UT_EF/ChampionsTest.cs | 30 +++++--- 10 files changed, 152 insertions(+), 28 deletions(-) create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs index c0c52ed..9f4d332 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/enums/ChampionClassMapper.cs @@ -7,11 +7,74 @@ namespace ApiLol.Mapper { public static ChampionClassDto ToDto(this ChampionClass championClass) { - return (ChampionClassDto) championClass; + if (championClass == ChampionClass.Unknown) + { + return ChampionClassDto.Unknown; + } + if (championClass == ChampionClass.Assassin) + { + return ChampionClassDto.Assassin; + } + if (championClass == ChampionClass.Fighter) + { + return ChampionClassDto.Fighter; + } + if (championClass == ChampionClass.Mage) + { + return ChampionClassDto.Mage; + } + if (championClass == ChampionClass.Marksman) + { + return ChampionClassDto.Marksman; + } + if (championClass == ChampionClass.Support) + { + return ChampionClassDto.Support; + } + if (championClass == ChampionClass.Tank) + { + return ChampionClassDto.Tank; + } + else + { + return ChampionClassDto.Unknown; + } + } public static ChampionClass ToModel(this ChampionClassDto championClass) - { - return (ChampionClass) championClass; + { + if (championClass == ChampionClassDto.Unknown) + { + return ChampionClass.Unknown; + } + if (championClass == ChampionClassDto.Assassin) + { + return ChampionClass.Assassin; + } + if (championClass == ChampionClassDto.Fighter) + { + return ChampionClass.Fighter; + } + if (championClass == ChampionClassDto.Mage) + { + return ChampionClass.Mage; + } + if (championClass == ChampionClassDto.Marksman) + { + return ChampionClass.Marksman; + } + if (championClass == ChampionClassDto.Support) + { + return ChampionClass.Support; + } + if (championClass == ChampionClassDto.Tank) + { + return ChampionClass.Tank; + } + else + { + return ChampionClass.Unknown; + } } } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db index f1405c5c7719449496b283a6c631ae5013545dc4..9ff30fad1af2ff6c5cb16e904d7019574d8ff427 100644 GIT binary patch literal 57344 zcmeI*Pi))P9S3keQld;dGIvP{ujoPxD;h6lK#`PbVHh@wB0H^$?8)*L9}0o98Aq%B zxS|Bq*k#Gu9d_QZbAerlU6=Dt#Rdc@cGzK;ZaWk`^^_LaFzh`_l&wGZydFBo{W5rx zNWS;@-skryhfkut`~7Nb5ULM){Z24YP3|ikA>4OVmE*V~O{+9zXhraWFg6m z3!aPI-LL;Nn|;Cw*&{A{wEBVk+sr%j|1PKjyC47o2tWV=*Hj?;B>i_yAt$ZwVfc3C zeslNDRyS%^I>Av`IgD3U-MZ&AJhf6Qd-v7cY@VFDT~l*$&YXHXH!hjmpcVhZStF0u z&(z#*M@{!(&^d1Px?XqC8l1$(pqp@5zlf%)S?0B=)6#+o(I0T0_n4yv_m<7ul&-?m6{+^>uIm)p6-^7#;Lm z#{;T3Q%RDeadJ%Sr&W2cdG*O5lD$c9k`N@7&{mAIoNbGrv}F>y`5@+0f4lBgUaPTY zE{uv=_k6GJ)m(2^odhk8VC9ewmgS8*SyB1+8sXxoMQ^p~{|uYKaL|j_#~RK2NM+^m zkC!uwqL6pZM83=5yV25|dzT&Le`04PK9_ps;M{=h^jilsBJ@nE&V?g6WzLJ&d@$%4 zS`GU23}vV3D2k`!bvhDB#<=M$tlNaK2d?wpZV?>9;#V5v@G7F-#;LJ*feW}%(sXEzn zLEzkW5Yh2)-l>%Eo|j=Jc9XV$k@4F}iOQWjWIqnc_{@sJw}xT&Ae>oEPlab@=j|?i z*Lszf+>k#bYb?w^`$=4^tpz=`-U>b@m$Dl^Q+XJ+IbC223f4!cA*tG|^M#(fxEr zv2F5rJMKoa>G}6sNBw}kRY%`#MT1`dWZ_1Bx&Ah4W&CbbW!oj|)-!*dl**pcSm@mxdA=7zG zW4<2t!M-5>hLis$|A9VXfdB*`009U<00Izz00bZa0SG|g|0M7=!6D~Q2MANU=Vk)< zmjp+elrC5^lK|}Ve_sBClb_KCED(SI1Rwwb2tWV=5P$##AOHafTnm8|FL1KDLK6^a`0sj#u!#f?3df z-O6j0Rq(V@!PYfnt7I2SuD#`!iq6A+OEA-!y){~bIF`R zE5$tRisjpyM?2yhw&nVUIlj&}NoJ4E2@uKLbjpUaWoYHRO^;%iJ#EV=7PL(-U$7jz zO#5Sx=Ltl1|Gy}&aPnW|-^o9h-;gc3f&~H)fB*y_009U<00Izz00ba#eFbg{d*m`R z2V$J@5)%e#mhm!^1SyvBGIIk0%Xpb70sa+X?^5#sqx=8gG~`~T?!76?E9 z0uX=z1Rwwb2tWV=5P$##o(F-i3PrMbrhvaGp}Oh*HI6HPH+?oFOc-hio}(A z!*={_fCu5wZ}r3V(dYjka`GqghhJ(xbRGf_fB*y_009U<00Izz00bcLJPWJ}>*RD& zfR}}rrL&U&qwD`qIr(4mr?i{w>i{gV%@R#ZG-YT?(S!v85P$##AOHafKmY;|fB*y_ z0D-F^aM|zwrv#4hf)HQhvzD`KeRiEM(!{RyZ_vd44gi}6SfweM3!pEtKmY;|fB*y_ z009U<00Izz00ba#^#sxaA$&R|NJL~0DfS?+2YUT4Nu$sIpKqMbgO(4w9T2l0edvB!cMB zfZ!%X-cZ~eT*V<%wvGjLaVQQQ#LY!0xa&Jxx+vK9_;~-m-=FV$(*tRG0B38t0suf3 zNS&&6?DupEEuflTUx&}{^5gX3(yd|G?eLeG5`T!A zB3t6dpT}pD@cy7v?S;cf{b+Z5zLEIPbdh)Q2DdY-{4HMPcQUtSLzVNvI)9hG%zvO| zO#%Sgq9HK+p^ds5cf>I;TC@WLOm|+W)oaJqRqjRySR%;`nMzv}%q+4ae7gE3kCa zVYcr2%-7Aj;~A_T*p_cAF_Dw#WI0wRh7b-C0`ZSXLgOJRU6UHx|0Kq~fGhyyWS-jo zO6Z_3snQA*mjs?WFUKqmn}B>E`=mq4_!s_!U*j$|#m8R7dxoYo^9Z2}nXwa&ACG0K zD$SKR Skills { get; set; } + public LargeImageEntity Image { get; set; } + + [ForeignKey("Image")] + public int ImageId { get; set; } } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs index 6fa04cf..5882826 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs @@ -11,7 +11,7 @@ namespace MyFlib { [Key] - public int ImageId { get; set; } + public int Id { get; set; } public string Base64 { get; set; } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs new file mode 100644 index 0000000..5690737 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + public class Rune + { + [Key] + [MaxLength(256)] + public string Name { get; set; } + + [Required] + [MaxLength(500)] + public string Description { get; set; } + public SkillTypeEntity SkillType { get; set; } + public LargeImageEntity Image { get; set; } + + [ForeignKey("Image")] + public int ImageId { get; set; } + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs index 772e162..c16b4c8 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -21,5 +22,8 @@ namespace MyFlib public float Price { get; set; } public LargeImageEntity Image { get; set; } + [ForeignKey("Image")] + public int ImageId { get; set; } + } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs new file mode 100644 index 0000000..f76c708 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib.Entities.enums +{ + enum RuneFamilyEntity + { + Unknown, + Precision, + Domination + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index e507575..3291f49 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -27,22 +27,21 @@ namespace MyFlib } protected override void OnModelCreating(ModelBuilder modelBuilder) { - var image1 = new LargeImageEntity { ImageId = 1, Base64 = "image1" }; - var image2 = new LargeImageEntity { ImageId = 2, Base64 = "image2" }; + var image1 = new LargeImageEntity { Id = 1, Base64 = "empty" }; + var image2 = new LargeImageEntity { Id = 2, Base64 = " " }; modelBuilder.Entity().HasData(image1, image2); - modelBuilder.Entity().Property("ImageId"); - modelBuilder.Entity().HasKey(e => e.Id); + modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); modelBuilder.Entity().HasData( - new { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", Image = "empty" }, - new { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = "empty" } + new { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }, + new { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 2 }, + new { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }, + new { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", ImageId = 1 }, + new { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", ImageId = 1 }, + new { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", ImageId = 1 } ); modelBuilder.Entity().HasData( diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs index fd66059..723a3a6 100644 --- a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs @@ -15,10 +15,20 @@ namespace UT_EF using (var context = new LolDbContext(options)) { - ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }; - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }; - ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; + ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; + + // test contrainte + ChampionEntity errorName = new ChampionEntity + { + Name = "c1832f35-f909-422d-a1fb-e0b79a62f562-fa7c5fe2-89b7-432e-9e0f-a5736445b381-3f75c0f8-de2e-4cf4-82d2-3d24411f6422-6b7e9196-3664-4813-b971-e9cc08a4b255-c1832f35-f909-422d-a1fb-e0b79a62f562-fa7c5fe2-89b7-432e-9e0f-a5736445b381-3f75c0f8-de2e-4cf4-82d2-3d24411f6422-6b7e9196-3664-4813-b971-e9cc08a4b255", + Class = ChampionClassEntity.Mage, + Bio = "", + Icon = "", + ImageId = 1 + }; context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); } @@ -39,9 +49,10 @@ namespace UT_EF using (var context = new LolDbContext(options)) { - ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }; - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }; - ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; + + ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); @@ -84,9 +95,10 @@ namespace UT_EF using (var context = new LolDbContext(options)) { - ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }; - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }; - ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }; + + ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); From 4ccbd68454c2d01b100a4c450564ee3b43a90d64 Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Wed, 1 Mar 2023 18:24:58 +0100 Subject: [PATCH 4/6] Back Up --- .../Sources/MyFlib/DataBase.db | Bin 57344 -> 61440 bytes .../Sources/MyFlib/Entities/ChampionEntity.cs | 2 + .../Entities/{Rune.cs => RuneEntity.cs} | 2 +- .../Sources/MyFlib/Entities/SkinEntity.cs | 4 +- .../Sources/MyFlib/LolDbContext.cs | 36 ++- ...230301171929_monNomDeMigration.Designer.cs | 276 ++++++++++++++++++ .../20230301171929_monNomDeMigration.cs | 175 +++++++++++ .../Migrations/LolDbContextModelSnapshot.cs | 273 +++++++++++++++++ 8 files changed, 754 insertions(+), 14 deletions(-) rename src/EntityFramework_LoL/Sources/MyFlib/Entities/{Rune.cs => RuneEntity.cs} (91%) create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.Designer.cs create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.cs create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db index 9ff30fad1af2ff6c5cb16e904d7019574d8ff427..ec7c5b480b2fdd9a944c2c18bd76fe22b7412ccf 100644 GIT binary patch delta 1339 zcmah{OKclO7~b{TUcc6pgrcQICBLjh&YL_0RfANB9H&Z45|pMQ?Zu4kaXiWHjJuBz zpPYsqazSd?N*uTpTBw3lBD9zGfK9#s#ZNm8Sd3P&{UmXwYzNZL~RF1nFUChux@5{t>t zW68vz`l;Fzy%Ambdi&c*_}%uX?ro{B$jG~{zTT*}sd`SAFLqN_CTr7+g)=LZ*@avc zn>EVW6t@UnVy8*H71wg}`H6)*OwUf{7a{W>?JIS7-$&FJ9RX==K-sA^d48s;=#2)kS z$3|s2>7hhlB>q81O!a?EK9Iv{MbiCmw3DG!7%fZaKDvo6qh-In?L6x12`e-D=*qsI#-XS3X#Br|l$!j5qM*wFCMsCT)uCIA`|+Cxor4K)M+N8Me@jQoH7 zVgK5z@3kp1dg!ZfJwV|@vNGuZG4~Sq(Mx}IrZh1^A?>P!BHC2}`mxs7D1>7Dn|VES zR-Ra~tC&HqUL;nH*WM;J6tO*6;jC;!IXmH&DTf?&>cE);E(6BhRf1ipHg_y;!#EfO z=1Gwl;;a}hAA%fl90E0N(?Hw+>_1^(D0AvS^GXA3&Y;9y3onrYu(9};h;0)fPH-#X z8ZJ?%xg%=9&QeyPhGP*6%9sgK0mbHL4mAmL0*<&+!PFAbDs~+bM8R(Elw6C7!yX7g zORZ-_bMs39^d?xOCg?YJhTu%Vq>3$*fQ45D4c7uAivhc~O`#~13Z6BcYhM#0oYjOtT8H7&ge{GGz=dxLJWs*($%_3S}%HZgW>Kc0r6l zSx_>v|Mmzw7!!4^3SlMVW?+8{SP(6{)WQKsiLi2@^_(F#!Wc1WU`fkS6F0vS^7huh z027O_fT>w@?I3LvYn7G+725%ayUW6V0kOudB6Toxo~R4OJXYvRC4!kj_ayW?y63kK ze}~?9LFs>bSVA32|I^xo#wgm8(BJ4W`ct(3hV}%&_sHA(p)0*Bp`XyMC`kp&KXm&O zq-2$|o>}Pjc6smqvyWTde*2wY(e^vh7sHAqhZIGMKOyxf$UfT7MiLQ4mO~;PkN*P* C>91%2 delta 622 zcma)3O=uHA6rR8CWOuW938-tV=n9qAP)uV$$VEgDp;Qz+Xm3WkhS+U3bQ8o|DAj`} z!=zrkSc&xHX)fj<7IT(J5lAEg`SllPpVqPsusM86p`pLYSF%9+345+R0*3_8k^yr%YWDlu;pERrAI9Hg(p+n#^ zyoQd>%sc|sIa$YAm%ujkp^LSrpu73oX-?8a%Zo!0*n%Va$F-xLu}gdY6JQiozv-sor?N2RUjKPPvTEm!oFr%{B4i zg6~D;S_OIGf_F7Utr3;Qjb|_*@Erzd*oVR~UZVdtV~2UcJSh62?oEwkb_x83T~v%m zx<6JE^8`X71X^ss<^Q!1oKVI&i6!C{pRtUA5c<&OGiX0As_nNE#twmBu%j~{zCruC Mumq;M1& diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs index 19c0183..35a11ee 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs @@ -23,6 +23,8 @@ namespace MyFlib [Required] public ChampionClassEntity Class { get; set; } public ICollection Skills { get; set; } + public ICollection Skins { get; set; } + public LargeImageEntity Image { get; set; } [ForeignKey("Image")] diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/RuneEntity.cs similarity index 91% rename from src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs rename to src/EntityFramework_LoL/Sources/MyFlib/Entities/RuneEntity.cs index 5690737..1858a30 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/Rune.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/RuneEntity.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace MyFlib { - public class Rune + public class RuneEntity { [Key] [MaxLength(256)] diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs index c16b4c8..7524011 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs @@ -20,8 +20,10 @@ namespace MyFlib public string Icon { get; set; } [Required] public float Price { get; set; } + [ForeignKey("ChampionForeignKey")] + public ChampionEntity Champion { get; set; } + public Guid ChampionForeignKey { get; set; } public LargeImageEntity Image { get; set; } - [ForeignKey("Image")] public int ImageId { get; set; } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index 3291f49..192ebd2 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -12,6 +12,7 @@ namespace MyFlib public DbSet Champions { get; set; } public DbSet Skills { get; set; } public DbSet Skins { get; set; } + public DbSet Runes { get; set; } public LolDbContext() { } @@ -27,31 +28,42 @@ namespace MyFlib } protected override void OnModelCreating(ModelBuilder modelBuilder) { - var image1 = new LargeImageEntity { Id = 1, Base64 = "empty" }; - var image2 = new LargeImageEntity { Id = 2, Base64 = " " }; + //LargeImageEntity + LargeImageEntity image1 = new LargeImageEntity { Id = 1, Base64 = "empty" }; + LargeImageEntity image2 = new LargeImageEntity { Id = 2, Base64 = " " }; modelBuilder.Entity().HasData(image1, image2); + //ChampionEntity modelBuilder.Entity().HasKey(e => e.Id); modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); - modelBuilder.Entity().HasData( - new { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }, - new { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 2 }, - new { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }, - new { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", ImageId = 1 }, - new { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", ImageId = 1 }, - new { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", ImageId = 1 } - ); + ChampionEntity Akali = new ChampionEntity { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity Aatrox = new ChampionEntity { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 2 }; + ChampionEntity Ahri = new ChampionEntity { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity Akshan = new ChampionEntity { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity Bard = new ChampionEntity { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity Alistar = new ChampionEntity { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", ImageId = 1 }; + + + modelBuilder.Entity().HasData(Akali, Aatrox, Ahri, Akshan, Bard, Alistar); + //SkillEntity modelBuilder.Entity().HasData( new { Name = "Boule de feu", Description = "Fire!", Type = SkillTypeEntity.Basic }, new { Name = "White Star", Description = "Random damage", Type = SkillTypeEntity.Ultimate } ); + //SkinEntity + modelBuilder.Entity().HasData( + new SkinEntity { Name = "Akali Infernale", ChampionForeignKey = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Description = "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", Icon = "empty", Price = 520, ImageId = 1 }, + new SkinEntity { Name = "Akshan Cyberpop", ChampionForeignKey = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Description = "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", Icon = "empty", Price = 1350, ImageId = 2 } + ); + + //RuneEntity modelBuilder.Entity().HasData( - new SkinEntity { Name = "Yone fleur spirituelle", Description = "Spirit Blossom", Icon = "empty", Price = 975, ImageId = 1 }, - new SkinEntity { Name = "Yasuo Lune de sang", Description = "Blood Moon", Icon = "empty", Price = 975, ImageId = 2 } + new SkinEntity { Name = "Akali Infernale", ChampionForeignKey = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Description = "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", Icon = "empty", Price = 520, ImageId = 1 }, + new SkinEntity { Name = "Akshan Cyberpop", ChampionForeignKey = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Description = "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", Icon = "empty", Price = 1350, ImageId = 2 } ); } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.Designer.cs b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.Designer.cs new file mode 100644 index 0000000..0378080 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.Designer.cs @@ -0,0 +1,276 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MyFlib; + +#nullable disable + +namespace MyFlib.Migrations +{ + [DbContext(typeof(LolDbContext))] + [Migration("20230301171929_monNomDeMigration")] + partial class monNomDeMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("MyFlib.ChampionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ImageId"); + + b.ToTable("Champions"); + + b.HasData( + new + { + Id = new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), + Bio = "", + Class = 1, + Icon = "", + ImageId = 1, + Name = "Akali" + }, + new + { + Id = new Guid("a4f84d92-c20f-4f2d-b3f9-ca00ef556e72"), + Bio = "", + Class = 2, + Icon = "", + ImageId = 2, + Name = "Aatrox" + }, + new + { + Id = new Guid("ae5fe535-f041-445e-b570-28b75bc78cb9"), + Bio = "", + Class = 3, + Icon = "", + ImageId = 1, + Name = "Ahri" + }, + new + { + Id = new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), + Bio = "", + Class = 4, + Icon = "", + ImageId = 1, + Name = "Akshan" + }, + new + { + Id = new Guid("7f7746fa-b1cb-49da-9409-4b3e6910500e"), + Bio = "", + Class = 5, + Icon = "", + ImageId = 1, + Name = "Bard" + }, + new + { + Id = new Guid("36ad2a82-d17b-47de-8a95-6e154a7df557"), + Bio = "", + Class = 6, + Icon = "", + ImageId = 1, + Name = "Alistar" + }); + }); + + modelBuilder.Entity("MyFlib.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("LargeImageEntity"); + + b.HasData( + new + { + Id = 1, + Base64 = "empty" + }, + new + { + Id = 2, + Base64 = " " + }); + }); + + modelBuilder.Entity("MyFlib.SkillEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionEntityId") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityId"); + + b.ToTable("Skills"); + + b.HasData( + new + { + Name = "Boule de feu", + Description = "Fire!", + Type = 1 + }, + new + { + Name = "White Star", + Description = "Random damage", + Type = 3 + }); + }); + + modelBuilder.Entity("MyFlib.SkinEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionForeignKey"); + + b.HasIndex("ImageId"); + + b.ToTable("Skins"); + + b.HasData( + new + { + Name = "Akali Infernale", + ChampionForeignKey = new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), + Description = "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", + Icon = "empty", + ImageId = 1, + Price = 520f + }, + new + { + Name = "Akshan Cyberpop", + ChampionForeignKey = new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), + Description = "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", + Icon = "empty", + ImageId = 2, + Price = 1350f + }); + }); + + modelBuilder.Entity("MyFlib.ChampionEntity", b => + { + b.HasOne("MyFlib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("MyFlib.SkillEntity", b => + { + b.HasOne("MyFlib.ChampionEntity", null) + .WithMany("Skills") + .HasForeignKey("ChampionEntityId"); + }); + + modelBuilder.Entity("MyFlib.SkinEntity", b => + { + b.HasOne("MyFlib.ChampionEntity", "Champion") + .WithMany("Skins") + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MyFlib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("MyFlib.ChampionEntity", b => + { + b.Navigation("Skills"); + + b.Navigation("Skins"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.cs b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.cs new file mode 100644 index 0000000..6ff02ea --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.cs @@ -0,0 +1,175 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace MyFlib.Migrations +{ + /// + public partial class monNomDeMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "LargeImageEntity", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Base64 = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LargeImageEntity", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Champions", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 64, nullable: false), + Bio = table.Column(type: "TEXT", maxLength: 255, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Class = table.Column(type: "INTEGER", nullable: false), + ImageId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Champions", x => x.Id); + table.ForeignKey( + name: "FK_Champions_LargeImageEntity_ImageId", + column: x => x.ImageId, + principalTable: "LargeImageEntity", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Skills", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Type = table.Column(type: "INTEGER", nullable: false), + ChampionEntityId = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Skills", x => x.Name); + table.ForeignKey( + name: "FK_Skills_Champions_ChampionEntityId", + column: x => x.ChampionEntityId, + principalTable: "Champions", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Skins", + columns: table => new + { + Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), + Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Icon = table.Column(type: "TEXT", nullable: false), + Price = table.Column(type: "REAL", nullable: false), + ChampionForeignKey = table.Column(type: "TEXT", nullable: false), + ImageId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Skins", x => x.Name); + table.ForeignKey( + name: "FK_Skins_Champions_ChampionForeignKey", + column: x => x.ChampionForeignKey, + principalTable: "Champions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Skins_LargeImageEntity_ImageId", + column: x => x.ImageId, + principalTable: "LargeImageEntity", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "LargeImageEntity", + columns: new[] { "Id", "Base64" }, + values: new object[,] + { + { 1, "empty" }, + { 2, " " } + }); + + migrationBuilder.InsertData( + table: "Skills", + columns: new[] { "Name", "ChampionEntityId", "Description", "Type" }, + values: new object[,] + { + { "Boule de feu", null, "Fire!", 1 }, + { "White Star", null, "Random damage", 3 } + }); + + migrationBuilder.InsertData( + table: "Champions", + columns: new[] { "Id", "Bio", "Class", "Icon", "ImageId", "Name" }, + values: new object[,] + { + { new Guid("36ad2a82-d17b-47de-8a95-6e154a7df557"), "", 6, "", 1, "Alistar" }, + { new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), "", 4, "", 1, "Akshan" }, + { new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), "", 1, "", 1, "Akali" }, + { new Guid("7f7746fa-b1cb-49da-9409-4b3e6910500e"), "", 5, "", 1, "Bard" }, + { new Guid("a4f84d92-c20f-4f2d-b3f9-ca00ef556e72"), "", 2, "", 2, "Aatrox" }, + { new Guid("ae5fe535-f041-445e-b570-28b75bc78cb9"), "", 3, "", 1, "Ahri" } + }); + + migrationBuilder.InsertData( + table: "Skins", + columns: new[] { "Name", "ChampionForeignKey", "Description", "Icon", "ImageId", "Price" }, + values: new object[,] + { + { "Akali Infernale", new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", "empty", 1, 520f }, + { "Akshan Cyberpop", new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", "empty", 2, 1350f } + }); + + migrationBuilder.CreateIndex( + name: "IX_Champions_ImageId", + table: "Champions", + column: "ImageId"); + + migrationBuilder.CreateIndex( + name: "IX_Skills_ChampionEntityId", + table: "Skills", + column: "ChampionEntityId"); + + migrationBuilder.CreateIndex( + name: "IX_Skins_ChampionForeignKey", + table: "Skins", + column: "ChampionForeignKey"); + + migrationBuilder.CreateIndex( + name: "IX_Skins_ImageId", + table: "Skins", + column: "ImageId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Skills"); + + migrationBuilder.DropTable( + name: "Skins"); + + migrationBuilder.DropTable( + name: "Champions"); + + migrationBuilder.DropTable( + name: "LargeImageEntity"); + } + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs new file mode 100644 index 0000000..f0dd4a8 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs @@ -0,0 +1,273 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using MyFlib; + +#nullable disable + +namespace MyFlib.Migrations +{ + [DbContext(typeof(LolDbContext))] + partial class LolDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); + + modelBuilder.Entity("MyFlib.ChampionEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Bio") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("TEXT"); + + b.Property("Class") + .HasColumnType("INTEGER"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ImageId"); + + b.ToTable("Champions"); + + b.HasData( + new + { + Id = new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), + Bio = "", + Class = 1, + Icon = "", + ImageId = 1, + Name = "Akali" + }, + new + { + Id = new Guid("a4f84d92-c20f-4f2d-b3f9-ca00ef556e72"), + Bio = "", + Class = 2, + Icon = "", + ImageId = 2, + Name = "Aatrox" + }, + new + { + Id = new Guid("ae5fe535-f041-445e-b570-28b75bc78cb9"), + Bio = "", + Class = 3, + Icon = "", + ImageId = 1, + Name = "Ahri" + }, + new + { + Id = new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), + Bio = "", + Class = 4, + Icon = "", + ImageId = 1, + Name = "Akshan" + }, + new + { + Id = new Guid("7f7746fa-b1cb-49da-9409-4b3e6910500e"), + Bio = "", + Class = 5, + Icon = "", + ImageId = 1, + Name = "Bard" + }, + new + { + Id = new Guid("36ad2a82-d17b-47de-8a95-6e154a7df557"), + Bio = "", + Class = 6, + Icon = "", + ImageId = 1, + Name = "Alistar" + }); + }); + + modelBuilder.Entity("MyFlib.LargeImageEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Base64") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("LargeImageEntity"); + + b.HasData( + new + { + Id = 1, + Base64 = "empty" + }, + new + { + Id = 2, + Base64 = " " + }); + }); + + modelBuilder.Entity("MyFlib.SkillEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionEntityId") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Name"); + + b.HasIndex("ChampionEntityId"); + + b.ToTable("Skills"); + + b.HasData( + new + { + Name = "Boule de feu", + Description = "Fire!", + Type = 1 + }, + new + { + Name = "White Star", + Description = "Random damage", + Type = 3 + }); + }); + + modelBuilder.Entity("MyFlib.SkinEntity", b => + { + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("ChampionForeignKey") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Icon") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("INTEGER"); + + b.Property("Price") + .HasColumnType("REAL"); + + b.HasKey("Name"); + + b.HasIndex("ChampionForeignKey"); + + b.HasIndex("ImageId"); + + b.ToTable("Skins"); + + b.HasData( + new + { + Name = "Akali Infernale", + ChampionForeignKey = new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), + Description = "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", + Icon = "empty", + ImageId = 1, + Price = 520f + }, + new + { + Name = "Akshan Cyberpop", + ChampionForeignKey = new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), + Description = "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", + Icon = "empty", + ImageId = 2, + Price = 1350f + }); + }); + + modelBuilder.Entity("MyFlib.ChampionEntity", b => + { + b.HasOne("MyFlib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("MyFlib.SkillEntity", b => + { + b.HasOne("MyFlib.ChampionEntity", null) + .WithMany("Skills") + .HasForeignKey("ChampionEntityId"); + }); + + modelBuilder.Entity("MyFlib.SkinEntity", b => + { + b.HasOne("MyFlib.ChampionEntity", "Champion") + .WithMany("Skins") + .HasForeignKey("ChampionForeignKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MyFlib.LargeImageEntity", "Image") + .WithMany() + .HasForeignKey("ImageId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Champion"); + + b.Navigation("Image"); + }); + + modelBuilder.Entity("MyFlib.ChampionEntity", b => + { + b.Navigation("Skills"); + + b.Navigation("Skins"); + }); +#pragma warning restore 612, 618 + } + } +} From dacb7131c6f10a83191c550fed9e9ac5d7cc661c Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Wed, 1 Mar 2023 18:55:22 +0100 Subject: [PATCH 5/6] Creation of all classes --- .../Sources/MyFlib/DataBase.db | Bin 61440 -> 73728 bytes .../Sources/MyFlib/Entities/RunePageEntity.cs | 12 + .../MyFlib/Entities/enums/CategoryEntity.cs | 18 ++ .../Sources/MyFlib/LolDbContext.cs | 6 +- ...230301171929_monNomDeMigration.Designer.cs | 276 ------------------ .../20230301171929_monNomDeMigration.cs | 175 ----------- .../Migrations/LolDbContextModelSnapshot.cs | 273 ----------------- 7 files changed, 33 insertions(+), 727 deletions(-) create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Entities/RunePageEntity.cs create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/CategoryEntity.cs delete mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.Designer.cs delete mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.cs delete mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db index ec7c5b480b2fdd9a944c2c18bd76fe22b7412ccf..cb2c8bd26d01c175abe32e879db24b314e9744f3 100644 GIT binary patch delta 987 zcmZ`&T}TvB6rMY?JG-;HGk4d*Y0L7mD5^1cK~RxUIE^YN?y&`3lAGS&GjJAK^HqKA(l^GzSKL4FFnbPE z;Szh%av$O~wh09AHrs2tH8|{Q0)9N?x_;CBiP~ru!K|WXwQl2s7@f^CQO2wQpB^9hD6KE)>sPaJ&DMh4fXk6FTj9${hNHMI?lw44yaXEv= zW)TsYu<~1I4>=DFwjpMt;P{^7VBjg4iG zz>{w;frpfN1@Z2ilO87n08KLt$1N|SPO@h`7SBb%5?HtGBj5W3kd-T4Lo0EF5JEC2ui delta 431 zcmYjNO(=v>6n)RUdEYnR-~C4F85*A{F(zaD>}F%Oq%2I4jVNJEEU1ZD%w#NV6g{Qv z{H-)idJF87og__SW1+E;!epbQcu2W*Zugvf&RyK>3CZ5MR%^Xcgb+ylReY_bvpI@d zhigpp7+Exq%yFv-c}v%e=A|~M@2R>LR<@KN&C|FD*ynCC;H8YGNgW3MNfh->{Gdo34Y z%yDoo{d0jD;>?Uz7z7dsZs7>lAtAhNL%s zv3np@*cBGfebx1XuD(0lC-qgDd?SStf)99uS9pR4D9Q8%@X|{|V*$Yp6r{!Y2VKtJ YF-yWDp-O)aHVS|Tc4*l?q&9wsFB~Rsu>b%7 diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/RunePageEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/RunePageEntity.cs new file mode 100644 index 0000000..d23e7a0 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/RunePageEntity.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib.Entities +{ + public class RunePageEntity + { + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/CategoryEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/CategoryEntity.cs new file mode 100644 index 0000000..fd59784 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/CategoryEntity.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib.Entities.enums +{ + enum CategoryEntity + { + Major, + Minor1, + Minor2, + Minor3, + OtherMinor1, + OtherMinor2 + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index 192ebd2..9ba2246 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -61,9 +61,9 @@ namespace MyFlib ); //RuneEntity - modelBuilder.Entity().HasData( - new SkinEntity { Name = "Akali Infernale", ChampionForeignKey = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Description = "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", Icon = "empty", Price = 520, ImageId = 1 }, - new SkinEntity { Name = "Akshan Cyberpop", ChampionForeignKey = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Description = "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", Icon = "empty", Price = 1350, ImageId = 2 } + modelBuilder.Entity().HasData( + new RuneEntity { Name = "Hextech Flashtraption ", Description = "While Flash is on cooldown, it is replaced by Hexflash.", SkillType = SkillTypeEntity.Passive, ImageId = 1 }, + new RuneEntity { Name = "Manaflow Band ", Description = "Hitting enemy champions with a spell grants 25 maximum mana, up to 250 mana.", SkillType = SkillTypeEntity.Basic, ImageId = 2 } ); } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.Designer.cs b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.Designer.cs deleted file mode 100644 index 0378080..0000000 --- a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.Designer.cs +++ /dev/null @@ -1,276 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using MyFlib; - -#nullable disable - -namespace MyFlib.Migrations -{ - [DbContext(typeof(LolDbContext))] - [Migration("20230301171929_monNomDeMigration")] - partial class monNomDeMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("MyFlib.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.Property("Class") - .HasColumnType("INTEGER"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ImageId") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(64) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("ImageId"); - - b.ToTable("Champions"); - - b.HasData( - new - { - Id = new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), - Bio = "", - Class = 1, - Icon = "", - ImageId = 1, - Name = "Akali" - }, - new - { - Id = new Guid("a4f84d92-c20f-4f2d-b3f9-ca00ef556e72"), - Bio = "", - Class = 2, - Icon = "", - ImageId = 2, - Name = "Aatrox" - }, - new - { - Id = new Guid("ae5fe535-f041-445e-b570-28b75bc78cb9"), - Bio = "", - Class = 3, - Icon = "", - ImageId = 1, - Name = "Ahri" - }, - new - { - Id = new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), - Bio = "", - Class = 4, - Icon = "", - ImageId = 1, - Name = "Akshan" - }, - new - { - Id = new Guid("7f7746fa-b1cb-49da-9409-4b3e6910500e"), - Bio = "", - Class = 5, - Icon = "", - ImageId = 1, - Name = "Bard" - }, - new - { - Id = new Guid("36ad2a82-d17b-47de-8a95-6e154a7df557"), - Bio = "", - Class = 6, - Icon = "", - ImageId = 1, - Name = "Alistar" - }); - }); - - modelBuilder.Entity("MyFlib.LargeImageEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Base64") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("LargeImageEntity"); - - b.HasData( - new - { - Id = 1, - Base64 = "empty" - }, - new - { - Id = 2, - Base64 = " " - }); - }); - - modelBuilder.Entity("MyFlib.SkillEntity", b => - { - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("ChampionEntityId") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("TEXT"); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.HasKey("Name"); - - b.HasIndex("ChampionEntityId"); - - b.ToTable("Skills"); - - b.HasData( - new - { - Name = "Boule de feu", - Description = "Fire!", - Type = 1 - }, - new - { - Name = "White Star", - Description = "Random damage", - Type = 3 - }); - }); - - modelBuilder.Entity("MyFlib.SkinEntity", b => - { - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("ChampionForeignKey") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ImageId") - .HasColumnType("INTEGER"); - - b.Property("Price") - .HasColumnType("REAL"); - - b.HasKey("Name"); - - b.HasIndex("ChampionForeignKey"); - - b.HasIndex("ImageId"); - - b.ToTable("Skins"); - - b.HasData( - new - { - Name = "Akali Infernale", - ChampionForeignKey = new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), - Description = "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", - Icon = "empty", - ImageId = 1, - Price = 520f - }, - new - { - Name = "Akshan Cyberpop", - ChampionForeignKey = new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), - Description = "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", - Icon = "empty", - ImageId = 2, - Price = 1350f - }); - }); - - modelBuilder.Entity("MyFlib.ChampionEntity", b => - { - b.HasOne("MyFlib.LargeImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("MyFlib.SkillEntity", b => - { - b.HasOne("MyFlib.ChampionEntity", null) - .WithMany("Skills") - .HasForeignKey("ChampionEntityId"); - }); - - modelBuilder.Entity("MyFlib.SkinEntity", b => - { - b.HasOne("MyFlib.ChampionEntity", "Champion") - .WithMany("Skins") - .HasForeignKey("ChampionForeignKey") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("MyFlib.LargeImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Champion"); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("MyFlib.ChampionEntity", b => - { - b.Navigation("Skills"); - - b.Navigation("Skins"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.cs b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.cs deleted file mode 100644 index 6ff02ea..0000000 --- a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230301171929_monNomDeMigration.cs +++ /dev/null @@ -1,175 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace MyFlib.Migrations -{ - /// - public partial class monNomDeMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "LargeImageEntity", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Base64 = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_LargeImageEntity", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Champions", - columns: table => new - { - Id = table.Column(type: "TEXT", nullable: false), - Name = table.Column(type: "TEXT", maxLength: 64, nullable: false), - Bio = table.Column(type: "TEXT", maxLength: 255, nullable: false), - Icon = table.Column(type: "TEXT", nullable: false), - Class = table.Column(type: "INTEGER", nullable: false), - ImageId = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Champions", x => x.Id); - table.ForeignKey( - name: "FK_Champions_LargeImageEntity_ImageId", - column: x => x.ImageId, - principalTable: "LargeImageEntity", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Skills", - columns: table => new - { - Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), - Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), - Type = table.Column(type: "INTEGER", nullable: false), - ChampionEntityId = table.Column(type: "TEXT", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Skills", x => x.Name); - table.ForeignKey( - name: "FK_Skills_Champions_ChampionEntityId", - column: x => x.ChampionEntityId, - principalTable: "Champions", - principalColumn: "Id"); - }); - - migrationBuilder.CreateTable( - name: "Skins", - columns: table => new - { - Name = table.Column(type: "TEXT", maxLength: 256, nullable: false), - Description = table.Column(type: "TEXT", maxLength: 500, nullable: false), - Icon = table.Column(type: "TEXT", nullable: false), - Price = table.Column(type: "REAL", nullable: false), - ChampionForeignKey = table.Column(type: "TEXT", nullable: false), - ImageId = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Skins", x => x.Name); - table.ForeignKey( - name: "FK_Skins_Champions_ChampionForeignKey", - column: x => x.ChampionForeignKey, - principalTable: "Champions", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Skins_LargeImageEntity_ImageId", - column: x => x.ImageId, - principalTable: "LargeImageEntity", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.InsertData( - table: "LargeImageEntity", - columns: new[] { "Id", "Base64" }, - values: new object[,] - { - { 1, "empty" }, - { 2, " " } - }); - - migrationBuilder.InsertData( - table: "Skills", - columns: new[] { "Name", "ChampionEntityId", "Description", "Type" }, - values: new object[,] - { - { "Boule de feu", null, "Fire!", 1 }, - { "White Star", null, "Random damage", 3 } - }); - - migrationBuilder.InsertData( - table: "Champions", - columns: new[] { "Id", "Bio", "Class", "Icon", "ImageId", "Name" }, - values: new object[,] - { - { new Guid("36ad2a82-d17b-47de-8a95-6e154a7df557"), "", 6, "", 1, "Alistar" }, - { new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), "", 4, "", 1, "Akshan" }, - { new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), "", 1, "", 1, "Akali" }, - { new Guid("7f7746fa-b1cb-49da-9409-4b3e6910500e"), "", 5, "", 1, "Bard" }, - { new Guid("a4f84d92-c20f-4f2d-b3f9-ca00ef556e72"), "", 2, "", 2, "Aatrox" }, - { new Guid("ae5fe535-f041-445e-b570-28b75bc78cb9"), "", 3, "", 1, "Ahri" } - }); - - migrationBuilder.InsertData( - table: "Skins", - columns: new[] { "Name", "ChampionForeignKey", "Description", "Icon", "ImageId", "Price" }, - values: new object[,] - { - { "Akali Infernale", new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", "empty", 1, 520f }, - { "Akshan Cyberpop", new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", "empty", 2, 1350f } - }); - - migrationBuilder.CreateIndex( - name: "IX_Champions_ImageId", - table: "Champions", - column: "ImageId"); - - migrationBuilder.CreateIndex( - name: "IX_Skills_ChampionEntityId", - table: "Skills", - column: "ChampionEntityId"); - - migrationBuilder.CreateIndex( - name: "IX_Skins_ChampionForeignKey", - table: "Skins", - column: "ChampionForeignKey"); - - migrationBuilder.CreateIndex( - name: "IX_Skins_ImageId", - table: "Skins", - column: "ImageId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Skills"); - - migrationBuilder.DropTable( - name: "Skins"); - - migrationBuilder.DropTable( - name: "Champions"); - - migrationBuilder.DropTable( - name: "LargeImageEntity"); - } - } -} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs deleted file mode 100644 index f0dd4a8..0000000 --- a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs +++ /dev/null @@ -1,273 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using MyFlib; - -#nullable disable - -namespace MyFlib.Migrations -{ - [DbContext(typeof(LolDbContext))] - partial class LolDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "7.0.2"); - - modelBuilder.Entity("MyFlib.ChampionEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("TEXT"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.Property("Class") - .HasColumnType("INTEGER"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ImageId") - .HasColumnType("INTEGER"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(64) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.HasIndex("ImageId"); - - b.ToTable("Champions"); - - b.HasData( - new - { - Id = new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), - Bio = "", - Class = 1, - Icon = "", - ImageId = 1, - Name = "Akali" - }, - new - { - Id = new Guid("a4f84d92-c20f-4f2d-b3f9-ca00ef556e72"), - Bio = "", - Class = 2, - Icon = "", - ImageId = 2, - Name = "Aatrox" - }, - new - { - Id = new Guid("ae5fe535-f041-445e-b570-28b75bc78cb9"), - Bio = "", - Class = 3, - Icon = "", - ImageId = 1, - Name = "Ahri" - }, - new - { - Id = new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), - Bio = "", - Class = 4, - Icon = "", - ImageId = 1, - Name = "Akshan" - }, - new - { - Id = new Guid("7f7746fa-b1cb-49da-9409-4b3e6910500e"), - Bio = "", - Class = 5, - Icon = "", - ImageId = 1, - Name = "Bard" - }, - new - { - Id = new Guid("36ad2a82-d17b-47de-8a95-6e154a7df557"), - Bio = "", - Class = 6, - Icon = "", - ImageId = 1, - Name = "Alistar" - }); - }); - - modelBuilder.Entity("MyFlib.LargeImageEntity", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("INTEGER"); - - b.Property("Base64") - .IsRequired() - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("LargeImageEntity"); - - b.HasData( - new - { - Id = 1, - Base64 = "empty" - }, - new - { - Id = 2, - Base64 = " " - }); - }); - - modelBuilder.Entity("MyFlib.SkillEntity", b => - { - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("ChampionEntityId") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("TEXT"); - - b.Property("Type") - .HasColumnType("INTEGER"); - - b.HasKey("Name"); - - b.HasIndex("ChampionEntityId"); - - b.ToTable("Skills"); - - b.HasData( - new - { - Name = "Boule de feu", - Description = "Fire!", - Type = 1 - }, - new - { - Name = "White Star", - Description = "Random damage", - Type = 3 - }); - }); - - modelBuilder.Entity("MyFlib.SkinEntity", b => - { - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("TEXT"); - - b.Property("ChampionForeignKey") - .HasColumnType("TEXT"); - - b.Property("Description") - .IsRequired() - .HasMaxLength(500) - .HasColumnType("TEXT"); - - b.Property("Icon") - .IsRequired() - .HasColumnType("TEXT"); - - b.Property("ImageId") - .HasColumnType("INTEGER"); - - b.Property("Price") - .HasColumnType("REAL"); - - b.HasKey("Name"); - - b.HasIndex("ChampionForeignKey"); - - b.HasIndex("ImageId"); - - b.ToTable("Skins"); - - b.HasData( - new - { - Name = "Akali Infernale", - ChampionForeignKey = new Guid("4422c524-b2cb-43ef-8263-990c3cea7cae"), - Description = "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", - Icon = "empty", - ImageId = 1, - Price = 520f - }, - new - { - Name = "Akshan Cyberpop", - ChampionForeignKey = new Guid("3708dcfd-02a1-491e-b4f7-e75bf274cf23"), - Description = "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", - Icon = "empty", - ImageId = 2, - Price = 1350f - }); - }); - - modelBuilder.Entity("MyFlib.ChampionEntity", b => - { - b.HasOne("MyFlib.LargeImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("MyFlib.SkillEntity", b => - { - b.HasOne("MyFlib.ChampionEntity", null) - .WithMany("Skills") - .HasForeignKey("ChampionEntityId"); - }); - - modelBuilder.Entity("MyFlib.SkinEntity", b => - { - b.HasOne("MyFlib.ChampionEntity", "Champion") - .WithMany("Skins") - .HasForeignKey("ChampionForeignKey") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("MyFlib.LargeImageEntity", "Image") - .WithMany() - .HasForeignKey("ImageId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Champion"); - - b.Navigation("Image"); - }); - - modelBuilder.Entity("MyFlib.ChampionEntity", b => - { - b.Navigation("Skills"); - - b.Navigation("Skins"); - }); -#pragma warning restore 612, 618 - } - } -} From 0bdef0bc74aa2b123de505040dcdc45e10a980f1 Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Sat, 11 Mar 2023 10:33:33 +0100 Subject: [PATCH 6/6] Add more UT and more stubData :white_check_mark: --- .vs/LolProject/v17/.wsuo | Bin 0 -> 13824 bytes .../Sources/MyFlib/DataBase.db | Bin 73728 -> 77824 bytes .../Sources/MyFlib/DataSeeder.cs | 71 +++++++---- .../Sources/MyFlib/Entities/ChampionEntity.cs | 2 +- .../MyFlib/Entities/LargeImageEntity.cs | 2 +- .../Sources/MyFlib/Entities/RuneEntity.cs | 10 +- .../Sources/MyFlib/Entities/SkillEntity.cs | 2 +- .../Sources/MyFlib/Entities/SkinEntity.cs | 3 +- .../MyFlib/Entities/enums/RuneFamilyEntity.cs | 2 +- .../Sources/MyFlib/LolDbContext.cs | 32 +++-- .../Sources/MyFlib/Program.cs | 22 +++- .../Sources/Tests/UT_EF/ChampionsTest.cs | 26 ++-- .../Sources/Tests/UT_EF/LargeImagesTest.cs | 111 ++++++++++++++++ .../Sources/Tests/UT_EF/SkillsTest.cs | 120 ++++++++++++++++++ .../Sources/Tests/UT_EF/SkinsTest.cs | 116 +++++++++++++++++ 15 files changed, 459 insertions(+), 60 deletions(-) create mode 100644 .vs/LolProject/v17/.wsuo create mode 100644 src/EntityFramework_LoL/Sources/Tests/UT_EF/LargeImagesTest.cs create mode 100644 src/EntityFramework_LoL/Sources/Tests/UT_EF/SkillsTest.cs create mode 100644 src/EntityFramework_LoL/Sources/Tests/UT_EF/SkinsTest.cs diff --git a/.vs/LolProject/v17/.wsuo b/.vs/LolProject/v17/.wsuo new file mode 100644 index 0000000000000000000000000000000000000000..53bddc1a2fa2c49263a6eb81a6e9feec4c9da03e GIT binary patch literal 13824 zcmeHN-%lJ>6h2!Nh5D;ivDTUpL$on2EU?0Yu_Dl_Q3_=#^nt`Iv%_}F!mhi6SgkMm zq=~P-+xQRoH}u{5>WkIH#F*%lPiicF-<`Sa>@Yh!JD?)WC9`+#&+p!I&$;)zXZYs! ziSNJo>hurd3Fo9k?rwKUrz=0fQj#L(&!^x*o<>f! z8L*QN`~>HH4C%1*e+qTAU2_@!VnbJ;Ju^InGX2i?HwUcCN?TQ4TTc*|g; z>tMT8#9?_a%v^;t;Gewrkq=T*c5d+RX%wGzsw@Dv2Hdy6b!%Y4S-Gk>xFv>S#m*iM|<_7>OlQ7!~hFruwaqYCHn} zr+wMzBGc%XGhKIjUQ)M!JaV@%f-=TY1Zq*C*HLwAkrd?rG?Gu?2`m4{Q1^z@MZEq; zd;Mo*UM}PIpM{2%l*QS)*6XqaM^${IXQ6-Ohx(4^Tgj8DIU%zz$pVmxO^eIH7S`}v zfHh1b<{kV^yf^nrJP&+wQQC7@{UZ| zkWFaa8oWVewHI5^O!r8fhE9}*{?Ug*pH|rUv%Wrmy!bW}PeR)h^(w|ukr|}uAF^{D zXcdhBpSa}RVexs_yT|Foi|;>wr?O9UHiG==N6I(B=Xq>k1uB83UVR`@^pAU0Gx=*i zKpQaev>FfOujKwH`V1?7?K|Tvyz(diuQH1;4r5@I5fhK+{Xg-tF5*74Mta0W<>_ zc^Mp^EdQll{m}o=UVA-9yDRcw+CtxOet2})NN18p$~2Sd)iEPEHn?IWhcl_nNY2Qm zS4PH^P}FsYjf)dZPbRYq<0<@oU>N3$W2lx)8N*}AbUHnhT*(b(l7lH@B%L!x&CJ;9 zhunKO6CJMH<_hq8fWCp%z{VDpmRs@?Gp}r{_w2STf!_j<~3Mw0cV}}j=d-ue^6KM zGr%X8AvS}nsOc-eVexwz!xVNNdLU}Bxgt*dtzDzA>oxo3_c!{;_$@pveh~j%Qnwxh zUJ&{qT8G{U{ENO4eg3x`(L4^RN`$si+wsz&11Dr4e|`_(oj&aR-TEK2{&PUxz#n<|1vTrs-f4WzzlqJD z^MhjAs$Tyf{6#f$3wOmFb}8+lWQ#l`b5&^}Ry9Hs=#r&($omx-}4$KTwXg?^PrU|LB80H+rDk<3Bc=tK1rR?#7oFZ+=?# z%BNNO)E}L%9Pjw(x0821{^j$5?|y7m|FD(E>mRTGe`)`={YKw^zV7_>lbg4q+y7y+ z=XU24-~Sr@&;I@|H%n-gu=fA9!#@v_|2O{r)3}~dQkwgP<)2Y7g4*l_KX0z)HcQsq z)_P@hXgJkxnKi3sT2^tR5a#-+c(lET2aT|K8TsR0+LOmNwy#VyN84RO9?tglKH6)) z*YWQjQF}S{aW}Tp{tb7oUmnZ-^7oSG#{8$>6Rwqug2lTS!<3B6GW^~(b?2+$o!=q( zEt=kF{%6P_^5_-NUuBlnJ(=>qvWNEk%1AVN7fL%GZ~K2vmN~E%!GHb3`|o4>kL`ai Vw(i%qh05-0acuv7;tX&9e*^AW-Bkbp literal 0 HcmV?d00001 diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db index cb2c8bd26d01c175abe32e879db24b314e9744f3..9d26f5c2b331c909c7878d162ad04f9e51a1df7e 100644 GIT binary patch literal 77824 zcmeI5U2NOd6@W!iKb9Sd`B^KtKg*5L!ZB>R`k^FiL(x(c)p&KB%(l{YSmx0ZZ8MQb zm89Ybedz3V#Rlx54|^?8bi=k3*t)%~PkS)-u=@B^V6AcPwdKmvCrfyia%iMt|6KFM@6y{=wgd~$vDs-|1(i%n%qU93ANC#4lx zT$9P-a#?Kh?2vvVq%6epS8Gl!~fG_3W$tgPFb-Eq1HmrsnUdX)H}W=N!6^%gfZ z^TbIv%$2sT4q!Sb$A>C&$#ko5F1cWCpNJ-Nrf=lKR8itz~f8 zRnznLanWQl$$TeiD;o{f860O9@0GhImX_p$0gsOp*rt}1raDE|_oLG5$3T}3wCZprl?yBK;$zFSlZO=Lki-l$xFWB} z%aXiG2Abrk)na{WhTcy?A9FHU)PBH;U53Q#g@W05q(zXrfy!Y@(JNlB?`${~ToSbByH~N|c_YEY$ zequa4g$1gghm{c;2wv*S`N}b zLK}elY$B3;Wb#9}(-u(h@O^CW;)HV#KmV*l-g%rjyO^7M|2g9ydoRZ=QLiXXtK=u`b-3|* zBLR;9HwEvr^iZA=V=>}k+qOVySt-qcreDdSon; zT;-2~>MeRb?Y$D=J_wA_{_j2+jwTBQX77U2{q=RZa$egq75eXhbxyNv!|aT_7<7Xe zDRV$$Q07P8Tt^f%g3U$KsJCnOCDpWs|91gKi;+n3a^WaOBkNgDkG#wRD2G-Y4&n(C z;Qq}0lKVb)g?p5{FY!U*_lch;zL(felpzT>B!C2v01`j~NB{{S0VIF~kN^_+91xg_ zvtlxn%4Ad7bUL+=&ZUI)^PRzu-@<%qJ~MU9C6mhMQo}M6hh+*vI=3(^Gwzbf<}$fq znV3r^lgp-uWyahxLaI0{6Lrg^QrTgdh)X7&PY<`}Y?wXYI;7mt?w_DIOs?#SZF)GV|$dDz)D9G7lb>$q7Yh+mH<7mdR#@%NYk9jwdz(+&kPp z_e1Vk?rYqa!2O1zxdg(TdN01`j~NB{{S0VIF~kN^@u0!RP}_#p5_R%DJg zAjI9tUfaPjSMreAV8Wg3wHS=MlfA}*m?zm|Cm8c2drSmTce2+y5P5(--|P3$hJmnK zXtYfrbWqVKa{%i~9pKRmdX;JFDw*5GP}Sp$mKF$lvA0!D5dkId`@k)><<0?4=?=(xW7B^_S5$Qf}d$e zv2rAU1dsp{Kmter2_OL^fCP{L5gQxJGT6brnV&P%W> zXN0UMkDIv`ZLJn%k6`!;L9;b?V|G7yEzf>17I zcqx;D)>blQzLc#Lc}YyA60Th9jnw2a3LMET(i^Y_bm1MCX!H`~6 z8k(O{F9mxHvW3(_S*n!zR7M1{#Wau=Dg|B!t`*QYsRD!8_0Rh$_X)<)1g4tJi{*^C zkm1Ye0<^YJmiYy-nB(&@yxT7p%7C}fivjSZxYYk2OT6g#|G5{q%ZYaquX6%70he$? z0!RP}AOR$R1dsp{Kmter2_OL^@Tn1?4sJiDnV91V_hD=qa|C_ZPoh-Nk3l5j2>P&b zgsGq(qeX}c`msZ>RM3xU!SVn5u@zANe<;2l;J(8J5|6?GZb$$LAOR$R1dsp{Kmter z2_OL^a4Q6MzY&Ve?p2xUigHcWjkZP3wRKxHuWF5krf-p^rqgBV=LoDBXTfziGEAcC zYO_OX+e))VQwgkIuiF;s7;OSCch|03#MmUB66eUywpQCFnqD(i#ZsxXN$N^d*;0wJ zrD#z8P{E2`CoR*srqvyJvZLACWLpJix4tzW^y8S`eVC1$-a9i^l??sqwrU#YMu*h9 zCG=~z4Wj6ty62qUD79L<*={Jd+V7aXt=Paouc>6S-Dq^W*VX#m5gq%m4)|(+I2f7P zeUPc1S9E2wVeF6+g>p`_Z8|>Qk#GPh#A>OHMt@i`Inq?FYt42OzIA1ev|9waoXMq} z^LbxE4%e7)@tLveIrX}&!YEc6inVQi-XMzX))@=KjjP2?w|#0VIF~kN^@u0!RP}AOR$R1dsp{ zKmwmVfm7@(<1zh&;_PW=V1HpxvNMd^nh~62i?PwB1;_uN*bi`j<9@@{-~cxyfCP{L z5lHLnTkQHPTYsHrapGHdPvIVQ$guEgCkV>6;C0ONICe)gtx%8(aIY zK>UT(ZnYq9Q`K!nGa*H_Y4pSu6#_R%gP!XUxB=eyx&lEP^a6-k^K~}z5JVURmfF{$ zaTQHh8f3Mlm{$+CZ2x6ar!)7{zz5p2UJKj}XeySaZT8Bix$Dr38VwPcXYUV&&rCA` z2o-=}id9$wU`>U+O9z6GXwwsd))81x6%K9d#X6L z3JD+qB!C2v01`j~NB{{S0VIF~K6eBr*#a}t&=Ii-YMzaB`u4LjVB01`j~NB{{S0VIF~kN^@u0!ZMN2s{@Ij?F$VCxg{$cdBG#oH##05C@^cxxRFESMPp+}3bb zQ(8(*v-fW}qSN4T)*9dmr*j5?_nJDsH^A$yQExYGqO!T!b$V|rZCj;RiM4;D);2Zx zf@uq&(3(>XWbV4u;hl77{Qix3vPv5Q4)&%>OywH10$l8kX@w|l@Mn_^=x5D zTnUjQ{LZ(21cwkT0Hw4{?K*YJ(_~9EuW1kjKtmU7qkRR!5g@SOI?St}L3DuK z#S0)CAdH~0JBkB#CcfB(N5;QqtC z&;5gY_cox0O+W%j00|%gB!C2v01`j~NB{{S0VIF~J`RBp8(>0o$I@MpWdkwl{||!O zAN>E+_kXJQIRW1Z_|WMAIrtp!eVo??JjZZ~8xlYQNB{{S0VIF~kN^@u0!RP}AOR%s z2@;?Y1)sS8-}(Lj2aNsy1jh-BLIOwt2_OL^fCP{L5#YnF#mc delta 1106 zcmZ`&U1(HC6rQN5Q9ofs7f#ugj#6&P+IU|Ura(r3Nb}YQ6!=$AHrq!`TxJwROC;S zi7B^+IhNNSlX#gmVb)rMPuY8#Sch*}O*DdC)`!gfiQK`n)_NMoY3m&p>LmU6msR9( z>G-}+Pt;?-{S0r1e7qJ0l&*~@oFxi4<~FKQ4DpKV(@^z$w}o25_IJc^LcY=1HBcHH zEcc|AqbH`!n67rrJ6QO1us8eJP;WU{T-+Y|f(Kc-!v}hCI`roAy=-rUdTO6_%|U8U zDhOOm(Xah@oE|F&wRZLu_8%w>50#&P*m&1_yi(;T7DcummS{{%zB&>}Y-y|B5|ZM! zpNVU~m=$%eJFrAt&5yM^j=y;`9p8$-h^(`#Gne@wlf|=k3_p_fvLT(%?b+42Gn?6+ z>C9nCHdG(V7Ah@hBk%-nz!~U=wrVuF1+XoCSMl8heuF#kEmWXe@g0EO&6n&Nfd!~t zkJ2Y_davs-!z9q)Qj_@Azjs)XI-#uC@*aU7VG??wRsJjQDfJD>leUvzBLw9Lm4rz5 zjg-t*%gM(Sh3{52MAL-XL)XvRDwkef< zwAxY7w}~l)6}W=FL=lC+hKhQkqYB!xP_{0-+Lo!k1-6!tx~Px3xN<*$Gn44QgkNZ& Pk?_miSV@tg7YF+f0jdF^ diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs b/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs index 8f18894..cc33473 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs @@ -1,24 +1,49 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MyFlib -{ - public static class DataSeeder - { - public static void SeedData(LolDbContext context) +using MyFlib.Entities.enums; +using System; +using System.Collections.Generic; +using System.Diagnostics.Metrics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyFlib +{ + public static class DataSeeder + { + public static void SeedData(LolDbContext context) { - var image1 = new LargeImageEntity { Id = 1, Base64 = "empty" }; - - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity nasus = new ChampionEntity { Name = "Nasus", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity ashe = new ChampionEntity { Name = "Ashe", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", ImageId = 1 }; - - context.AddRange(hecarim, nasus, ashe); - - context.SaveChanges(); - } - } -} + var image1 = new LargeImageEntity { Id = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"), Base64 = "empty" }; + + // Champions + + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity nasus = new ChampionEntity { Name = "Nasus", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity ashe = new ChampionEntity { Name = "Ashe", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + + context.AddRange(hecarim, nasus, ashe); + + // Skins + + SkinEntity darkJhin = new SkinEntity { Name = "Dark Cosmic Jhin", ChampionForeignKey = Guid.Parse("{234F5E7F-F196-4C88-AD1C-6C392AA2E038}"), Description = "In the depths of the universe, serial killer Jhin has found a new form of power in cosmic darkness. With his galaxy mask and strange synergy with the four elements of space, he's never been deadlier.", Icon = "empty", Price = 1820, ImageId = Guid.Parse("{7cc1b02d-29a3-4493-96b7-1e3d9f3e14e2}") }; + SkinEntity kaiSaPrestige = new SkinEntity { Name = "K/DA Kai'Sa Prestige Edition", ChampionForeignKey = Guid.Parse("{15E0C4F4-4C04-4CCE-8F4D-78F37F63E63F}"), Description = "Kai'Sa, the hottest K-pop star of the moment, knows that to make a sensation, you have to be willing to do anything. With her dazzling outfit and electrifying dance moves, she'll make waves on stage and on the battlefield.", Icon = "empty", Price = 2000, ImageId = Guid.Parse("{555c9eb9-f41f-42f1-a05b-ae5d2ee7f782}") }; + SkinEntity pykeProject = new SkinEntity { Name = "PROJECT: Pyke", ChampionForeignKey = Guid.Parse("{F32FA768-A1DC-4F6A-9366-FFEC6B0D4159}"), Description = "Pyke, the ultimate android assassin, has recently been upgraded to carry out the most complex missions. With his new tools and enhanced programming, he can sneak into any security system and eliminate any target.", Icon = "empty", Price = 1350, ImageId = Guid.Parse("{6b47024c-0c1d-4066-bda8-2cb0d7c900fa}") }; + + context.AddRange(darkJhin, kaiSaPrestige, pykeProject); + + // Skills + SkillEntity yasuoTempest = new SkillEntity { Name = "Yasuo's Steel Tempest", Description = " une attaque de mêlée qui peut être chargée pour infliger des dégâts supplémentaires et projeter les ennemis dans les airs.", Type = SkillTypeEntity.Basic }; + SkillEntity LuxFinal = new SkillEntity { Name = "Lux's Final Spark", Description = "une attaque à distance qui inflige des dégâts massifs dans une direction.", Type = SkillTypeEntity.Ultimate }; + + context.AddRange(yasuoTempest, LuxFinal); + + // Runes + + RuneEntity conqueror = new RuneEntity { Name = "Conqueror", Description = "by dealing damage to an enemy champion, you accumulate stacks that, once fully stacked, increase your damage and provide you with healing.", Family = RuneFamilyEntity.Unknown, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + RuneEntity ravenousHunter = new RuneEntity { Name = "Ravenous Hunter", Description = "killing minions, monsters, or enemy champions grants you stacks of Ravenous Hunter, which increase your damage against enemy champions and provide you with healing.", Family = RuneFamilyEntity.Domination, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + + context.AddRange(conqueror, ravenousHunter); + + context.SaveChanges(); + } + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs index 35a11ee..f93cabb 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs @@ -28,7 +28,7 @@ namespace MyFlib public LargeImageEntity Image { get; set; } [ForeignKey("Image")] - public int ImageId { get; set; } + public Guid ImageId { get; set; } } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs index 5882826..b9b3815 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/LargeImageEntity.cs @@ -11,7 +11,7 @@ namespace MyFlib { [Key] - public int Id { get; set; } + public Guid Id { get; set; } public string Base64 { get; set; } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/RuneEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/RuneEntity.cs index 1858a30..595b114 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/RuneEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/RuneEntity.cs @@ -1,4 +1,5 @@ -using System; +using MyFlib.Entities.enums; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -11,16 +12,17 @@ namespace MyFlib public class RuneEntity { [Key] - [MaxLength(256)] + [MaxLength(64)] public string Name { get; set; } [Required] [MaxLength(500)] public string Description { get; set; } - public SkillTypeEntity SkillType { get; set; } + [Required] + public RuneFamilyEntity Family { get; set; } public LargeImageEntity Image { get; set; } [ForeignKey("Image")] - public int ImageId { get; set; } + public Guid ImageId { get; set; } } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs index fa87c23..fb27e82 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkillEntity.cs @@ -10,7 +10,7 @@ namespace MyFlib public class SkillEntity { [Key] - [MaxLength(256)] + [MaxLength(64)] public string Name { get; set; } [Required] diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs index 7524011..4aba605 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/SkinEntity.cs @@ -20,12 +20,11 @@ namespace MyFlib public string Icon { get; set; } [Required] public float Price { get; set; } - [ForeignKey("ChampionForeignKey")] public ChampionEntity Champion { get; set; } public Guid ChampionForeignKey { get; set; } public LargeImageEntity Image { get; set; } [ForeignKey("Image")] - public int ImageId { get; set; } + public Guid ImageId { get; set; } } } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs index f76c708..9667ba4 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/enums/RuneFamilyEntity.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace MyFlib.Entities.enums { - enum RuneFamilyEntity + public enum RuneFamilyEntity { Unknown, Precision, diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index 9ba2246..9acfecc 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -1,4 +1,5 @@ using Microsoft.EntityFrameworkCore; +using MyFlib.Entities.enums; using System; using System.Collections.Generic; using System.Linq; @@ -9,6 +10,7 @@ namespace MyFlib { public class LolDbContext : DbContext { + public DbSet LargeImages { get; set; } public DbSet Champions { get; set; } public DbSet Skills { get; set; } public DbSet Skins { get; set; } @@ -29,21 +31,22 @@ namespace MyFlib protected override void OnModelCreating(ModelBuilder modelBuilder) { //LargeImageEntity - LargeImageEntity image1 = new LargeImageEntity { Id = 1, Base64 = "empty" }; - LargeImageEntity image2 = new LargeImageEntity { Id = 2, Base64 = " " }; + LargeImageEntity image1 = new LargeImageEntity { Id = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"), Base64 = "empty" }; + LargeImageEntity image2 = new LargeImageEntity { Id = Guid.Parse("{9f9086f5-5cc5-47b5-af9b-a935f4e9b89c}"), Base64 = " " }; modelBuilder.Entity().HasData(image1, image2); //ChampionEntity modelBuilder.Entity().HasKey(e => e.Id); + modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); - ChampionEntity Akali = new ChampionEntity { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity Aatrox = new ChampionEntity { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 2 }; - ChampionEntity Ahri = new ChampionEntity { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity Akshan = new ChampionEntity { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity Bard = new ChampionEntity { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity Alistar = new ChampionEntity { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity Akali = new ChampionEntity { Id = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity Aatrox = new ChampionEntity { Id = Guid.Parse("{A4F84D92-C20F-4F2D-B3F9-CA00EF556E72}"), Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = Guid.Parse("{9f9086f5-5cc5-47b5-af9b-a935f4e9b89c}") }; + ChampionEntity Ahri = new ChampionEntity { Id = Guid.Parse("{AE5FE535-F041-445E-B570-28B75BC78CB9}"), Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity Akshan = new ChampionEntity { Id = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity Bard = new ChampionEntity { Id = Guid.Parse("{7f7746fa-b1cb-49da-9409-4b3e6910500e}"), Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity Alistar = new ChampionEntity { Id = Guid.Parse("{36ad2a82-d17b-47de-8a95-6e154a7df557}"), Name = "Alistar", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; modelBuilder.Entity().HasData(Akali, Aatrox, Ahri, Akshan, Bard, Alistar); @@ -55,15 +58,20 @@ namespace MyFlib ); //SkinEntity + modelBuilder.Entity() + .HasOne(m => m.Champion) + .WithMany(a => a.Skins) + .HasForeignKey("ChampionForeignKey"); // not really useful because it is made in the Skin class + modelBuilder.Entity().HasData( - new SkinEntity { Name = "Akali Infernale", ChampionForeignKey = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Description = "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", Icon = "empty", Price = 520, ImageId = 1 }, - new SkinEntity { Name = "Akshan Cyberpop", ChampionForeignKey = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Description = "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", Icon = "empty", Price = 1350, ImageId = 2 } + new SkinEntity { Name = "Akali Infernale", ChampionForeignKey = Guid.Parse("{4422C524-B2CB-43EF-8263-990C3CEA7CAE}"), Description = "Djinn qu'on invoque en dessous du monde, l'Infernale connue sous le nom d'Akali réduira en cendres les ennemis de son maître… mais le prix de son service est toujours exorbitant.", Icon = "empty", Price = 520, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }, + new SkinEntity { Name = "Akshan Cyberpop", ChampionForeignKey = Guid.Parse("{3708dcfd-02a1-491e-b4f7-e75bf274cf23}"), Description = "Les bas-fonds d'Audio City ont un nouveau héros : le Rebelle fluo. Cette position, Akshan la doit à son courage, sa sagesse et sa capacité à s'infiltrer dans des bâtiments d'affaires hautement sécurisés, et ce, sans être repéré. Son charme ravageur l'a aussi beaucoup aidé.", Icon = "empty", Price = 1350, ImageId = Guid.Parse("{9f9086f5-5cc5-47b5-af9b-a935f4e9b89c}") } ); //RuneEntity modelBuilder.Entity().HasData( - new RuneEntity { Name = "Hextech Flashtraption ", Description = "While Flash is on cooldown, it is replaced by Hexflash.", SkillType = SkillTypeEntity.Passive, ImageId = 1 }, - new RuneEntity { Name = "Manaflow Band ", Description = "Hitting enemy champions with a spell grants 25 maximum mana, up to 250 mana.", SkillType = SkillTypeEntity.Basic, ImageId = 2 } + new RuneEntity { Name = "Hextech Flashtraption ", Description = "While Flash is on cooldown, it is replaced by Hexflash.", Family = RuneFamilyEntity.Unknown, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }, + new RuneEntity { Name = "Manaflow Band ", Description = "Hitting enemy champions with a spell grants 25 maximum mana, up to 250 mana.", Family = RuneFamilyEntity.Domination, ImageId = Guid.Parse("{9f9086f5-5cc5-47b5-af9b-a935f4e9b89c}") } ); } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Program.cs b/src/EntityFramework_LoL/Sources/MyFlib/Program.cs index 00d8f3d..b40c873 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Program.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Program.cs @@ -5,6 +5,8 @@ using static System.Console; using (var context = new LolDbContext()) { + WriteLine("\nChampions :\n"); + foreach (var c in context.Champions) { WriteLine($"{c.Name} - {c.Class}"); @@ -16,11 +18,27 @@ using (var context = new LolDbContext()) foreach (var c in context.Champions) { WriteLine($"{c.Name} - {c.Class}"); - foreach (var s in c.Skills) + /* foreach (var s in c.Skills) { WriteLine($"\t\t{s.Name} - {s.Description}"); - } + }*/ + } + + WriteLine("\nSkills :\n"); + + foreach (var c in context.Skills) + { + WriteLine($"{c.Name} - {c.Description} - {c.Type}"); } + WriteLine("\nSkins :\n"); + + foreach (var c in context.Skins) + { + WriteLine($"{c.Name} - {c.Description} - Price: {c.Price} - ChampionId: {c.ChampionForeignKey}"); + } + + WriteLine("\nRunes :\n"); + context.SaveChangesAsync(); // or context.SaveChangesAsync } \ No newline at end of file diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs index 723a3a6..1e5086d 100644 --- a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs @@ -10,15 +10,15 @@ namespace UT_EF public void TestAdd() { var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase(databaseName: "Add_Test_database") + .UseInMemoryDatabase(databaseName: "Add_Test_Champion_database") .Options; using (var context = new LolDbContext(options)) { - ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; // test contrainte ChampionEntity errorName = new ChampionEntity @@ -27,7 +27,7 @@ namespace UT_EF Class = ChampionClassEntity.Mage, Bio = "", Icon = "", - ImageId = 1 + ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); @@ -44,15 +44,15 @@ namespace UT_EF public void Modify_Test() { var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase(databaseName: "Modify_Test_database") + .UseInMemoryDatabase(databaseName: "Modify_Test_Champion_database") .Options; using (var context = new LolDbContext(options)) { - ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); @@ -90,15 +90,15 @@ namespace UT_EF public void Delete_Test() { var options = new DbContextOptionsBuilder() - .UseInMemoryDatabase(databaseName: "Delete_Test_database") + .UseInMemoryDatabase(databaseName: "Delete_Test_Champion_database") .Options; using (var context = new LolDbContext(options)) { - ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = 1 }; - ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = 1 }; + ChampionEntity sylas = new ChampionEntity { Name = "Sylas", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; + ChampionEntity yuumi = new ChampionEntity { Name = "yuumi", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") }; context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/LargeImagesTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/LargeImagesTest.cs new file mode 100644 index 0000000..b3c22ff --- /dev/null +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/LargeImagesTest.cs @@ -0,0 +1,111 @@ +using Microsoft.EntityFrameworkCore; +using MyFlib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UT_EF +{ + public class LargeImagesTest + { + [Fact] + public void TestAdd() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Add_Test_LargeImage_database") + .Options; + + using (var context = new LolDbContext(options)) + { + + LargeImageEntity image1 = new LargeImageEntity { Id = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"), Base64 = "https://fastly.picsum.photos/id/598/2000/2000.jpg?hmac=MReozmZFar5xI7HICmcgvZTP739rBonuoAmpBWE-4XE" }; + LargeImageEntity image2 = new LargeImageEntity { Id = Guid.Parse("{9f9086f5-5cc5-47b5-af9b-a935f4e9b89c}"), Base64 = "https://fastly.picsum.photos/id/788/2000/2000.jpg?hmac=UKqhiA0k3uH3wqqaIYk-o18U1kNPnD_MVq7fLdtW1R8" }; + + context.LargeImages.AddRange(image1, image2); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + Assert.Equal(2, context.LargeImages.Count()); + Assert.Equal("https://fastly.picsum.photos/id/598/2000/2000.jpg?hmac=MReozmZFar5xI7HICmcgvZTP739rBonuoAmpBWE-4XE", context.LargeImages.First().Base64); + } + } + + [Fact] + public void Modify_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Modify_Test_LargeImage_database") + .Options; + + using (var context = new LolDbContext(options)) + { + LargeImageEntity image1 = new LargeImageEntity { Id = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"), Base64 = "https://fastly.picsum.photos/id/598/2000/2000.jpg?hmac=MReozmZFar5xI7HICmcgvZTP739rBonuoAmpBWE-4XE" }; + LargeImageEntity image2 = new LargeImageEntity { Id = Guid.Parse("{9f9086f5-5cc5-47b5-af9b-a935f4e9b89c}"), Base64 = "https://fastly.picsum.photos/id/788/2000/2000.jpg?hmac=UKqhiA0k3uH3wqqaIYk-o18U1kNPnD_MVq7fLdtW1R8" }; + + context.LargeImages.AddRange(image1, image2); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + string linkToFind = "fastly"; + Assert.Equal(2, context.LargeImages.Where(c => c.Base64.ToLower().Contains(linkToFind)).Count()); + linkToFind = "bonuoampbwe"; + Assert.Equal(1, context.LargeImages.Where(c => c.Base64.ToLower().Contains(linkToFind)).Count()); + var ewok = context.LargeImages.Where(c => c.Base64.ToLower().Contains(linkToFind)).First(); + ewok.Base64 = "empty"; + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + string linkToFind = "bonuoampbwe"; + Assert.Equal(0, context.LargeImages.Where(c => c.Base64.ToLower().Contains(linkToFind)).Count()); + linkToFind = "empty"; + Assert.Equal(1, context.LargeImages.Where(c => c.Base64.ToLower().Contains(linkToFind)).Count()); + } + } + + [Fact] + public void Delete_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Delete_Test_LargeImage_database") + .Options; + + using (var context = new LolDbContext(options)) + { + + LargeImageEntity image1 = new LargeImageEntity { Id = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"), Base64 = "https://fastly.picsum.photos/id/598/2000/2000.jpg?hmac=MReozmZFar5xI7HICmcgvZTP739rBonuoAmpBWE-4XE" }; + LargeImageEntity image2 = new LargeImageEntity { Id = Guid.Parse("{9f9086f5-5cc5-47b5-af9b-a935f4e9b89c}"), Base64 = "https://fastly.picsum.photos/id/788/2000/2000.jpg?hmac=UKqhiA0k3uH3wqqaIYk-o18U1kNPnD_MVq7fLdtW1R8" }; + + context.LargeImages.AddRange(image1, image2); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + var ewok = context.LargeImages.First(); + string linkToFind = "bonuoampbwe"; + Assert.Equal(1, context.LargeImages.Where(c => c.Base64.ToLower().Contains(linkToFind)).Count()); + Assert.Equal(2, context.LargeImages.Count()); + context.LargeImages.Remove(ewok); + context.SaveChanges(); + + } + + using (var context = new LolDbContext(options)) + { + string linkToFind = "bonuoampbwe"; + Assert.Equal(0, context.LargeImages.Where(c => c.Base64.ToLower().Contains(linkToFind)).Count()); + Assert.Equal(1, context.LargeImages.Count()); + + } + + } + } +} diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/SkillsTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/SkillsTest.cs new file mode 100644 index 0000000..1fa7c88 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/SkillsTest.cs @@ -0,0 +1,120 @@ +using Microsoft.EntityFrameworkCore; +using MyFlib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UT_EF +{ + public class SkillsTest + { + [Fact] + public void TestAdd() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Add_Test_Skill_database") + .Options; + + using (var context = new LolDbContext(options)) + { + SkillEntity fireBall = new SkillEntity { Name = "Boule de feu", Description = "Fire!", Type = SkillTypeEntity.Basic }; + SkillEntity whiteStar = new SkillEntity { Name = "White Star", Description = "Random damage", Type = SkillTypeEntity.Ultimate }; + SkillEntity yasuoTempest = new SkillEntity { Name = "Yasuo's Steel Tempest", Description = " une attaque de mêlée qui peut être chargée pour infliger des dégâts supplémentaires et projeter les ennemis dans les airs.", Type = SkillTypeEntity.Basic }; + SkillEntity LuxFinal = new SkillEntity { Name = "Lux's Final Spark", Description = "une attaque à distance qui inflige des dégâts massifs dans une direction.", Type = SkillTypeEntity.Ultimate }; + + context.Skills.AddRange(fireBall, whiteStar, yasuoTempest, LuxFinal); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + Assert.Equal(4, context.Skills.Count()); + Assert.Equal("Boule de feu", context.Skills.First().Name); + } + } + + [Fact] + public void Modify_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Modify_Test_Skill_database") + .Options; + + using (var context = new LolDbContext(options)) + { + SkillEntity fireBall = new SkillEntity { Name = "Boule de feu", Description = "Fire!", Type = SkillTypeEntity.Unknown }; + SkillEntity whiteStar = new SkillEntity { Name = "White Star", Description = "Random damage", Type = SkillTypeEntity.Ultimate }; + SkillEntity yasuoTempest = new SkillEntity { Name = "Yasuo's Steel Tempest", Description = " une attaque de mêlée qui peut être chargée pour infliger des dégâts supplémentaires et projeter les ennemis dans les airs.", Type = SkillTypeEntity.Basic }; + SkillEntity LuxFinal = new SkillEntity { Name = "Lux's Final Spark", Description = "une attaque à distance qui inflige des dégâts massifs dans une direction.", Type = SkillTypeEntity.Ultimate }; + + context.Skills.AddRange(fireBall, whiteStar, yasuoTempest, LuxFinal); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + string letterToFind = "a"; + SkillTypeEntity type = SkillTypeEntity.Ultimate; + Assert.Equal(3, context.Skills.Where(c => c.Description.ToLower().Contains(letterToFind)).Count()); + Assert.Equal(2, context.Skills.Where(c => c.Type == type).Count()); + string descriptionToFind = "random"; + Assert.Equal(1, context.Skills.Where(c => c.Description.ToLower().Contains(descriptionToFind)).Count()); + var ewok = context.Skills.Where(c => c.Description.ToLower().Contains(descriptionToFind)).First(); + ewok.Description = "empty"; + ewok.Type = SkillTypeEntity.Basic; + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + string descriptionToFind = "Random"; + Assert.Equal(0, context.Skills.Where(c => c.Description.ToLower().Contains(descriptionToFind)).Count()); + descriptionToFind = "empty"; + SkillTypeEntity type = SkillTypeEntity.Ultimate; + Assert.Equal(1, context.Skills.Where(c => c.Description.ToLower().Contains(descriptionToFind)).Count()); + Assert.Equal(1, context.Skills.Where(c => c.Type == type).Count()); + } + } + + [Fact] + public void Delete_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Delete_Test_Skill_database") + .Options; + + using (var context = new LolDbContext(options)) + { + SkillEntity fireBall = new SkillEntity { Name = "Boule de feu", Description = "Fire!", Type = SkillTypeEntity.Basic }; + SkillEntity whiteStar = new SkillEntity { Name = "White Star", Description = "Random damage", Type = SkillTypeEntity.Ultimate }; + SkillEntity yasuoTempest = new SkillEntity { Name = "Yasuo's Steel Tempest", Description = " une attaque de mêlée qui peut être chargée pour infliger des dégâts supplémentaires et projeter les ennemis dans les airs.", Type = SkillTypeEntity.Basic }; + SkillEntity LuxFinal = new SkillEntity { Name = "Lux's Final Spark", Description = "une attaque à distance qui inflige des dégâts massifs dans une direction.", Type = SkillTypeEntity.Ultimate }; + + context.Skills.AddRange(fireBall, whiteStar, yasuoTempest, LuxFinal); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + var ewok = context.Skills.First(); + string nameToFind = "boule de feu"; + Assert.Equal(1, context.Skills.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(4, context.Skills.Count()); + context.Skills.Remove(ewok); + context.SaveChanges(); + + } + + using (var context = new LolDbContext(options)) + { + string nameToFind = "Boule de feu"; + Assert.Equal(0, context.Skills.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(3, context.Skills.Count()); + + } + + } + } +} diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/SkinsTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/SkinsTest.cs new file mode 100644 index 0000000..c6a83a0 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/SkinsTest.cs @@ -0,0 +1,116 @@ +using Microsoft.EntityFrameworkCore; +using MyFlib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UT_EF +{ + public class SkinsTest + { + [Fact] + public void TestAdd() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Add_Test_Skin_database") + .Options; + + using (var context = new LolDbContext(options)) + { + + SkinEntity darkJhin = new SkinEntity { Name = "Dark Cosmic Jhin", ChampionForeignKey = Guid.Parse("{234F5E7F-F196-4C88-AD1C-6C392AA2E038}"), Description = "In the depths of the universe, serial killer Jhin has found a new form of power in cosmic darkness. With his galaxy mask and strange synergy with the four elements of space, he's never been deadlier.", Icon = "empty", Price = 1820, ImageId = Guid.Parse("{7cc1b02d-29a3-4493-96b7-1e3d9f3e14e2}") }; + SkinEntity kaiSaPrestige = new SkinEntity { Name = "K/DA Kai'Sa Prestige Edition", ChampionForeignKey = Guid.Parse("{15E0C4F4-4C04-4CCE-8F4D-78F37F63E63F}"), Description = "Kai'Sa, the hottest K-pop star of the moment, knows that to make a sensation, you have to be willing to do anything. With her dazzling outfit and electrifying dance moves, she'll make waves on stage and on the battlefield.", Icon = "empty", Price = 2000, ImageId = Guid.Parse("{555c9eb9-f41f-42f1-a05b-ae5d2ee7f782}") }; + SkinEntity pykeProject = new SkinEntity { Name = "PROJECT: Pyke", ChampionForeignKey = Guid.Parse("{F32FA768-A1DC-4F6A-9366-FFEC6B0D4159}"), Description = "Pyke, the ultimate android assassin, has recently been upgraded to carry out the most complex missions. With his new tools and enhanced programming, he can sneak into any security system and eliminate any target.", Icon = "empty", Price = 1350, ImageId = Guid.Parse("{6b47024c-0c1d-4066-bda8-2cb0d7c900fa}") }; + + context.Skins.AddRange(darkJhin, kaiSaPrestige, pykeProject); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + Assert.Equal(3, context.Skins.Count()); + Assert.Equal("Dark Cosmic Jhin", context.Skins.First().Name); + } + } + + [Fact] + public void Modify_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Modify_Test_Skin_database") + .Options; + + using (var context = new LolDbContext(options)) + { + + SkinEntity darkJhin = new SkinEntity { Name = "Dark Cosmic Jhin", ChampionForeignKey = Guid.Parse("{234F5E7F-F196-4C88-AD1C-6C392AA2E038}"), Description = "In the depths of the universe, serial killer Jhin has found a new form of power in cosmic darkness. With his galaxy mask and strange synergy with the four elements of space, he's never been deadlier.", Icon = "empty", Price = 1820, ImageId = Guid.Parse("{7cc1b02d-29a3-4493-96b7-1e3d9f3e14e2}") }; + SkinEntity kaiSaPrestige = new SkinEntity { Name = "K/DA Kai'Sa Prestige Edition", ChampionForeignKey = Guid.Parse("{15E0C4F4-4C04-4CCE-8F4D-78F37F63E63F}"), Description = "Kai'Sa, the hottest K-pop star of the moment, knows that to make a sensation, you have to be willing to do anything. With her dazzling outfit and electrifying dance moves, she'll make waves on stage and on the battlefield.", Icon = "empty", Price = 2000, ImageId = Guid.Parse("{555c9eb9-f41f-42f1-a05b-ae5d2ee7f782}") }; + SkinEntity pykeProject = new SkinEntity { Name = "PROJECT: Pyke", ChampionForeignKey = Guid.Parse("{F32FA768-A1DC-4F6A-9366-FFEC6B0D4159}"), Description = "Pyke, the ultimate android assassin, has recently been upgraded to carry out the most complex missions. With his new tools and enhanced programming, he can sneak into any security system and eliminate any target.", Icon = "empty", Price = 1350, ImageId = Guid.Parse("{6b47024c-0c1d-4066-bda8-2cb0d7c900fa}") }; + + context.Skins.AddRange(darkJhin, kaiSaPrestige, pykeProject); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + string letterToFind = "i"; + Assert.Equal(3, context.Skins.Where(c => c.Description.ToLower().Contains(letterToFind)).Count()); + letterToFind = "depths"; + Assert.Equal(1, context.Skins.Where(c => c.Description.ToLower().Contains(letterToFind)).Count()); + var ewok = context.Skins.Where(c => c.Description.ToLower().Contains(letterToFind)).First(); + ewok.Description = "For test"; + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + string nameToFind = "depths"; + Assert.Equal(0, context.Skins.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + string descriptionToFind = "for test"; + Assert.Equal(1, context.Skins.Where(c => c.Description.ToLower().Contains(descriptionToFind)).Count()); + } + } + + [Fact] + public void Delete_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Delete_Test_Skin_database") + .Options; + + using (var context = new LolDbContext(options)) + { + + SkinEntity darkJhin = new SkinEntity { Name = "Dark Cosmic Jhin", ChampionForeignKey = Guid.Parse("{234F5E7F-F196-4C88-AD1C-6C392AA2E038}"), Description = "In the depths of the universe, serial killer Jhin has found a new form of power in cosmic darkness. With his galaxy mask and strange synergy with the four elements of space, he's never been deadlier.", Icon = "empty", Price = 1820, ImageId = Guid.Parse("{7cc1b02d-29a3-4493-96b7-1e3d9f3e14e2}") }; + SkinEntity kaiSaPrestige = new SkinEntity { Name = "K/DA Kai'Sa Prestige Edition", ChampionForeignKey = Guid.Parse("{15E0C4F4-4C04-4CCE-8F4D-78F37F63E63F}"), Description = "Kai'Sa, the hottest K-pop star of the moment, knows that to make a sensation, you have to be willing to do anything. With her dazzling outfit and electrifying dance moves, she'll make waves on stage and on the battlefield.", Icon = "empty", Price = 2000, ImageId = Guid.Parse("{555c9eb9-f41f-42f1-a05b-ae5d2ee7f782}") }; + SkinEntity pykeProject = new SkinEntity { Name = "PROJECT: Pyke", ChampionForeignKey = Guid.Parse("{F32FA768-A1DC-4F6A-9366-FFEC6B0D4159}"), Description = "Pyke, the ultimate android assassin, has recently been upgraded to carry out the most complex missions. With his new tools and enhanced programming, he can sneak into any security system and eliminate any target.", Icon = "empty", Price = 1350, ImageId = Guid.Parse("{6b47024c-0c1d-4066-bda8-2cb0d7c900fa}") }; + + context.Skins.AddRange(darkJhin, kaiSaPrestige, pykeProject); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + var ewok = context.Skins.First(); + string nameToFind = "jhin"; + Assert.Equal(1, context.Skins.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(3, context.Skins.Count()); + context.Skins.Remove(ewok); + context.SaveChanges(); + + } + + using (var context = new LolDbContext(options)) + { + string nameToFind = "jhin"; + Assert.Equal(0, context.Skins.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(2, context.Skins.Count()); + + } + + } + } +} +