Merge pull request (#6) from UT_Entity_Relation_NextStep into master
continuous-integration/drone/push Build is passing Details

UT_EF_Manager
Emre KARTAL 2 years ago
commit 32d41969f1

Binary file not shown.

@ -1,17 +1,80 @@
using DTO;
using Model;
namespace ApiLol.Mapper
{
public static class ChampionClassMapper
{
public static ChampionClassDto ToDto(this ChampionClass championClass)
{
return (ChampionClassDto) championClass;
}
public static ChampionClass ToModel(this ChampionClassDto championClassDto)
{
return (ChampionClass) championClassDto;
}
}
}
using DTO;
using Model;
namespace ApiLol.Mapper
{
public static class ChampionClassMapper
{
public static ChampionClassDto ToDto(this ChampionClass 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)
{
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;
}
}
}
}

@ -1,22 +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)
{
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();
}
}
}
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 = 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();
}
}
}

@ -13,13 +13,22 @@ namespace MyFlib
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
[MaxLength(255)]
[Required]
[MaxLength(64)]
public string Name { get; set; }
[Required]
[MaxLength(255)]
public string Bio { get; set; }
public string Icon { get; set; }
public string Image { get; set; }
[Required]
public ChampionClassEntity Class { get; set; }
public ICollection<SkillEntity> Skills { get; set; }
public ICollection<SkinEntity> Skins { get; set; }
public LargeImageEntity Image { get; set; }
[ForeignKey("Image")]
public Guid ImageId { get; set; }
}
}

@ -0,0 +1,18 @@
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 Guid Id { get; set; }
public string Base64 { get; set; }
}
}

@ -0,0 +1,28 @@
using MyFlib.Entities.enums;
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 RuneEntity
{
[Key]
[MaxLength(64)]
public string Name { get; set; }
[Required]
[MaxLength(500)]
public string Description { get; set; }
[Required]
public RuneFamilyEntity Family { get; set; }
public LargeImageEntity Image { get; set; }
[ForeignKey("Image")]
public Guid ImageId { get; set; }
}
}

@ -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
{
}
}

@ -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(64)]
public string Name { get; set; }
[Required]
[MaxLength(500)]
public string Description { get; set; }
[Required]
public SkillTypeEntity Type { get; set; }
}
}

@ -0,0 +1,30 @@
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 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 ChampionEntity Champion { get; set; }
public Guid ChampionForeignKey { get; set; }
public LargeImageEntity Image { get; set; }
[ForeignKey("Image")]
public Guid ImageId { get; set; }
}
}

@ -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
}
}

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyFlib.Entities.enums
{
public enum RuneFamilyEntity
{
Unknown,
Precision,
Domination
}
}

@ -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
}
}

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using MyFlib.Entities.enums;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,7 +10,11 @@ namespace MyFlib
{
public class LolDbContext : DbContext
{
public DbSet<LargeImageEntity> LargeImages { get; set; }
public DbSet<ChampionEntity> Champions { get; set; }
public DbSet<SkillEntity> Skills { get; set; }
public DbSet<SkinEntity> Skins { get; set; }
public DbSet<RuneEntity> Runes { get; set; }
public LolDbContext()
{ }
@ -25,15 +30,48 @@ namespace MyFlib
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//LargeImageEntity
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<LargeImageEntity>().HasData(image1, image2);
//ChampionEntity
modelBuilder.Entity<ChampionEntity>().HasKey(e => e.Id);
modelBuilder.Entity<ChampionEntity>().Property(e => e.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<ChampionEntity>().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 = "" }
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<ChampionEntity>().HasData(Akali, Aatrox, Ahri, Akshan, Bard, Alistar);
//SkillEntity
modelBuilder.Entity<SkillEntity>().HasData(
new { Name = "Boule de feu", Description = "Fire!", Type = SkillTypeEntity.Basic },
new { Name = "White Star", Description = "Random damage", Type = SkillTypeEntity.Ultimate }
);
//SkinEntity
modelBuilder.Entity<SkinEntity>()
.HasOne(m => m.Champion)
.WithMany(a => a.Skins)
.HasForeignKey("ChampionForeignKey"); // not really useful because it is made in the Skin class
modelBuilder.Entity<SkinEntity>().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 = 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<RuneEntity>().HasData(
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}") }
);
}

@ -1,21 +1,44 @@
// See https://aka.ms/new-console-template for more information
using MyFlib;
using static System.Console;
using (var context = new LolDbContext())
{
WriteLine("\nChampions :\n");
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}");
}*/
}
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
}

@ -10,15 +10,25 @@ namespace UT_EF
public void TestAdd()
{
var options = new DbContextOptionsBuilder<LolDbContext>()
.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 = "", 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 = 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
{
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 = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}")
};
context.Champions.AddRange(sylas, hecarim, yuumi);
context.SaveChanges();
}
@ -34,14 +44,15 @@ namespace UT_EF
public void Modify_Test()
{
var options = new DbContextOptionsBuilder<LolDbContext>()
.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 = "", 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 = 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();
@ -79,14 +90,15 @@ namespace UT_EF
public void Delete_Test()
{
var options = new DbContextOptionsBuilder<LolDbContext>()
.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 = "", 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 = 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();

@ -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<LolDbContext>()
.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<LolDbContext>()
.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<LolDbContext>()
.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());
}
}
}
}

@ -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<LolDbContext>()
.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<LolDbContext>()
.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<LolDbContext>()
.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());
}
}
}
}

@ -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<LolDbContext>()
.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<LolDbContext>()
.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<LolDbContext>()
.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());
}
}
}
}
Loading…
Cancel
Save