Merge branch 'master' of https://codefirst.iut.uca.fr/git/corentin.richard/EntityFramework_ConsoDeServices_TP into httpClient
continuous-integration/drone/push Build is passing Details

pull/30/head
Pierre Ferreira 2 years ago
commit 9ff4f2cd4d

@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\EntityFramework\EntityFramework.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>

@ -30,6 +30,12 @@ namespace API_LoL.Controllers
// GET api/<ChampionController>/5
[HttpGet("count")]
public async Task<IActionResult> GetCount()
{
return Ok(ChampionsManager.GetNbItems());
}
[HttpGet]
public async Task<IActionResult> Get(string? name = null,String? skill = null, String? characteristic = null,int index = 0,int size =10)
{
@ -92,9 +98,10 @@ namespace API_LoL.Controllers
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First()));
if (skins.Count() != 0)
var nb = await SkinsManager.GetNbItemsByChampion(list.First());
if (nb != 0)
{
var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, nb);
return Ok(skins.Select(skin => skin?.ToDTO()));
}
else { return NoContent(); }
@ -102,8 +109,27 @@ namespace API_LoL.Controllers
else { return NoContent(); }
}
// POST api/<ChampionController>
[HttpPost]
//[HttpGet("name/skills")]
//public async Task<IActionResult> GetSkillsByName(String name)
//{
// if (string.IsNullOrEmpty(name)) return BadRequest();
// var list = await ChampionsManager.GetItemsByName(name, 0, 1);
// if (list.Count() == 1)
// {
// var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First()));
// if (skins.Count() != 0)
// {
// return Ok(skins.Select(skin => skin?.ToDTO()));
// }
// else { return NoContent(); }
// }
// else { return NoContent(); }
//}
// POST api/<ChampionController>
[HttpPost]
public async Task<IActionResult> Post(ChampionDTO champion)
{
if (champion == null)
@ -112,21 +138,43 @@ namespace API_LoL.Controllers
}
else
{
var champ = await ChampionsManager.GetItemsByName(champion.Name, 0, 1);
if(champ.Count() != 0 && champ.FirstOrDefault().Name == champion.Name)
{
return Conflict(champion);
}
await ChampionsManager.AddItem(champion.ToChampion());
return CreatedAtAction("Post",champion);
}
}
// PUT api/<ChampionController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
[HttpPut("name")]
public async Task<IActionResult> Put(string name, ChampionDTO championDTO)
{
if(string.IsNullOrEmpty(name))
return BadRequest();
if(championDTO == null)
return UnprocessableEntity();
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
return Ok(ChampionsManager.UpdateItem(list.First(), championDTO.ToChampion()));
}
else { return NoContent(); }
}
// DELETE api/<ChampionController>/5
[HttpDelete("{id}")]
public void Delete(int id)
[HttpDelete("name")]
public async Task<IActionResult> Delete(string name)
{
if (string.IsNullOrEmpty(name))
return BadRequest();
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if(list.Count() == 1){
return Ok(await ChampionsManager.DeleteItem(list.First()));
}else { return NoContent(); }
}
}
}

@ -12,19 +12,13 @@ namespace DTO.Mapper
{
public static ChampionDTO ToDTO(this Champion champion)
{
return new ChampionDTO(champion.Name, champion.Bio, champion.Icon,champion.Class.ToDTO().ToString());
//return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Skills);
return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Class.ToDTO(), champion.Image.Base64);
}
public static Champion ToChampion(this ChampionDTO champion)
{
Champion champ = new Champion(champion.Name, champion.Class.ToChampionClass(), champion.Icon, "", champion.Bio);
return new Champion(champion.Name, champClass: champion.Class.ToChampionClass(),icon: champion.Icon,bio: champion.Bio,image :champion.Image);
//foreach (Skill skill in champion.Skills)
//{
// champ.AddSkill(skill);
//}
return champ;
}
}
}

@ -7,12 +7,12 @@ namespace API_LoL.Mapper
{
public static SkinDTO ToDTO(this Skin skin)
{
return new SkinDTO(skin.Name, skin.Description, skin.Icon);
return new SkinDTO(skin.Name, skin.Description, skin.Icon,skin.Image.Base64,skin.Price);
}
public static Skin ToSkin(this SkinDTO skin)
{
return new Skin(skin.Name, null, icon:skin.Icon) ;
return new Skin(skin.Name, null,price: skin.Price, icon:skin.Icon,image: skin.Image,description: skin.Description) ;
}
}
}

@ -1,4 +1,6 @@
using API_LoL;
using EntityFramework;
using EntityFramework.Manager;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Versioning;
using Model;
@ -11,7 +13,7 @@ var builder = WebApplication.CreateBuilder(args);
///NOT WORKING WHEN CHANGING VERSIONS :
/// voir sur https://blog.christian-schou.dk/how-to-use-api-versioning-in-net-core-web-api/ rubrique "Configure SwaggerOptions"
/// (mais requiere l'injection de dépendance).
/// (mais requiere l'injection de d<EFBFBD>pendance).
/// Sinon, code plus simple disponible par le prof
@ -37,15 +39,24 @@ builder.Services.AddControllers();
builder.Services.AddScoped<IDataManager,StubData>();
//builder.Services.AddScoped<IDataManager,StubData>();
builder.Services.AddHttpClient();
//builder.Services.AddScoped<IDataManager,StubData>();
builder.Services.AddScoped<IDataManager,EFDataManager>();
builder.Services.AddDbContext<LoLDBContextWithStub>();
var app = builder.Build();
using(var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetService<LoLDBContextWithStub>();
context.Database.EnsureCreated();
}
var apiVersionDescriptionProvider = app.Services.GetRequiredService<IApiVersionDescriptionProvider>();

Binary file not shown.

@ -21,7 +21,7 @@ namespace Api_UT
public async Task Get_Default_OkList()
{
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","","","Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter"), new ChampionDTO("Ahri", "", "", "Mage"), new ChampionDTO("Akshan", "", "", "Marksman"), new ChampionDTO("Bard", "", "","Support"), new ChampionDTO("Alistar", "", "","Tank") };
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","","","Assassin",""), new ChampionDTO("Aatrox", "", "", "Fighter",""), new ChampionDTO("Ahri", "", "", "Mage",""), new ChampionDTO("Akshan", "", "", "Marksman",""), new ChampionDTO("Bard", "", "","Support",""), new ChampionDTO("Alistar", "", "","Tank","") };
IActionResult a = await api.Get();
a.Should().NotBeNull();
var aObject = a as OkObjectResult;
@ -42,7 +42,7 @@ namespace Api_UT
[TestMethod]
public async Task Get_2First_OkListOf2()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter") };
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin",""), new ChampionDTO("Aatrox", "", "", "Fighter","") };
IActionResult a = await api.Get(index: 0,size: 2);
@ -57,7 +57,7 @@ namespace Api_UT
[TestMethod]
public async Task Get_FilterAName_OkListOf5()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Akshan", "", "", "Marksman") };
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin", ""), new ChampionDTO("Akshan", "", "", "Marksman", "") };
IActionResult a = await api.Get(name: "Ak");
@ -75,10 +75,12 @@ namespace Api_UT
public async Task Post_ValidChampion_Created()
{
ChampionsController api = new ChampionsController(new StubData());
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin"));
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin",""));
var action = (CreatedAtActionResult)a;
var champAction = action.Value as IEnumerable<ChampionDTO>;
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin", "");
Assert.IsTrue(champ.equals(other: (ChampionDTO)((CreatedAtActionResult)a).Value));
}
}

@ -5,17 +5,19 @@ namespace DTO
{
public class ChampionDTO
{
public ChampionDTO(string name, string bio, string icon, string championClassDTO)
public ChampionDTO(string name, string bio, string icon, string Class, string image)
{
Name = name;
Bio = bio;
Icon = icon;
Class = championClassDTO;
this.Class = Class;
Image = image;
}
public string Name { get; set; }
public string Bio { get; set; }
public string Icon { get; set; }
public string Image { get; set; }
public string Class { get; set; }
public bool equals(ChampionDTO other)

@ -13,10 +13,16 @@ namespace DTO
public string Description { get; set; }
public string Icon { get; set; }
public SkinDTO(string name,string description,string icon) {
public string Image { get; set; }
public float Price { get; set; }
public SkinDTO(string name,string description,string icon,string image,float price) {
this.Name = name;
this.Description = description;
this.Icon = icon;
this.Image = image;
this.Price = price;
}
}

@ -0,0 +1,53 @@
using EntityFramework;
using EntityFramework.Manager;
using FluentAssertions;
using FluentAssertions.Primitives;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EF_UT
{
[TestClass]
public class EFDataManagerChampionTest
{
[TestMethod]
public void Add_ValidChampion_Added()
{
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
var champ = championsManager.AddItem(new Champion("test"));
}
[TestMethod]
public async Task GetItemsByName_DefaultChamp_One()
{
var builder = WebApplication.CreateBuilder();
builder.Services.AddDbContext<LoLDBContextWithStub>();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetService<LoLDBContextWithStub>();
context.Database.EnsureCreated();
}
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
var ak = (await championsManager.GetItemsByName("A", 0, 1)).First();
Assert.IsNotNull(ak);
//Assert.AreEqual("Akali", ak.Name);
}
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@ -8,6 +8,14 @@
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Manager\EFDataManager.Champion.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Manager\EFDataManager.Champion.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
@ -18,6 +26,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>

@ -35,7 +35,7 @@ namespace EntityFramework
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ChampionEntity>().HasKey(entity => entity.Name);
modelBuilder.Entity<ChampionEntity>().ToTable("Champion");
modelBuilder.Entity<ChampionEntity>().ToTable("Champions");
//modelBuilder.Entity<ChampionEntity>().Property(entity => entity.Id)
// .ValueGeneratedOnAdd();

@ -0,0 +1,186 @@
using EntityFramework.Mapper;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Manager
{
public partial class EFDataManager
{
public class ChampionsManager : IChampionsManager
{
private readonly EFDataManager parent;
public ChampionsManager(EFDataManager parent)
{
this.parent = parent;
}
public async Task<Champion?> AddItem(Champion? item)
{
using(var context = new LoLDBContextWithStub())
{
if (item != null)
{
context.Add(item.ToEntity());
context.SaveChanges();
return item;
}
else
{
throw new Exception();
}
}
}
public async Task<bool> DeleteItem(Champion? item)
{
using (var context = new LoLDBContextWithStub())
{
var champ = context.Champions.Select(c => c == item.ToEntity());
if(champ.Count()<1)
{
return false;
}
context.Champions.Remove(item.ToEntity());
context.SaveChanges();
return true;
}
}
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
using(var context = new LoLDBContextWithStub() )
{
var champ = context.Champions.ToArray();
if (descending == false)
{
return champ.ToList().Skip(index * count).Take(count).Select(c => c.ToChampion()).OrderBy(c => c.Name);
}
else
{
return champ.ToList().Skip(index * count).Take(count).Select(c => c.ToChampion()).OrderByDescending(c => c.Name);
}
}
}
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsByClass(Model.ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Champion?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
using (var context = new LoLDBContextWithStub())
{
var champ = context.Champions.Where(c => c.Name.Contains(substring)).AsEnumerable();
if (descending == false)
{
return champ.Select(c => c.ToChampion()).ToList().Skip(index * count).Take(count).OrderBy(c=> c.Name);
}
else
{
return champ.Select(c => c.ToChampion()).ToList().Skip(index*count).Take(count).OrderByDescending(c => c.Name);
}
}
}
public Task<IEnumerable<Champion?>> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Champion?>> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Champion?>> GetItemsBySkill(string skill, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
using(var context = new LoLDBContextWithStub())
{
var champ = context.Champions.Where(c => c.Skills.Any(c => c.Name.Contains(skill)));
if (descending.Equals(false))
{
return champ.Select(c=> c.ToChampion()).ToList().Skip(index * count).Take(count).OrderBy(c => c.Name);
}
else
{
return champ.Select(c => c.ToChampion()).ToList().Skip(index * count).Take(count).OrderByDescending(c => c.Name);
}
}
}
public async Task<int> GetNbItems()
{
using(var context = new LoLDBContextWithStub())
{
return context.Champions.Count();
}
}
public Task<int> GetNbItemsByCharacteristic(string charName)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByClass(Model.ChampionClass championClass)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsByRunePage(RunePage? runePage)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(Skill? skill)
{
throw new NotImplementedException();
}
public Task<int> GetNbItemsBySkill(string skill)
{
throw new NotImplementedException();
}
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
using(var context = new LoLDBContextWithStub())
{
if (oldItem != null && newItem != null)
{
var champ = context.Champions.Where(c => c == oldItem.ToEntity()).First();
champ = newItem.ToEntity();
context.SaveChanges();
return newItem;
}
else { throw new Exception(); }
}
}
}
}
}

@ -0,0 +1,85 @@
using EntityFramework.Mapper;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Manager
{
public partial class EFDataManager
{
public class SkinsManager : ISkinsManager
{
private readonly EFDataManager parent;
public SkinsManager(EFDataManager parent)
{
this.parent = parent;
}
public Task<Skin?> AddItem(Skin? item)
{
throw new NotImplementedException();
}
public Task<bool> DeleteItem(Skin? item)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Skin?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public async Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
using (var context = new LoLDBContextWithStub())
{
var skins = context.Skins.Where(c => c.Champion.Equals(champion)).ToList();
if (descending == false)
{
return skins.Select(c => c.ToSkin()).ToList().Skip(index * count).Take(count).OrderBy(c => c.Name);
}
else
{
return skins.Select(c => c.ToSkin()).ToList().Skip(index * count).Take(count).OrderByDescending(c => c.Name);
}
}
}
public Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
}
public Task<int> GetNbItems()
{
throw new NotImplementedException();
}
public async Task<int> GetNbItemsByChampion(Champion? champion)
{
using(var context = new LoLDBContextWithStub())
{
return context.Skins.Where(c => c.Champion.Equals(champion.ToEntity())).Count();
}
}
public Task<int> GetNbItemsByName(string substring)
{
throw new NotImplementedException();
}
public Task<Skin?> UpdateItem(Skin? oldItem, Skin? newItem)
{
throw new NotImplementedException();
}
}
}
}

@ -0,0 +1,25 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Manager
{
public partial class EFDataManager : IDataManager
{
public EFDataManager() {
ChampionsMgr = new ChampionsManager(this);
SkinsMgr = new SkinsManager(this);
}
public IChampionsManager ChampionsMgr { get; }
public ISkinsManager SkinsMgr { get; }
public IRunesManager RunesMgr { get; }
public IRunePagesManager RunePagesMgr { get; }
}
}

@ -12,5 +12,11 @@ namespace EntityFramework.Mapper
public static ChampionEntity ToEntity(this Champion champion) {
return new ChampionEntity { Name = champion.Name, Bio = champion.Bio, Icon = champion.Icon };
}
public static Champion ToChampion(this ChampionEntity champion)
{
return new Champion(champion.Name,bio: champion.Bio,icon: champion.Icon);
}
}
}

@ -0,0 +1,24 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework.Mapper
{
public static class SkinMapper
{
public static SkinEntity ToEntity(this Skin skin)
{
return new SkinEntity { Champion = skin.Champion.ToEntity(), Description = skin.Description, Icon = skin.Icon, Image = skin.Image.Base64, Name = skin.Name, Price = skin.Price };
}
public static Skin ToSkin(this SkinEntity entity)
{
return new Skin(entity.Name,entity.Champion.ToChampion(),price: entity.Price,icon: entity.Icon, image: entity.Image,description: entity.Description);
}
}
}

@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EntityFramework.Migrations
{
[DbContext(typeof(LoLDBContextWithStub))]
[Migration("20230315145258_myMig")]
[Migration("20230319224555_myMig")]
partial class myMig
{
/// <inheritdoc />
@ -40,7 +40,7 @@ namespace EntityFramework.Migrations
b.HasKey("Name");
b.ToTable("Champion", (string)null);
b.ToTable("Champions", (string)null);
b.HasData(
new

@ -13,7 +13,7 @@ namespace EntityFramework.Migrations
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champion",
name: "Champions",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
@ -23,7 +23,7 @@ namespace EntityFramework.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Champion", x => x.Name);
table.PrimaryKey("PK_Champions", x => x.Name);
});
migrationBuilder.CreateTable(
@ -52,9 +52,9 @@ namespace EntityFramework.Migrations
{
table.PrimaryKey("PK_SkillEntity", x => x.Name);
table.ForeignKey(
name: "FK_SkillEntity_Champion_ChampionEntityName",
name: "FK_SkillEntity_Champions_ChampionEntityName",
column: x => x.ChampionEntityName,
principalTable: "Champion",
principalTable: "Champions",
principalColumn: "Name");
});
@ -73,14 +73,14 @@ namespace EntityFramework.Migrations
{
table.PrimaryKey("PK_Skins", x => x.Name);
table.ForeignKey(
name: "FK_Skins_Champion_ChampionEntityForeignKey",
name: "FK_Skins_Champions_ChampionEntityForeignKey",
column: x => x.ChampionEntityForeignKey,
principalTable: "Champion",
principalTable: "Champions",
principalColumn: "Name");
});
migrationBuilder.InsertData(
table: "Champion",
table: "Champions",
columns: new[] { "Name", "Bio", "Icon", "Image" },
values: new object[,]
{
@ -116,7 +116,7 @@ namespace EntityFramework.Migrations
name: "Skins");
migrationBuilder.DropTable(
name: "Champion");
name: "Champions");
}
}
}

@ -37,7 +37,7 @@ namespace EntityFramework.Migrations
b.HasKey("Name");
b.ToTable("Champion", (string)null);
b.ToTable("Champions", (string)null);
b.HasData(
new

@ -1,78 +1,86 @@
// See https://aka.ms/new-console-template for more information
using EntityFramework;
using EntityFramework.Manager;
using Microsoft.EntityFrameworkCore;
using Model;
using ( var context = new LoLDbContext())
{
//context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
context.SaveChanges();
IDataManager dataManager = new EFDataManager();
IChampionsManager championsManager = dataManager.ChampionsMgr;
IEnumerable<Champion?> champions = await championsManager.GetItemsByName("A", 0, 1);
Console.WriteLine(champions.First().Name);
ChampionEntity champ = context.Find<ChampionEntity>("Akali");
if( champ != null)
{
Console
.WriteLine(champ.ToString());
//using ( var context = new LoLDbContext())
//{
// //context.Add(new ChampionEntity{ Name = "test", Bio = "test", Icon = "test" } );
// context.SaveChanges();
}
else
{
Console.WriteLine("Not Found");
}
// ChampionEntity champ = context.Find<ChampionEntity>("Akali");
//Test BDD Skills
ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" };
// if( champ != null)
// {
// Console
// .WriteLine(champ.ToString());
//SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown };
SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type=SkillType.Ultimate };
SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = SkillType.Passive };
// }
// else
// {
// Console.WriteLine("Not Found");
// }
champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown });
champSkill.AddSkill(s2);
champSkill.AddSkill(s3);
// //Test BDD Skills
// ChampionEntity champSkill = new ChampionEntity { Name="nomSkill", Bio="bioSkill", Icon="iconSkill" };
context.Add(champSkill);
// //SkillEntity s1 = new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown };
// SkillEntity s2 = new SkillEntity { Name="Skill2", Description="desc2", Type=SkillType.Ultimate };
// SkillEntity s3 = new SkillEntity { Name = "Skill3", Description = "desc3", Type = SkillType.Passive };
context.SaveChanges();
// champSkill.AddSkill(new SkillEntity { Name = "Skill1", Description = "desc", Type = SkillType.Unknown });
// champSkill.AddSkill(s2);
// champSkill.AddSkill(s3);
// context.Add(champSkill);
//OneToMany
Console.WriteLine("Champions : ");
foreach (var champi in context.Champions.Include(a => a.skins))
{
Console.WriteLine($"\t{champi.Name} : {champi.Bio}");
foreach (var s in champi.skins)
{
Console.WriteLine($"\t\t{s.Name}");
}
}
// context.SaveChanges();
Console.WriteLine();
Console.WriteLine("Skin :");
foreach (var s in context.Skins)
{
Console.WriteLine($"\t{s.Name}: {s.Description} (Champion : {s.Champion.Name})");
}
// //OneToMany
// Console.WriteLine("Champions : ");
// foreach (var champi in context.Champions.Include(a => a.skins))
// {
// Console.WriteLine($"\t{champi.Name} : {champi.Bio}");
// foreach (var s in champi.skins)
// {
// Console.WriteLine($"\t\t{s.Name}");
// }
// }
// Console.WriteLine();
Console.WriteLine("\nAjout d'un Champion et 6 Skins...\n");
// Console.WriteLine("Skin :");
// foreach (var s in context.Skins)
// {
// Console.WriteLine($"\t{s.Name}: {s.Description} (Champion : {s.Champion.Name})");
// }
ChampionEntity captainMarvel = new ChampionEntity { Name = "Captain Marvel", Bio="Mais que fait un avenger ici ??", Icon="Icon.png"};
SkinEntity[] skins = { new SkinEntity {Name = "La Fiesta", Champion = captainMarvel},
new SkinEntity { Name = "Five Hundred Miles High", Champion = captainMarvel },
new SkinEntity { Name = "Captain Marvel", Champion = captainMarvel },
new SkinEntity { Name = "Time's Lie", Champion = captainMarvel },
new SkinEntity { Name = "Lush Life", Champion = captainMarvel },
new SkinEntity { Name = "Day Waves", Champion = captainMarvel }
};
foreach (var s in skins)
{
captainMarvel.skins.Add(s);
}
context.Add(captainMarvel);
context.SaveChanges();
// Console.WriteLine("\nAjout d'un Champion et 6 Skins...\n");
// ChampionEntity captainMarvel = new ChampionEntity { Name = "Captain Marvel", Bio="Mais que fait un avenger ici ??", Icon="Icon.png"};
// SkinEntity[] skins = { new SkinEntity {Name = "La Fiesta", Champion = captainMarvel},
// new SkinEntity { Name = "Five Hundred Miles High", Champion = captainMarvel },
// new SkinEntity { Name = "Captain Marvel", Champion = captainMarvel },
// new SkinEntity { Name = "Time's Lie", Champion = captainMarvel },
// new SkinEntity { Name = "Lush Life", Champion = captainMarvel },
// new SkinEntity { Name = "Day Waves", Champion = captainMarvel }
// };
// foreach (var s in skins)
// {
// captainMarvel.skins.Add(s);
// }
}
// context.Add(captainMarvel);
// context.SaveChanges();
//}

@ -8,7 +8,7 @@ namespace StubLib
private List<Champion> champions = new()
{
new Champion("Akali", ChampionClass.Assassin),
new Champion("Aatrox", ChampionClass.Fighter),
new Champion("Aatrox", ChampionClass.Fighter),
new Champion("Ahri", ChampionClass.Mage),
new Champion("Akshan", ChampionClass.Marksman),
new Champion("Bard", ChampionClass.Support),

Loading…
Cancel
Save