From 0bdef0bc74aa2b123de505040dcdc45e10a980f1 Mon Sep 17 00:00:00 2001 From: "emre.kartal" Date: Sat, 11 Mar 2023 10:33:33 +0100 Subject: [PATCH] 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`+#&+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%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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gY_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()); + + } + + } + } +} +