From 636ae58e55b5f720e762b01fe98c262a15fecff9 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@gmail.com" Date: Wed, 1 Mar 2023 16:44:22 +0100 Subject: [PATCH 1/3] add TestAddSkinToChampionInMemory --- Sources/EFLol/ChampionEntity.cs | 2 +- Sources/EFLol/Program.cs | 4 +- Sources/TestUnitaire/TestEfLol.cs | 61 +++++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/Sources/EFLol/ChampionEntity.cs b/Sources/EFLol/ChampionEntity.cs index b23a534..7cdd4da 100644 --- a/Sources/EFLol/ChampionEntity.cs +++ b/Sources/EFLol/ChampionEntity.cs @@ -18,6 +18,6 @@ namespace EFLol //public LargeImage Image { get; set; } //public ReadOnlyDictionary Characteristics { get; private set; } //private HashSet skills = new HashSet(); - public ReadOnlyCollection Skins { get; set; } + public Collection Skins { get; set; } } } diff --git a/Sources/EFLol/Program.cs b/Sources/EFLol/Program.cs index fbac836..9897c31 100644 --- a/Sources/EFLol/Program.cs +++ b/Sources/EFLol/Program.cs @@ -18,14 +18,14 @@ ChampionEntity Zeus = new ChampionEntity { Name = "Zeus", Bio = "Zeus is the god of the sky", - Skins = new ReadOnlyCollection(new List { black, white }) + Skins = new Collection(new List { black, white }) }; ChampionEntity Hera = new ChampionEntity { Name = "Hera", Bio = "Hera is the goddess of marriage", - Skins = new ReadOnlyCollection(new List { green }) + Skins = new Collection(new List { green }) }; ChampionEntity Poseidon = new ChampionEntity { Name = "Poseidon", Bio = "Poseidon is the god of the sea" }; diff --git a/Sources/TestUnitaire/TestEfLol.cs b/Sources/TestUnitaire/TestEfLol.cs index d9bae90..21851dd 100644 --- a/Sources/TestUnitaire/TestEfLol.cs +++ b/Sources/TestUnitaire/TestEfLol.cs @@ -1,6 +1,7 @@ using EFLol; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; +using System.Collections.ObjectModel; namespace TestUnitaire { @@ -28,10 +29,16 @@ namespace TestUnitaire using (var context = new MyDbContext(options)) { await context.Database.EnsureCreatedAsync(); + SkinEntity black = new SkinEntity { Name = "Black", Description = "Black skin", Icon = "black.png", Price = 0.99f }; + SkinEntity white = new SkinEntity { Name = "White", Description = "White skin", Icon = "white.png", Price = 150.99f }; + SkinEntity green = new SkinEntity { Name = "Green", Description = "Green skin", Icon = "green.png", Price = 4.99f }; + + var Dieu = new ChampionEntity { Name = name, - Bio = bio + Bio = bio, + Skins = new Collection(new List { black, white, green }) }; ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus"); @@ -45,6 +52,7 @@ namespace TestUnitaire Assert.Equal(1, await context.Champions.CountAsync()); Assert.Equal(name, found.Name); + Assert.Equal(3,found.Skins.Count); // Test if the max length of the name is respected (30) and the max length of the bio is respected (256) if (expected) @@ -54,8 +62,8 @@ namespace TestUnitaire } else { - Assert.False(found.Bio.Length <= 256); Assert.False(found.Name.Length <= 30); + Assert.False(found.Bio.Length <= 256); } } @@ -113,5 +121,52 @@ namespace TestUnitaire Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count()); } } - } + + [Theory] + + [InlineData("black", "super Skin", "icon1.png",190000000.2f,true)] + [InlineData("White", "skin1", "icon1", 19, true)] + [InlineData("Green", "skin", "icon1.jpg", -1, false)] + public async Task TestAddSkinToChampionInMemory(String name, String description, String icon,float price,bool expected) + { + var connection = new SqliteConnection("DataSource=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder() + .UseSqlite(connection) + .Options; + + using (var context = new MyDbContext(options)) + { + await context.Database.EnsureCreatedAsync(); + + var Dieu = new ChampionEntity + { + Name = "Zeus", + Bio = "Dieu de la foudre", + Skins = new Collection() + }; + + SkinEntity item = new SkinEntity + { + Name = name, + Description = description, + Icon = icon, + Price = price + }; + + Dieu.Skins.Add(item); + + ChampionEntity found = await context.Champions.SingleOrDefaultAsync(c => c.Name == "Zeus"); + Assert.Null(found); + + await context.Champions.AddAsync(Dieu); + await context.SaveChangesAsync(); + + found = await context.Champions.SingleOrDefaultAsync(c => c.Name == name); + } + + } + + } } \ No newline at end of file From ff581216885a0dc8e04891f291fbabbee5745fcf Mon Sep 17 00:00:00 2001 From: "bastien.ollier@gmail.com" Date: Wed, 1 Mar 2023 16:48:04 +0100 Subject: [PATCH 2/3] add test id chmapion --- Sources/TestUnitaire/TestEfLol.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Sources/TestUnitaire/TestEfLol.cs b/Sources/TestUnitaire/TestEfLol.cs index 21851dd..4a8c3a5 100644 --- a/Sources/TestUnitaire/TestEfLol.cs +++ b/Sources/TestUnitaire/TestEfLol.cs @@ -10,14 +10,14 @@ namespace TestUnitaire [Theory] - [InlineData("Zeus", "Dieu de la foudre", true)] - [InlineData("Hades", "Dieu des enfers", true)] - [InlineData("Aphrodite", "Déesse de l'amour", true)] - [InlineData("AresAresAresAresAresAresAresAresAresAres", + [InlineData(0,"Zeus", "Dieu de la foudre", true)] + [InlineData(10,"Hades", "Dieu des enfers", true)] + [InlineData(1,"Aphrodite", "Déesse de l'amour", true)] + [InlineData(10,"AresAresAresAresAresAresAresAresAresAres", "Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre" + "Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre" + "Dieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerreDieu de la guerre", false)] - public async Task TestAddInMemory(String name, String bio, bool expected) + public async Task TestAddInMemory(int id, String name, String bio, bool expected) { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); @@ -36,6 +36,7 @@ namespace TestUnitaire var Dieu = new ChampionEntity { + Id = id, Name = name, Bio = bio, Skins = new Collection(new List { black, white, green }) @@ -85,9 +86,9 @@ namespace TestUnitaire //context.Database.OpenConnection(); context.Database.EnsureCreated(); - ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca", Bio = "Zeus is the king of the gods." }; - ChampionEntity yoda = new ChampionEntity { Name = "Yoda", Bio = "Zeus is the king of the gods." }; - ChampionEntity ewok = new ChampionEntity { Name = "Ewok", Bio = "Zeus is the king of the gods." }; + ChampionEntity chewie = new ChampionEntity {Id = 0, Name = "Chewbacca", Bio = "Zeus is the king of the gods." }; + ChampionEntity yoda = new ChampionEntity {Id = 1, Name = "Yoda", Bio = "Zeus is the king of the gods." }; + ChampionEntity ewok = new ChampionEntity { Id = 2, Name = "Ewok", Bio = "Zeus is the king of the gods." }; context.Champions.Add(chewie); @@ -142,6 +143,7 @@ namespace TestUnitaire var Dieu = new ChampionEntity { + Id = 0, Name = "Zeus", Bio = "Dieu de la foudre", Skins = new Collection() From 98b092e1301b25802dcfd2b85fa6caa245aa963a Mon Sep 17 00:00:00 2001 From: "bastien.ollier@gmail.com" Date: Wed, 1 Mar 2023 16:49:25 +0100 Subject: [PATCH 3/3] add test id skin --- Sources/TestUnitaire/TestEfLol.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sources/TestUnitaire/TestEfLol.cs b/Sources/TestUnitaire/TestEfLol.cs index 4a8c3a5..26c10b1 100644 --- a/Sources/TestUnitaire/TestEfLol.cs +++ b/Sources/TestUnitaire/TestEfLol.cs @@ -125,10 +125,10 @@ namespace TestUnitaire [Theory] - [InlineData("black", "super Skin", "icon1.png",190000000.2f,true)] - [InlineData("White", "skin1", "icon1", 19, true)] - [InlineData("Green", "skin", "icon1.jpg", -1, false)] - public async Task TestAddSkinToChampionInMemory(String name, String description, String icon,float price,bool expected) + [InlineData(0,"black", "super Skin", "icon1.png",190000000.2f,true)] + [InlineData(1,"White", "skin1", "icon1", 19, true)] + [InlineData(2,"Green", "skin", "icon1.jpg", -1, false)] + public async Task TestAddSkinToChampionInMemory(int id,String name, String description, String icon,float price,bool expected) { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); @@ -151,6 +151,7 @@ namespace TestUnitaire SkinEntity item = new SkinEntity { + Id = id, Name = name, Description = description, Icon = icon,