avancement
continuous-integration/drone/push Build is failing Details

master
Jolys Enzo 2 years ago
parent 3adec1b76a
commit 3f3ab28054

@ -46,10 +46,11 @@ namespace Api_lol.Controllers
}
catch(Exception ex)
{
logger.LogInformation(ex.Message, ex);
return BadRequest(ex.Message);
}
GetChampions dto = new GetChampions(champs.ToList(), index, count,await data.ChampionsMgr.GetNbItems());
logger.LogInformation($"GetChampions: {dto}");
return Ok(dto);
}
@ -65,9 +66,11 @@ namespace Api_lol.Controllers
}
catch (Exception ex)
{
return BadRequest(ex.Message);
logger.LogError(ex.Message,champDTO);
return BadRequest();
}
DtoChampions dtoChamp = champion.ModelToDto();
logger.LogInformation("Post : Un Champion a été ajouté !", dtoChamp);
return CreatedAtAction(nameof(GetChampion),new { name = dtoChamp.name},dtoChamp);
}
@ -83,10 +86,12 @@ namespace Api_lol.Controllers
}
catch (Exception ex)
{
logger.LogError(ex.Message, ex);
return BadRequest(ex.Message);
}
if ( champion == null)
{
logger.LogInformation($"GetChampion : Le champion {name} n'a pas été trouvé !");
return BadRequest();
}
DtoChampions result = champion.ModelToDto();
@ -103,10 +108,11 @@ namespace Api_lol.Controllers
champion = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).First(e => e.Name == name);
} catch (Exception ex)
{
logger.LogError(ex.Message, ex);
return BadRequest(ex.Message);
}
await data.ChampionsMgr.DeleteItem(champion);
logger.LogInformation($"Delete champio : suppression de {name}");
return Ok(champion.ModelToDto());
}
@ -114,6 +120,7 @@ namespace Api_lol.Controllers
[Route("/GetItems")]
public async Task<IEnumerable<DtoChampions?>> GetItems(int index,int count,string? propertyName = null, bool descending = false)
{
//logger.LogInformation($"{nameof(GetItems)}");
return (await data.ChampionsMgr.GetItems(index, count, propertyName, descending)).Select(e => e.ModelToDto());
}
@ -121,6 +128,7 @@ namespace Api_lol.Controllers
[Route("/GetNbItems")]
public async Task<int> GetNbItems()
{
//logger.LogInformation($"{nameof(GetNbItems)}");
return await data.ChampionsMgr.GetNbItems();
}
}

@ -87,9 +87,16 @@ namespace Api_lol.Controllers
{
return BadRequest("Le champion n'existe pas !");
}
Skin skinModele = skin.DtoToModel(champion);
Skin skinModele = skin.DtoToModel();
await data.SkinsMgr.AddItem(skinModele);
return Ok();
}
[HttpPost]
[Route("/GetItemsByChampion")]
public async Task<IEnumerable<DtoSkins>> GetItemsByChampion(DtoChampions champ,int index,int count,string ordering = "null",bool descending = false)
{
return (await data.SkinsMgr.GetItemsByChampion(champ.DtoToModel(),index,count,ordering,descending)).Select(e => e.ModelToDto());
}
}
}

@ -42,6 +42,7 @@ namespace Api_lol.Factories
dto.classe = champ.Class.ToString();
dto.bio = champ.Bio;
dto.icon = champ.Icon;
dto.image = champ.Image.Base64;
return dto;
}

@ -13,13 +13,15 @@ namespace Api_lol.Factories
dto.description = skin.Description;
dto.price = skin.Price;
dto.icon = skin.Icon;
dto.image = skin.Image.Base64;
dto.champion = skin.Champion.ModelToDto();
return dto;
}
public static Skin DtoToModel(this DtoSkins skinDto,Champion champ)
public static Skin DtoToModel(this DtoSkins skinDto)
{
return new Skin(skinDto.name, champ);
return new Skin(skinDto.name,skinDto.champion.DtoToModel());
}
}
}

@ -15,7 +15,9 @@ namespace DTO
public string icon { get; set; }
public DtoChampions champion { get; set; }
public string image { get; set; }
}
}

@ -99,12 +99,14 @@ namespace EntityFramwork
// ---------------------------------- Stub --------------------------------------//
DataStub dataStub = new DataStub();
List<Champion> champions = dataStub.champions;
dataStub.InitSkins();
List<EntityLargeImage> listImage = new List<EntityLargeImage>();
List<EntityChampions> listChampions = new List<EntityChampions>();
List<EntitySkins> listeSkins = new List<EntitySkins>();
int i = 1;
foreach (var champion in champions)
foreach (var champion in dataStub.champions)
{
listImage.Add(new EntityLargeImage() { Id = i, Base64 = champion.Image.Base64 });
EntityChampions tmpChamp = champion.ChampionModelToEntity();
@ -114,6 +116,28 @@ namespace EntityFramwork
i++;
}
modelBuilder.Entity<EntityChampions>().HasData(listChampions);
int c = 0;
foreach(var skin in dataStub.skins)
{
listImage.Add(new EntityLargeImage() { Id = i,Base64 = skin.Image.Base64 });
EntitySkins entitySkins = skin.SkinsModelToEntity();
entitySkins.Id = c+1;
entitySkins.ImageId = i;
if ( c == 0 || c==1 || c == 2) { entitySkins.ChampionId = 1; }
if (c == 3) { entitySkins.ChampionId =2; }
if (c == 4 || c == 5 || c == 6) { entitySkins.ChampionId = 3; }
if (c == 7 || c == 8 || c == 9) { entitySkins.ChampionId = 4; }
if(c == 10 || c == 11 || c == 12) { entitySkins.ChampionId = 5; }
if (c == 13 || c == 14 ) { entitySkins.ChampionId = 6; }
if (c == 15 || c == 16) { entitySkins.ChampionId = 7; }
listeSkins.Add(entitySkins);
i++;
c++;
}
modelBuilder.Entity<EntitySkins>().HasData(listeSkins);
modelBuilder.Entity<EntityLargeImage>().HasData(listImage);
/*

File diff suppressed because one or more lines are too long

@ -24,6 +24,7 @@ namespace EntityFramwork.Factories
public static Champion EntityChampionToModele(this EntityChampions entity)
{
ChampionClass classe = ChampionClass.Unknown;
string image;
switch (entity.Classe)
{
@ -47,13 +48,16 @@ namespace EntityFramwork.Factories
classe = ChampionClass.Tank;
break;
}
using (BDDContext db = new BDDContext())
{
image = db.Images.Where(e => e.Id == entity.ImageId).First().Base64;
}
// Attention l'image !!
return new Champion(entity.Name,champClass:classe,icon:entity.Icon,bio:entity.Bio);
return new Champion(entity.Name,champClass:classe,icon:entity.Icon,bio:entity.Bio,image:image);
}
// Skins
public static EntitySkins SkinsModelToEntity(this Skin skin,int id)
public static EntitySkins SkinsModelToEntity(this Skin skin)
{
EntitySkins entity= new EntitySkins();
@ -61,11 +65,22 @@ namespace EntityFramwork.Factories
entity.Icon = skin.Icon;
entity.Name = skin.Name;
entity.Description = skin.Description;
entity.ChampionId = id;
return entity;
}
public static Skin SkinEntityToModele(this EntitySkins entity)
{
Champion champ;
LargeImage image;
using (BDDContext db = new BDDContext())
{
champ = db.Champions.Where(e => e.Id == entity.ChampionId).First().EntityChampionToModele();
image = db.Images.Where(e => e.Id == entity.ImageId).First().ImageEntityToModele();
}
return new Skin(entity.Name, champ, entity.Price, entity.Icon, image.Base64, entity.Description);
}
public static EntityRunes RuneModelToEntity(this Rune rune)
{
@ -91,6 +106,9 @@ namespace EntityFramwork.Factories
return entity;
}
public static LargeImage ImageEntityToModele(this EntityLargeImage entity)
{
return new LargeImage(entity.Base64);
}
}
}

@ -1,4 +1,5 @@
using Model;
using EntityFramwork.Factories;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
@ -26,7 +27,16 @@ namespace EntityFramwork.Manager
public Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
throw new NotImplementedException();
IEnumerable<Skin?> items = new List<Skin>();
using (BDDContext db = new BDDContext())
{
int idChampions = db.Champions.Where( e => e.Name == champion.Name).FirstOrDefault().Id;
items = db.Skins.Where(e => e.ChampionId == idChampions).Skip(index).Take(count).Select(e => e.SkinEntityToModele()).ToList();
}
return Task.FromResult(items);
}
public Task<IEnumerable<Skin?>> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -40,11 +40,11 @@ namespace RelationApi.Factories
public static DtoChampions ModelToDto(this Champion champ)
{
DtoChampions dto = new DtoChampions();
dto.name = champ.Name;
dto.classe = champ.Class.ToString();
dto.bio = champ.Bio;
dto.icon = champ.Icon;
dto.image = champ.Image.Base64;
return dto;
}

@ -0,0 +1,32 @@
using DTO;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RelationApi.Factories
{
public static class SkinsFacto
{
public static DtoSkins ModelToDto(this Skin skin)
{
DtoSkins dto = new DtoSkins();
dto.name = skin.Name;
dto.description = skin.Description;
dto.price = skin.Price;
dto.icon = skin.Icon;
dto.image = skin.Image.Base64;
//dto.champion = skin.Champion.ModelToDto();
return dto;
}
public static Skin DtoToModel(this DtoSkins skinDto)
{
return new Skin(skinDto.name, skinDto.champion.DtoToModel());
}
}
}

@ -9,6 +9,7 @@
<ItemGroup>
<ProjectReference Include="..\..\SourcesMobileApp\Model\Model.csproj" />
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
</ItemGroup>
</Project>

@ -34,9 +34,9 @@ namespace RelationApi
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
{
IEnumerable<DtoChampions?> dto = await _httpClient.GetFromJsonAsync<IEnumerable<DtoChampions?>>(IpApi+ "GetItems?index="+index+"&count="+count+"&descending="+descending);
return dto.Select(e => e.DtoToModel()).ToList();
throw new NotImplementedException();
//return dto.Select(e => e.DtoToModel()).ToList();
}
public Task<IEnumerable<Champion?>> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false)

@ -1,7 +1,10 @@
using Model;
using DTO;
using Model;
using RelationApi.Factories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
@ -33,8 +36,15 @@ namespace RelationApi
throw new NotImplementedException();
}
public Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
public async Task<IEnumerable<Skin?>> GetItemsByChampion(Champion? champion, int index, int count, string? orderingPropertyName = null, bool descending = false)
{
/*
if ( champion == null)
{
throw new NotImplementedException();
}
IEnumerable<DtoSkins> dto = await _httpClient.GetFromJsonAsync<IEnumerable<DtoSkins>>(IpApi + "GetItemsByChampion?champ="+champion.ModelToDto()+"index=" + index + "&count=" + count + "&descending=" + descending);
return dto.Select(e => e.DtoToModel()).ToList();*/
throw new NotImplementedException();
}

@ -1,6 +1,7 @@
using Api_lol.Controllers;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using StubLib;
using System.Net.Http.Json;
using System.Reflection;
@ -11,7 +12,7 @@ namespace TestUnitaireApi
{
StubData stubChamps;
Champions controlleurChampion;
/*
public TestChampions()
{
this.stubChamps = new StubData();
@ -22,21 +23,22 @@ namespace TestUnitaireApi
[Fact]
public async Task TestGetChampions()
{
var liste = controlleurChampion.Get();
IEnumerable<DtoChampions?> liste = await controlleurChampion.GetItems(0,3);
OkObjectResult tmp = liste as OkObjectResult;
if (tmp == null)
if (liste == null)
{
//Assert.Fail("Liste okObject == null");
Assert.Fail("Liste okObject == null");
return;
}
IEnumerable<DtoChampions> listeChamp = tmp.Value as IEnumerable<DtoChampions>;
if (listeChamp == null)
{
//Assert.Fail("Liste champ == null");
return;
}
//Assert.Equal(6,listeChamp.Count());
}*/
Assert.Equal(3,liste.Count());
}
[Fact]
public async Task TestGetNbChampions()
{
int nb = await controlleurChampion.GetNbItems();
Assert.Equal(6,nb);
}
}
}

@ -11,6 +11,7 @@ namespace TestUnitaireBDD
{
private void Add_Champion_Image(DbContextOptions<BDDContext> options)
{
//Image 1
Random aleatoire = new Random();
EntityLargeImage tmpImage = new EntityLargeImage();
@ -70,8 +71,8 @@ namespace TestUnitaireBDD
{
context.Database.EnsureCreated();
//Assert.Equal(3, context.Champions.Count());
//Assert.Equal("Chewbacca", context.Champions.First().Name);
Assert.Equal(10, context.Champions.Count());
Assert.Equal("Renekton", context.Champions.First().Name);
}
}
@ -93,11 +94,8 @@ namespace TestUnitaireBDD
{
context.Database.EnsureCreated();
string nameToFind = "ew";
Assert.Equal(2, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
nameToFind = "wo";
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
var ewok = context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).First();
Assert.Equal(1, context.Champions.Where(e => e.Name == "Ewok").Count());
var ewok = context.Champions.Where(n => n.Name == "Ewok").First();
ewok.Name = "Wicket";
context.SaveChanges();
}
@ -107,10 +105,8 @@ namespace TestUnitaireBDD
{
context.Database.EnsureCreated();
string nameToFind = "ew";
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
nameToFind = "wick";
Assert.Equal(1, context.Champions.Where(n => n.Name.ToLower().Contains(nameToFind)).Count());
string nameToFind = "Wicket";
Assert.Equal(1, context.Champions.Where(n => n.Name == nameToFind).Count());
}
}
@ -129,7 +125,7 @@ namespace TestUnitaireBDD
using (var context = new BDDContext(options))
{
EntityChampions tmpChamp = context.Champions.OrderBy(e => e.Name).Include(e => e.Image).First();
EntityChampions tmpChamp = context.Champions.OrderBy(e => e.Name).Include(e => e.Image).Last();
context.Remove(tmpChamp);
context.SaveChanges();
@ -137,8 +133,8 @@ namespace TestUnitaireBDD
using (var context = new BDDContext(options))
{
//Assert.Equal(2, context.Champions.Count());
//Assert.Equal("Yoda",context.Champions.First().Name);
Assert.Equal(9, context.Champions.Count());
Assert.Equal("Yoda",context.Champions.OrderBy(e => e.Name).Last().Name);
}
}
}

@ -15,17 +15,17 @@ namespace TestUnitaireBDD
{
private void Add_Image(DbContextOptions<BDDContext> options)
{
/*
EntityLargeImage tmpImage = new EntityLargeImage();
tmpImage.Id = 1;
tmpImage.Id = 97;
tmpImage.Base64 = "Inconnu";
EntityLargeImage tmpImage2 = new EntityLargeImage();
tmpImage2.Id = 2;
tmpImage2.Id = 98;
tmpImage2.Base64 = "Inconnu";
EntityLargeImage tmpImage3 = new EntityLargeImage();
tmpImage3.Id = 3;
tmpImage3.Id = 99;
tmpImage3.Base64 = "Inconnu";
//prepares the database with one instance of the context
@ -39,8 +39,8 @@ namespace TestUnitaireBDD
context.Add(tmpImage3);
context.SaveChanges();
}
*/
Assert.True(true);
}
[Fact]
@ -58,16 +58,15 @@ namespace TestUnitaireBDD
using (var context = new BDDContext(options))
{
//Assert.Equal(3,context.Images.Count());
//Assert.Equal(1,context.Images.First().Id);
Assert.True(true);
Assert.Equal(10,context.Images.Count());
Assert.Equal(1,context.Images.First().Id);
}
}
[Fact]
public void Modify_Test()
{
/*
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -80,7 +79,7 @@ namespace TestUnitaireBDD
using (var context = new BDDContext(options))
{
var image = context.Images.Where(e => e.Id == 3).First();
var image = context.Images.Where(e => e.Id == 97).First();
image.Base64 = "Modify";
context.SaveChanges();
}
@ -90,14 +89,12 @@ namespace TestUnitaireBDD
var image = context.Images.Where(e => e.Base64 == "Modify").First();
Assert.NotNull(image);
}
*/
Assert.True(true);
}
[Fact]
public void Delete_Test()
{
/*
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -110,16 +107,14 @@ namespace TestUnitaireBDD
using (var context = new BDDContext(options))
{
var image = context.Images.Where(e => e.Id == 3).First();
var image = context.Images.Where(e => e.Id == 97).First();
context.Remove(image);
context.SaveChanges();
}
using (var context = new BDDContext(options))
{
//Assert.Equal(2,context.Images.Count());
Assert.True(true);
}*/
Assert.True(true);
Assert.Equal(9,context.Images.Count());
}
}
}

@ -74,8 +74,8 @@ namespace TestUnitaireBDD
{
context.Database.EnsureCreated();
//Assert.Equal(3, context.Runes.Count());
//Assert.Equal("Chewbacca", context.Runes.First().Name);
Assert.Equal(3, context.Runes.Count());
Assert.Equal("Yoda", context.Runes.OrderBy(e => e.Name).Last().Name);
}
}
@ -133,7 +133,7 @@ namespace TestUnitaireBDD
using (var context = new BDDContext(options))
{
EntityRunes tmpChamp = context.Runes.OrderBy(e => e.Name).Include(e => e.Image).First();
EntityRunes tmpChamp = context.Runes.OrderBy(e => e.Name).Include(e => e.Image).Last();
context.Remove(tmpChamp);
context.SaveChanges();
@ -141,8 +141,8 @@ namespace TestUnitaireBDD
using (var context = new BDDContext(options))
{
//Assert.Equal(2, context.Runes.Count());
//Assert.Equal("Yoda", context.Runes.First().Name);
Assert.Equal(2, context.Runes.Count());
Assert.Equal("Ewok", context.Runes.OrderBy(e => e.Name).Last().Name);
}
}
}

@ -15,16 +15,16 @@ namespace TestUnitaireBDD
{
private void Add_Skill(DbContextOptions<BDDContext> options)
{
/*
//Image Champ
EntityLargeImage imageChamp = new EntityLargeImage();
imageChamp.Base64 = "Inconnu";
imageChamp.Id = 1;
imageChamp.Id = 99;
//Champion
EntityChampions champ = new EntityChampions { Name = "Chewbacca", Bio = "Inconnu", Icon = "Inconnu", Classe = ChampionClass.Assassin.ToString() };
champ.ImageId = imageChamp.Id;
champ.Id = 1;
champ.Id = 99;
//prepares the database with one instance of the context
using (var context = new BDDContext(options))
@ -38,14 +38,12 @@ namespace TestUnitaireBDD
context.SaveChanges();
}
*/
Assert.True(true);
}
[Fact]
public void Add_Test()
{
/*
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -61,16 +59,15 @@ namespace TestUnitaireBDD
{
context.Database.EnsureCreated();
//Assert.Equal(1, context.Skills.Count());
//Assert.Equal("toto", context.Skills.First().Name);
}*/
Assert.True(true);
Assert.Equal(1, context.Skills.Count());
Assert.Equal("toto", context.Skills.First().Name);
}
}
[Fact]
public void Modify_Test()
{
/*
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -92,15 +89,15 @@ namespace TestUnitaireBDD
//uses another instance of the context to do the tests
using (var context = new BDDContext(options))
{
//Assert.Equal("totoModify", context.Skills.First().Name);
}*/
Assert.Equal("totoModify", context.Skills.First().Name);
}
Assert.True(true);
}
[Fact]
public void Delete_Test()
{
/*
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -121,9 +118,9 @@ namespace TestUnitaireBDD
using (var context = new BDDContext(options))
{
//Assert.Equal(0, context.Skills.Count());
Assert.Equal(0, context.Skills.Count());
}
*/
Assert.True(true);
}
}

@ -15,16 +15,16 @@ namespace TestUnitaireBDD
{
private void Add_Skin(DbContextOptions<BDDContext> options)
{
/*
//Image Champ
EntityLargeImage imageChamp = new EntityLargeImage();
imageChamp.Base64 = "Inconnu";
imageChamp.Id = 1;
imageChamp.Id = 95;
//Image skin
EntityLargeImage imageSkin = new EntityLargeImage();
imageSkin.Base64 = "Inconnu";
imageSkin.Id = 2;
imageSkin.Id = 96;
//prepares the database with one instance of the context
@ -34,7 +34,7 @@ namespace TestUnitaireBDD
context.Database.EnsureCreated();
EntityChampions chewie = new EntityChampions { Name = "Chewbacca", Bio = "Inconnu", Icon = "Inconnu", Classe = ChampionClass.Assassin.ToString() };
EntitySkins skin = new EntitySkins { Description = "Inconnu", Icon = "Inconnu", Price = 1350 };
EntitySkins skin = new EntitySkins { Name = "toto",Description = "Inconnu", Icon = "Inconnu", Price = 1350 };
context.Add(imageChamp);
context.Add(imageSkin);
@ -49,14 +49,12 @@ namespace TestUnitaireBDD
context.SaveChanges();
}
*/
Assert.True(true);
}
[Fact]
public void Add_Test()
{
/*
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -72,17 +70,15 @@ namespace TestUnitaireBDD
{
context.Database.EnsureCreated();
//Assert.Equal(1, context.Skins.Count());
//Assert.Equal(1350, context.Skins.First().Price);
Assert.Equal(1, context.Skins.Count());
Assert.Equal(1350, context.Skins.First().Price);
}
*/
Assert.True(true);
}
[Fact]
public void Modify_Test()
{
/*
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -104,16 +100,14 @@ namespace TestUnitaireBDD
//uses another instance of the context to do the tests
using (var context = new BDDContext(options))
{
//Assert.Equal(100,context.Skins.First().Price);
Assert.Equal(100,context.Skins.First().Price);
}
*/
Assert.True(true);
}
[Fact]
public void Delete_Test()
{
/*
//connection must be opened to use In-memory database
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
@ -134,10 +128,8 @@ namespace TestUnitaireBDD
using (var context = new BDDContext(options))
{
//Assert.Equal(0, context.Skins.Count());
Assert.Equal(0, context.Skins.Count());
}
*/
Assert.True(true);
}
}
}

Loading…
Cancel
Save