From 82984ee4d6b562ae833145a03fc9af90d6c9657a Mon Sep 17 00:00:00 2001 From: Emre Date: Sun, 19 Mar 2023 11:59:51 +0100 Subject: [PATCH] Added more UT for the Entities :+1: --- .../Sources/MyFlib/DataBase.db | Bin 131072 -> 131072 bytes .../Sources/MyFlib/LolDbContext.cs | 2 +- .../Sources/Tests/UT_EF/RunePagesTest.cs | 82 ++++++++++++ .../Sources/Tests/UT_EF/RunesTest.cs | 121 ++++++++++++++++++ 4 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 src/EntityFramework_LoL/Sources/Tests/UT_EF/RunePagesTest.cs create mode 100644 src/EntityFramework_LoL/Sources/Tests/UT_EF/RunesTest.cs diff --git a/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db b/src/EntityFramework_LoL/Sources/MyFlib/DataBase.db index 3dcabb2bae26f5c90a464576cc24af0bdd1daae8..59a1e3911cadba4db5b050e974c66d7b91eca2ac 100644 GIT binary patch delta 1915 zcmb`IU2GIp6vywGnVs2>nYp_y?X>KcT^0gepv`V81*`(4=|dx=Euj=bv6N*48`^^G zF4$JeHl#vg(o#mb7?p~RltjZSW3n+wAW=gIny7?mAN;6_4w9X^aOil4^$d;kOYAc#{hdF1~b5|&lD=md4;|~=;Z8YSW6tb1?eV)**9@$^x68r zt~Carw>H|bCGu?Tx|Zr~t-D&o@yM=dEFKNBP&eeVwgjjwnE;tojw5C9MBO~5oZe>cn%1Nox%q{fc#fdakQrr`P3Q)!_KaydbKd0Am5!SW+OF(bC6 zKZrmCL_#clU4Xs27v?n3}$;}3$ zV9AYT3TxjP-O&-VhwP$;*~~4+6^(-?T~)jAB{Et&D|^SS9pHgC*jw#zOso|}ZR4U$ z+&G~=4Sb=zQzO*XXX2>4xEH;Bku^y5z$xZWvX*_heluaZLM%R|^fLahBh zGH$qnV~TB!C^hCO3N-4^+?{Rs`@aXLNF9WJMN{;7x{*Fc9k}qesvkNguuYd>HY@%F z0($e%Nr|I`(1R4y@09KA(CiEwI*>G*TK-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t@L0S zonVLAfK~)-k{u-jS|LX{&1=IT0s<*Vdm2_!iLSTe@`I?#NQ!j01jg!vHZ8gVn*uma zFR7%EDLIv!B7g;82T=%hkqt}FODVtuWYO3JbWVgr1y3t7DNJ$FFlR{-XYJEADHHoc z=yg}XEuLY-kHrt6biO8@fx=l9H`TJu=%Ms;V>W?4FXFg`YzWP!mYw);Jz9mMg31W| zim4XYch7I|E2<`{yQ@_9W%p%%g`m2h^xR-y;r{VRi`!?O!re+-2>1r>ezg*Au^IZ!9t+QqML5&60MKu>iIVm@maqt{OjS}8*FSuV{Ntk7iQyQnqb4ar=Ux; z#l1E0lN{RPdWze}2<%CwiV;5GukqjGmwS@#D0`DVIemdF{IMsYlJ~RL?{w7U962o3 zK;PxuA2Bz~_t>NK;YAA<(H99_Z(=~<*? zu0v0AW5W!5M`8X#En}pIaLU62U_Dm$rvzcx>Lsk^hS)JhS4WrV420#PbYv zNpFjn#q*G~-w`Lyzk>GFoay6h=^>Mf2yoLQ7iVo7LG@Pj99rr2!aF~){~X#YT4yh! zmDcsQQ0N)A*v>##enRXQ+r@GFq`C|Qm%~k!(dWjg=Q{We!cBiM-1QS1&Y=boxoH!> z%KFAQDqrA!g=(Nn=%3a(4gjAQKNE1i^^4c(IpD!J?u9vP*R0aT(T07-j``RPleNb0 tpd^$xFztlB6c`7KHQ7Msb=+{z_qbt$nh$!mnN14q?U6{gb@>k3^j}rR@(ut1 diff --git a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs index 845f521..2675f56 100644 --- a/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs +++ b/src/EntityFramework_LoL/Sources/MyFlib/LolDbContext.cs @@ -18,7 +18,7 @@ namespace MyFlib public DbSet Runes { get; set; } public DbSet CategoryRunes { get; set; } public DbSet RunePages { get; set; } - + public DbSet Characteristic { get; set; } public LolDbContext() { } diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/RunePagesTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/RunePagesTest.cs new file mode 100644 index 0000000..966846d --- /dev/null +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/RunePagesTest.cs @@ -0,0 +1,82 @@ +using Microsoft.EntityFrameworkCore; +using MyFlib; +using MyFlib.Entities; +using MyFlib.Entities.enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UT_EF +{ + public class RunePagesTest + { + [Fact] + public void TestAdd() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Add_Test_RunePage_database") + .Options; + + using (var context = new LolDbContext(options)) + { + RuneEntity runeHextech = 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}") }; + RunePageEntity page1 = new RunePageEntity { Name = "Page 1" }; + RunePageEntity page2 = new RunePageEntity { Name = "Page 2" }; + DictionaryCategoryRune dictionary = new DictionaryCategoryRune { category = CategoryEntity.Major, RuneName = runeHextech.Name, RunePageName = page1.Name }; + + context.CategoryRunes.Add(dictionary); + context.RunePages.AddRange(page1, page2); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + Assert.Equal(2, context.RunePages.Count()); + Assert.Equal("Page 1", context.RunePages.First().Name); + } + } + + [Fact] + public void Delete_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Delete_Test_RunePage_database") + .Options; + + using (var context = new LolDbContext(options)) + { + + RuneEntity runeHextech = 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}") }; + RunePageEntity page1 = new RunePageEntity { Name = "Page 1" }; + RunePageEntity page2 = new RunePageEntity { Name = "Page 2" }; + DictionaryCategoryRune dictionary = new DictionaryCategoryRune { category = CategoryEntity.Major, RuneName = runeHextech.Name, RunePageName = page1.Name }; + + context.CategoryRunes.Add(dictionary); + context.RunePages.AddRange(page1, page2); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + var ewok = context.RunePages.First(); + string nameToFind = "1"; + Assert.Equal(1, context.RunePages.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(2, context.RunePages.Count()); + context.RunePages.Remove(ewok); + context.SaveChanges(); + + } + + using (var context = new LolDbContext(options)) + { + string nameToFind = "1"; + Assert.Equal(0, context.RunePages.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(1, context.RunePages.Count()); + + } + + } + } +} diff --git a/src/EntityFramework_LoL/Sources/Tests/UT_EF/RunesTest.cs b/src/EntityFramework_LoL/Sources/Tests/UT_EF/RunesTest.cs new file mode 100644 index 0000000..6b004d5 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/Tests/UT_EF/RunesTest.cs @@ -0,0 +1,121 @@ +using Microsoft.EntityFrameworkCore; +using MyFlib; +using MyFlib.Entities.enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UT_EF +{ + public class RunesTest + { + [Fact] + public void TestAdd() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Add_Test_Rune_database") + .Options; + + using (var context = new LolDbContext(options)) + { + 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}") }; + RuneEntity electrocute = new RuneEntity { Name = "Electrocute", Description = "hitting an enemy champion with 3 separate attacks or abilities within 3 seconds deals bonus damage.", Family = RuneFamilyEntity.Domination, ImageId = Guid.Parse("{e7c87f12-2c7b-44d5-8867-eba1ae5a4657}") }; + RuneEntity pressTheAttack = new RuneEntity { Name = "Press the Attack", Description = "hitting an enemy champion with 3 consecutive basic attacks deals bonus damage and makes them take increased damage from all sources for a short period of time.", Family = RuneFamilyEntity.Precision, ImageId = Guid.Parse("{7c354729-5ecf-43d8-ae73-153740e87644}") }; + + context.Runes.AddRange(conqueror, ravenousHunter, electrocute, pressTheAttack); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + Assert.Equal(4, context.Runes.Count()); + Assert.Equal("Conqueror", context.Runes.First().Name); + } + } + + [Fact] + public void Modify_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Modify_Test_Rune_database") + .Options; + + using (var context = new LolDbContext(options)) + { + 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}") }; + RuneEntity electrocute = new RuneEntity { Name = "Electrocute", Description = "hitting an enemy champion with 3 separate attacks or abilities within 3 seconds deals bonus damage.", Family = RuneFamilyEntity.Domination, ImageId = Guid.Parse("{e7c87f12-2c7b-44d5-8867-eba1ae5a4657}") }; + RuneEntity pressTheAttack = new RuneEntity { Name = "Press the Attack", Description = "hitting an enemy champion with 3 consecutive basic attacks deals bonus damage and makes them take increased damage from all sources for a short period of time.", Family = RuneFamilyEntity.Precision, ImageId = Guid.Parse("{7c354729-5ecf-43d8-ae73-153740e87644}") }; + + context.Runes.AddRange(conqueror, ravenousHunter, electrocute, pressTheAttack); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + string bioToFind = "stacks"; + RuneFamilyEntity type = RuneFamilyEntity.Domination; + Assert.Equal(2, context.Runes.Where(c => c.Description.ToLower().Contains(bioToFind)).Count()); + Assert.Equal(2, context.Runes.Where(c => c.Family == type).Count()); + bioToFind = "dealing damage"; + Assert.Equal(1, context.Runes.Where(c => c.Description.ToLower().Contains(bioToFind)).Count()); + var ewok = context.Runes.Where(c => c.Description.ToLower().Contains(bioToFind)).First(); + ewok.Description = "Rune resist"; + ewok.Family = type; + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + string bioToFind = "stacks"; + Assert.Equal(1, context.Runes.Where(c => c.Description.ToLower().Contains(bioToFind)).Count()); + bioToFind = "rune resist"; + RuneFamilyEntity type = RuneFamilyEntity.Domination; + Assert.Equal(1, context.Runes.Where(c => c.Description.ToLower().Contains(bioToFind)).Count()); + Assert.Equal(3, context.Runes.Where(c => c.Family == type).Count()); + } + } + + [Fact] + public void Delete_Test() + { + var options = new DbContextOptionsBuilder() + .UseInMemoryDatabase(databaseName: "Delete_Test_Rune_database") + .Options; + + using (var context = new LolDbContext(options)) + { + 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}") }; + RuneEntity electrocute = new RuneEntity { Name = "Electrocute", Description = "hitting an enemy champion with 3 separate attacks or abilities within 3 seconds deals bonus damage.", Family = RuneFamilyEntity.Domination, ImageId = Guid.Parse("{e7c87f12-2c7b-44d5-8867-eba1ae5a4657}") }; + RuneEntity pressTheAttack = new RuneEntity { Name = "Press the Attack", Description = "hitting an enemy champion with 3 consecutive basic attacks deals bonus damage and makes them take increased damage from all sources for a short period of time.", Family = RuneFamilyEntity.Precision, ImageId = Guid.Parse("{7c354729-5ecf-43d8-ae73-153740e87644}") }; + + context.Runes.AddRange(conqueror, ravenousHunter, electrocute, pressTheAttack); + context.SaveChanges(); + } + + using (var context = new LolDbContext(options)) + { + var ewok = context.Runes.First(); + string nameToFind = "conqueror"; + Assert.Equal(1, context.Runes.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(4, context.Runes.Count()); + context.Runes.Remove(ewok); + context.SaveChanges(); + + } + + using (var context = new LolDbContext(options)) + { + string nameToFind = "conqueror"; + Assert.Equal(0, context.Runes.Where(c => c.Name.ToLower().Contains(nameToFind)).Count()); + Assert.Equal(3, context.Runes.Count()); + + } + + } + } +}