Add more UT and more stubData
continuous-integration/drone/push Build is passing Details

pull/6/head
Emre KARTAL 2 years ago
parent dacb7131c6
commit 0bdef0bc74

Binary file not shown.

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

@ -28,7 +28,7 @@ namespace MyFlib
public LargeImageEntity Image { get; set; }
[ForeignKey("Image")]
public int ImageId { get; set; }
public Guid ImageId { get; set; }
}
}

@ -11,7 +11,7 @@ namespace MyFlib
{
[Key]
public int Id { get; set; }
public Guid Id { get; set; }
public string Base64 { get; set; }
}

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

@ -10,7 +10,7 @@ namespace MyFlib
public class SkillEntity
{
[Key]
[MaxLength(256)]
[MaxLength(64)]
public string Name { get; set; }
[Required]

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

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace MyFlib.Entities.enums
{
enum RuneFamilyEntity
public enum RuneFamilyEntity
{
Unknown,
Precision,

@ -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<LargeImageEntity> LargeImages { get; set; }
public DbSet<ChampionEntity> Champions { get; set; }
public DbSet<SkillEntity> Skills { get; set; }
public DbSet<SkinEntity> 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<LargeImageEntity>().HasData(image1, image2);
//ChampionEntity
modelBuilder.Entity<ChampionEntity>().HasKey(e => e.Id);
modelBuilder.Entity<ChampionEntity>().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<ChampionEntity>().HasData(Akali, Aatrox, Ahri, Akshan, Bard, Alistar);
@ -55,15 +58,20 @@ namespace MyFlib
);
//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 = 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<RuneEntity>().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}") }
);
}

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

@ -10,15 +10,15 @@ 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 = "", 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<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 = "", 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<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 = "", 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();

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