From 1c0bcaa52f67c963ebe16e882dd097a20adf7db8 Mon Sep 17 00:00:00 2001 From: Emre Date: Wed, 8 Feb 2023 19:43:06 +0100 Subject: [PATCH] Add UT for delete champion and add seedData --- .vs/API/v17/.suo | Bin 11264 -> 13824 bytes README.md | 3 +- .../Sources/MyFlib/DataBase.db | Bin 20480 -> 24576 bytes .../Sources/MyFlib/DataSeeder.cs | 22 ++++ .../Sources/MyFlib/Entities/ChampionEntity.cs | 6 +- .../Sources/MyFlib/LolDbContext.cs | 12 +- .../20230204131532_MyMigration.Designer.cs | 114 ------------------ .../Migrations/20230204131532_MyMigration.cs | 53 -------- .../Migrations/LolDbContextModelSnapshot.cs | 111 ----------------- .../Sources/MyFlib/Program.cs | 11 +- .../Sources/Tests/UT_EF/ChampionsTest.cs | 55 +++++++-- 11 files changed, 91 insertions(+), 296 deletions(-) create mode 100644 src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs delete mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230204131532_MyMigration.Designer.cs delete mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230204131532_MyMigration.cs delete mode 100644 src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs diff --git a/.vs/API/v17/.suo b/.vs/API/v17/.suo index 76b671db3e0d26f4ae200fe998cd6f31631e63a1..064ca0b7cb5408ee9dd9f5b7a35b18b41eefee80 100644 GIT binary patch delta 1503 zcmb_c&rcIk5PrMe%35AaDQzi~2o_=~W|Qp?XtzRKr5X$fC2FFk2U=+p6XHQjA{b*6 zJ@%kG@gLwnz$P9{Jn6v$37B}%gLh+0Jb=-}fHO-Mih*F%X=nHCx8J^*_szUlxmuZf zJS^CkM_NRI!*Q|OHIq4){Cw)Y5MYeyO|U2~3SF=vPQoiOYIh-c3l?nSd<#v)C%VI1 zPoFc04@c0+WDuk_!y!fKEg45}b9=bu!Lb|tD7q7!;8wiT+?!9P+wC1VXojfVzC80t zFvJOrPl@T@GJlhp5QL4UZpg@9pARQ)L8plAc&F$Tv6Vs-NGa}(?iltFXn7kFz34s| zarD;ax~hV4IOEuu+*}VpN(r4X@0#MYe2PhC!hYCrO*#dd-rqona!b}!n=-b@oJ9P9 zPG;~7CxM&LEdo^fCAiBcxP+i%&x?Qr-+5NHHG*a5yZ@e}-ORD}qkCL5^QRhH=@|h@ zh`~Z=oZAt#YCH(4Nt}_4eeb^Rj71e=XfR{V^cAbgr$O?o-t1Qg3g2;Ub$`6DOfva7xk|3 z&N^)u^sRtCpo1Q%xIe7G$>-rOpZp)I(#xk0mtfle)d*!cZAR)C>!ZCb(pdL{TBJ7% zuSFHsd$XK6s;gl#D7)9Vi~yZbRs<-wR*iwmfmto}OGe0DbGsA5{@;2>_Z483j!G!| zszwhIeqUFu+*1{v1teSe1m-fz(k#cWusf{CZsRq_=Ii4eJHxW<0?Xmy=L0=>v6(ud W-l^~+cs``E-5Es8gZuXwh$rl;3SiI?>GPdc(1(W#sb&*$^`N+#MM9!qU=W|+azIr^#>0sTKV>=TaovtqS1e-h+A+H&5RFWG|EEJ zDI--uGOS{|nuL^Q`p@?`ob?yD3Dwvnm@&<-?eb>Y(WoRM>XHw^npu`Kn;3EkLoubm zce4V{j026qk6PGD$7dMUjIxZNee}FfdmeoZ7aq>sgSYVqk_w{M!=Nh7DBn7rcDWo0 z@K6W!8}FKSNsb~;gYV+)aRt`xCz3Xi?kT3Ah>D-K0|z1p^=qGXMypKqEV59)ek8{N zpc}8AIc#~iJPt31iy!8dNSs_s>@Iu39gNb|wa>9UO{^{*m)bW6g`>cW{v+Oln zWh)){A_Tkn#b#`wJ8$XNc6ifp{_E@#u8`+XkM=>M;91zPTsW|EaBP)zPDeuH?)5!c tkvan54R;)m5hM%yf@SvT^7UAyt5ZLQeKB`c>XE-wt8`Gw*6Gct@*B|(Ha!3U diff --git a/README.md b/README.md index 06487b4..53081bc 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,8 @@ Et enfin cliquer sur l'icône ci-dessous pour faire la connexion à la solution -Vous pouvez dorénavant voir toutes les tables qui y sont enregistrées ! +Vous pouvez dorénavant voir toutes les tables qui y sont enregistrées ! Si vous souhaitez ajouter des modifications à la base de données et les visualiser, +réaliser à nouveau la migration (ou *updater* celui actuel), puis supprimer toutes les tables et lancer la commande : **dotnet ef database update** et enfin rafraichiser la BD ! :information_source: *Notez qu'il est également possible grâce à SQLLite d'ajouter, modifier ou supprimer des données dans les tables.* diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db index d146bd75f1ea62bf6e77ac0f2653cb25ce37d487..2553478a6f1132b671abf415c17cf66a8a22b24f 100644 GIT binary patch literal 24576 zcmeI)!EW0&7yw|&vSmAgtX&GD=z<8oEJe$Jq9{|kjgqL=XyRn4Jv0~!Lrc8GXl$>x z1GLy_8?bY41@;m<=NX3Gci3rfuqW6^$8nY*?tBJ1lMX&ej(i!SxEqeVB2PqOj2=E#bPCt`12VQb~#Zr-du zdZeE#j9;I~F;{2YeSO*;9CWXp7Osd~ySOos&3P$=t(9CqK#46@V7aC(0E#5?Z%;meV#URVDn-@hmn ztBmPC>`Y-g9g%MLjz-x;^}DCN@nkr9dt+qoD%g!_F1zLYp8wfD7u@KEzPdXa9-bad zzU+?1va;7YpzK8r)2zN^i&Snbr{mrjt;X~vrDe&W+ka^C0~-i{00@8p2!H?xfB*=9 z00@8p2!OyX6sYM2uM$i=OmN@^9&`Op|LuI@f^FhWGHaHa56H=&-uJ6_{jh-m2!H?x zfB*=900@8p2!H?xfB*>GDuFeFmlsb0sQ3Tn3f1gi?e})q_9}l@eyjXkIhIkdfdB}A z00@8p2!H?xfB*=900`W10a7luA6S-E4pS0RHz0`dgd*yvAqsI2AfH9tO-T|biFn#Q z$VRN$dm1fImROO{kmX;XOq$JO%CU0rLdGST2DEO z+&DrsOgIWD4rLWRQ4d}0%dAm0IxJx0yeVZ$35k6|QAAV@PoyXybq|Fhj=flL7IVR0 zWhXt7o7Kx>I7s3&L6}G+8oIJ2G-XK0cBF*SIF*jC#>d$p@9F1{Mfd7FAzVI|#AUJ+ zmIxH^&_{LQ`joRoHiz*O`AvvyWUBGM{L;T>|22K@f3XhWj`whAJ_vvS2!H?xfB*=9 z00@8p2!H?xd^CYo)11zrOs5no1yfDI=yDuiGVbXr&RjJfsB<;0FRU2%_1U~Y*{I4x zIjLZ%l(PD^e)+2jEAqTtd8bwWw12mMv45(Z*)J>aY-+E5w01(lAOHd&00JNY0w4ea zAOHd&00MVFV8dwZ%PcD>tAxv}B`B$c%Pb)%s)Wld95AN|msl@QPzje=B#>7LmsuNN SsD#Tb3CMkBw9Ct^1Na9IkNHmk delta 314 zcmZoTz}T>Wae}m<5Ca1PD-gqg&_o?$Q6UDscqv}~9}FzK=?r|A_}B98-jAOluQf_j7*J;;(aT9 zGt-L_OEUBG%=HZPjJSaIF!DcQ;C}=(?lk|z0A3?mW=BpV10!PtBLghDc!3(&_?I&9 zf8u|{e}(@D|2F=mK&=z`lla-#8Kil6c^MsZGK)(Ri`aNr*%?GZ0#1oVDXe@f>FnZ+#5@)rW~i)VMo}g+9}`SAv7{)!f{BNbok1L^n$s~mF((sbDI@>K&Fl`Z`1yGm RndKRsGZJ$PfSxF30|525NLBy< diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs b/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs new file mode 100644 index 0000000..eeb743a --- /dev/null +++ b/src/EntityFramework_LoL/Sources/MyFlib/DataSeeder.cs @@ -0,0 +1,22 @@ +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) + { + ChampionEntity hecarim = new ChampionEntity { Name = "Hecarim", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }; + ChampionEntity nasus = new ChampionEntity { Name = "Nasus", Class = ChampionClassEntity.Tank, Bio = "", Icon = "", Image = "" }; + ChampionEntity ashe = new ChampionEntity { Name = "Ashe", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = "" }; + + context.AddRange(hecarim, nasus, ashe); + + context.SaveChanges(); + } + } +} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs index 98313cf..dbd29c1 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Entities/ChampionEntity.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; @@ -10,14 +11,13 @@ namespace MyFlib public class ChampionEntity { [Key] - public int Id { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public Guid Id { get; set; } [MaxLength(255)] public string Name { get; set; } [MaxLength(255)] public string Bio { get; set; } - [MaxLength(255)] public string Icon { get; set; } - [MaxLength(255)] public string Image { get; set; } public ChampionClassEntity Class { get; set; } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index 8b78047..5ff7132 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -28,12 +28,12 @@ namespace MyFlib modelBuilder.Entity().HasKey(e => e.Id); modelBuilder.Entity().Property(e => e.Id).ValueGeneratedOnAdd(); modelBuilder.Entity().HasData( - new ChampionEntity { Id = 1, Name = "Akali", Class = ChampionClassEntity.Assassin, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = 2, Name = "Aatrox", Class = ChampionClassEntity.Fighter, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = 3, Name = "Ahri", Class = ChampionClassEntity.Mage, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = 4, Name = "Akshan", Class = ChampionClassEntity.Marksman, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = 5, Name = "Bard", Class = ChampionClassEntity.Support, Bio = "", Icon = "", Image = "" }, - new ChampionEntity { Id = 6, 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 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 = "" } ); } diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230204131532_MyMigration.Designer.cs b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230204131532_MyMigration.Designer.cs deleted file mode 100644 index 8cfaffe..0000000 --- a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230204131532_MyMigration.Designer.cs +++ /dev/null @@ -1,114 +0,0 @@ -// -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("20230204131532_MyMigration")] - partial class MyMigration - { - /// - 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("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.Property("Class") - .HasColumnType("INTEGER"); - - b.Property("Icon") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.Property("Image") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champions"); - - b.HasData( - new - { - Id = 1, - Bio = "", - Class = 1, - Icon = "", - Image = "", - Name = "Akali" - }, - new - { - Id = 2, - Bio = "", - Class = 2, - Icon = "", - Image = "", - Name = "Aatrox" - }, - new - { - Id = 3, - Bio = "", - Class = 3, - Icon = "", - Image = "", - Name = "Ahri" - }, - new - { - Id = 4, - Bio = "", - Class = 4, - Icon = "", - Image = "", - Name = "Akshan" - }, - new - { - Id = 5, - Bio = "", - Class = 5, - Icon = "", - Image = "", - Name = "Bard" - }, - new - { - Id = 6, - Bio = "", - Class = 6, - Icon = "", - Image = "", - Name = "Alistar" - }); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230204131532_MyMigration.cs b/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230204131532_MyMigration.cs deleted file mode 100644 index 2480c4e..0000000 --- a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/20230204131532_MyMigration.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace MyFlib.Migrations -{ - /// - public partial class MyMigration : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Champions", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Name = table.Column(type: "TEXT", maxLength: 255, nullable: false), - Bio = table.Column(type: "TEXT", maxLength: 255, nullable: false), - Icon = table.Column(type: "TEXT", maxLength: 255, nullable: false), - Image = table.Column(type: "TEXT", maxLength: 255, nullable: false), - Class = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Champions", x => x.Id); - }); - - migrationBuilder.InsertData( - table: "Champions", - columns: new[] { "Id", "Bio", "Class", "Icon", "Image", "Name" }, - values: new object[,] - { - { 1, "", 1, "", "", "Akali" }, - { 2, "", 2, "", "", "Aatrox" }, - { 3, "", 3, "", "", "Ahri" }, - { 4, "", 4, "", "", "Akshan" }, - { 5, "", 5, "", "", "Bard" }, - { 6, "", 6, "", "", "Alistar" } - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Champions"); - } - } -} 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 76cb456..0000000 --- a/src/EntityFramework_LoL/Sources/MyFlib/Migrations/LolDbContextModelSnapshot.cs +++ /dev/null @@ -1,111 +0,0 @@ -// -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("INTEGER"); - - b.Property("Bio") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.Property("Class") - .HasColumnType("INTEGER"); - - b.Property("Icon") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.Property("Image") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(255) - .HasColumnType("TEXT"); - - b.HasKey("Id"); - - b.ToTable("Champions"); - - b.HasData( - new - { - Id = 1, - Bio = "", - Class = 1, - Icon = "", - Image = "", - Name = "Akali" - }, - new - { - Id = 2, - Bio = "", - Class = 2, - Icon = "", - Image = "", - Name = "Aatrox" - }, - new - { - Id = 3, - Bio = "", - Class = 3, - Icon = "", - Image = "", - Name = "Ahri" - }, - new - { - Id = 4, - Bio = "", - Class = 4, - Icon = "", - Image = "", - Name = "Akshan" - }, - new - { - Id = 5, - Bio = "", - Class = 5, - Icon = "", - Image = "", - Name = "Bard" - }, - new - { - Id = 6, - Bio = "", - Class = 6, - Icon = "", - Image = "", - Name = "Alistar" - }); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/EntityFramework_LoL/Sources/MyFlib/Program.cs b/src/EntityFramework_LoL/Sources/MyFlib/Program.cs index 3e22f35..0da5a3c 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/Program.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/Program.cs @@ -6,7 +6,16 @@ using (var context = new LolDbContext()) foreach (var c in context.Champions) { - Console.WriteLine($"{c.Name} - {c.Bio}"); + Console.WriteLine($"{c.Name} - {c.Class}"); } + + Console.WriteLine("\nWith new Champions :\n"); + + DataSeeder.SeedData(context); + foreach (var c in context.Champions) + { + Console.WriteLine($"{c.Name} - {c.Class}"); + } + 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 1f99d6a..fd66059 100644 --- a/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/ChampionsTest.cs @@ -1,4 +1,3 @@ - using Microsoft.EntityFrameworkCore; using MyFlib; using Xunit; @@ -20,9 +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 = "" }; - context.Champions.Add(sylas); - context.Champions.Add(hecarim); - context.Champions.Add(yuumi); + context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); } @@ -46,20 +43,22 @@ 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.Add(sylas); - context.Champions.Add(hecarim); - context.Champions.Add(yuumi); + context.Champions.AddRange(sylas, hecarim, yuumi); context.SaveChanges(); } using (var context = new LolDbContext(options)) { string nameToFind = "m"; + ChampionClassEntity type = ChampionClassEntity.Fighter; Assert.Equal(2, context.Champions.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(1, context.Champions.Where(c => c.Class == type).Count()); nameToFind = "yuu"; Assert.Equal(1, context.Champions.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); var ewok = context.Champions.Where(c => c.Name.ToLower().Contains(nameToFind)).First(); ewok.Name = "Garen"; + ewok.Bio = "Magic resist"; + ewok.Class = type; context.SaveChanges(); } @@ -68,8 +67,50 @@ namespace UT_EF string nameToFind = "m"; Assert.Equal(1, context.Champions.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); nameToFind = "garen"; + string bioToFind = "magic resist"; + ChampionClassEntity type = ChampionClassEntity.Fighter; + Assert.Equal(1, context.Champions.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(1, context.Champions.Where(c => c.Bio.ToLower().Contains(bioToFind)).Count()); + Assert.Equal(2, context.Champions.Where(c => c.Class == type).Count()); + } + } + + [Fact] + public void Delete_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Delete_Test_database") + .Options; + + 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 = "" }; + + context.Champions.AddRange(sylas, hecarim, yuumi); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + var ewok = context.Champions.First(); + string nameToFind = "sylas"; Assert.Equal(1, context.Champions.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(3, context.Champions.Count()); + context.Champions.Remove(ewok); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + string nameToFind = "sylas"; + Assert.Equal(0, context.Champions.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(2, context.Champions.Count()); + + } + } } } \ No newline at end of file