fix merge conflit 💚
continuous-integration/drone/push Build is passing Details

pull/21/head
Pierre Ferreira 2 years ago
commit 10ab573922

@ -19,7 +19,7 @@ steps:
- dotnet build LeagueOfLegends.sln -c Release --no-restore
- dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release
# docker image build
# docker image build
- name: docker-build-and-push
image: plugins/docker
settings:
@ -60,8 +60,8 @@ steps:
# accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN}
sonar_token:
from_secret: SECRET_SONAR_LOGIN
depends_on: [docker-build-and-push]
depends_on: [tests]
# container deployment
- name: deploy-container
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dockerproxy-clientdrone:latest

@ -3,6 +3,7 @@ using Model;
using StubLib;
using DTO;
using DTO.Mapper;
using System.CodeDom.Compiler;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -19,26 +20,49 @@ namespace API_LoL.Controllers
private IChampionsManager ChampionsManager;
// GET: api/<ChampionController>
// GET api/<ChampionController>/5
[HttpGet]
public async Task<IActionResult> Get()
public async Task<IActionResult> Get(String? name= null,String? skill = null, String? characteristic = null,int index = 0,int size =10)
{
var list = await ChampionsManager.GetItems(0,await ChampionsManager.GetNbItems());
if (list.Count() != 0) {
return Ok(list.Select(champion => champion?.toDTO()));
}else {
return NoContent();
if (size - index > 10)
{
return BadRequest();
}
if (!string.IsNullOrEmpty(name))
{
var list = await ChampionsManager.GetItemsByName(name, index,size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
}else if(!string.IsNullOrEmpty(skill)) {
var list = await ChampionsManager.GetItemsBySkill(skill, index, size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
}
else if(!string.IsNullOrEmpty (characteristic)) {
var list = await ChampionsManager.GetItems(index, size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
}
else {
var list = await ChampionsManager.GetItems(index, size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
}
}
// GET api/<ChampionController>/5
/*
[HttpGet("{id}")]
public string Get(String name)
{
return "value";
}*/
// POST api/<ChampionController>
[HttpPost]
public async Task<IActionResult> Post(ChampionDTO champion)
@ -49,7 +73,7 @@ namespace API_LoL.Controllers
}
else
{
await ChampionsManager.AddItem(champion.toChampion());
await ChampionsManager.AddItem(champion.ToChampion());
return CreatedAtAction("Post",champion);
}
}

@ -9,15 +9,21 @@ namespace DTO.Mapper
{
public static class ChampionMapper
{
public static ChampionDTO toDTO(this Champion champion)
public static ChampionDTO ToDTO(this Champion champion)
{
return new ChampionDTO(champion.Name, champion.Bio, champion.Icon);
//return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Skills);
}
public static Champion toChampion(this ChampionDTO champion)
public static Champion ToChampion(this ChampionDTO champion)
{
return new Champion(champion.Name, ChampionClass.Unknown, champion.Icon, "", champion.Bio);
Champion champ = new Champion(champion.Name, ChampionClass.Unknown, champion.Icon, "", champion.Bio);
//foreach (Skill skill in champion.Skills)
//{
// champ.AddSkill(skill);
//}
return champ;
}
}
}

@ -0,0 +1,85 @@
using API_LoL.Controllers;
using DTO;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Model;
using StubLib;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace Api_UT
{
[TestClass]
public class ChampionControllerTest
{
ChampionsController api = new ChampionsController(new StubData());
[TestMethod]
public async Task Get_Default_OkList()
{
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") };
IActionResult a = await api.Get();
a.Should().NotBeNull();
var aObject = a as OkObjectResult;
aObject.Should().NotBeNull();
var championresult = aObject.Value as IEnumerable<ChampionDTO>;
list.Should().BeEquivalentTo(championresult);
}
[TestMethod]
public async Task Get_MoreThanLimit_BadRequest()
{
IActionResult a = await api.Get(index :0,size :11);
a.Should().NotBeNull();
a.Should().BeOfType<BadRequestResult>();
}
[TestMethod]
public async Task Get_2First_OkListOf2()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", ""), new ChampionDTO("Aatrox", "", "") };
IActionResult a = await api.Get(index: 0,size: 2);
a.Should().NotBeNull();
a.Should().BeOfType<OkObjectResult>();
var aObject = a as OkObjectResult;
aObject.Should().NotBeNull();
var championresult = aObject.Value as IEnumerable<ChampionDTO>;
list.Should().BeEquivalentTo(championresult);
}
[TestMethod]
public async Task Get_FilterAName_OkListOf5()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", ""), new ChampionDTO("Akshan", "", "") };
IActionResult a = await api.Get(name: "Ak");
a.Should().NotBeNull();
a.Should().BeOfType<OkObjectResult>();
var aObject = a as OkObjectResult;
aObject.Should().NotBeNull();
var championresult = aObject.Value as IEnumerable<ChampionDTO>;
list.Should().BeEquivalentTo(championresult);
}
[TestMethod]
public async Task Post_ValidChampion_Created()
{
ChampionsController api = new ChampionsController(new StubData());
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon"));
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
}
}
}

@ -2,12 +2,8 @@ using API_LoL.Controllers;
using DTO;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Model;
using StubLib;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace Api_UT
{
@ -38,7 +34,7 @@ namespace Api_UT
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon"));
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
//Assert.AreEqual<ChampionDTO>(champ,((CreatedAtActionResult)a).Value);
}
}

@ -1,4 +1,5 @@
using Model;
using System.Collections.Immutable;
namespace DTO
{
@ -11,14 +12,19 @@ namespace DTO
Icon = icon;
}
//public ChampionDTO(string name, string bio, string icon, ICollection<Skill> skills)
//{
// Name = name;
// Bio = bio;
// Icon = icon;
// Skills = skills;
//}
public string Name { get; set; }
public string Bio { get; set; }
//public ChampionClass Class { get; set; }
public string Icon { get; set; }
public bool equals(ChampionDTO other)
{
return other.Name==this.Name && other.Bio==this.Bio && other.Icon==this.Icon;

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
@ -28,13 +29,16 @@ namespace EntityFramework
[Required]
public string Icon { get; set; }
public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
private HashSet<Skill> skills = new HashSet<Skill>();
//public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
//private HashSet<Skill> skills = new HashSet<Skill>();
private ICollection<SkillEntity> Skills { get; set; }
public ChampionEntity(string name,string bio,string icon) {
this.Name = name;
this.Bio = bio;
this.Icon = icon;
Skills= new List<SkillEntity>();
}
public override string ToString()
@ -44,10 +48,10 @@ namespace EntityFramework
public bool AddSkill(Skill skill)
=> skills.Add(skill);
public void AddSkill(SkillEntity skill)
=> Skills.Add(skill);
public bool RemoveSkill(Skill skill)
=> skills.Remove(skill);
public void RemoveSkill(SkillEntity skill)
=> Skills.Remove(skill);
}
}

@ -0,0 +1,85 @@
// <auto-generated />
using System;
using EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramework.Migrations
{
[DbContext(typeof(LoLDbContext))]
[Migration("20230301152530_SkillMigration")]
partial class SkillMigration
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Champion", (string)null);
});
modelBuilder.Entity("EntityFramework.Skill", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<int?>("ChampionEntityId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ChampionEntityId");
b.ToTable("Skill");
});
modelBuilder.Entity("EntityFramework.Skill", b =>
{
b.HasOne("EntityFramework.ChampionEntity", null)
.WithMany("Skills")
.HasForeignKey("ChampionEntityId");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Navigation("Skills");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,63 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace EntityFramework.Migrations
{
/// <inheritdoc />
public partial class SkillMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Champion",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
Bio = table.Column<string>(type: "string", maxLength: 500, nullable: false),
Icon = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Champion", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Skill",
columns: table => new
{
Name = table.Column<string>(type: "TEXT", nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
ChampionEntityId = table.Column<int>(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Skill", x => x.Name);
table.ForeignKey(
name: "FK_Skill_Champion_ChampionEntityId",
column: x => x.ChampionEntityId,
principalTable: "Champion",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_Skill_ChampionEntityId",
table: "Skill",
column: "ChampionEntityId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Skill");
migrationBuilder.DropTable(
name: "Champion");
}
}
}

@ -0,0 +1,82 @@
// <auto-generated />
using System;
using EntityFramework;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace EntityFramework.Migrations
{
[DbContext(typeof(LoLDbContext))]
partial class LoLDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.2");
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Bio")
.IsRequired()
.HasMaxLength(500)
.HasColumnType("string")
.HasColumnName("Bio");
b.Property<string>("Icon")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Champion", (string)null);
});
modelBuilder.Entity("EntityFramework.Skill", b =>
{
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<int?>("ChampionEntityId")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("Name");
b.HasIndex("ChampionEntityId");
b.ToTable("Skill");
});
modelBuilder.Entity("EntityFramework.Skill", b =>
{
b.HasOne("EntityFramework.ChampionEntity", null)
.WithMany("Skills")
.HasForeignKey("ChampionEntityId");
});
modelBuilder.Entity("EntityFramework.ChampionEntity", b =>
{
b.Navigation("Skills");
});
#pragma warning restore 612, 618
}
}
}

@ -18,4 +18,20 @@ using( var context = new LoLDbContext())
{
Console.WriteLine("Not Found");
}
//Test BDD Skills
ChampionEntity champSkill = new ChampionEntity("nomSkill", "bioSkill", "iconSkill");
SkillEntity s1 = new SkillEntity("Skill1", "desc", SkillType.Unknown);
SkillEntity s2 = new SkillEntity("Skill2", "desc2", SkillType.Ultimate);
SkillEntity s3 = new SkillEntity("Skill3", "desc3", SkillType.Passive);
champSkill.AddSkill(s1);
champSkill.AddSkill(s2);
champSkill.AddSkill(s3);
context.Add(champSkill);
context.SaveChanges();
}

@ -7,10 +7,11 @@ using System.Threading.Tasks;
namespace EntityFramework
{
public class Skill
public class SkillEntity
{
public SkillType Type { get; private set; }
[Key]
public string Name
{
@ -40,5 +41,11 @@ namespace EntityFramework
}
}
private string description = "";
public SkillEntity(string Name, string Description, SkillType Type) {
this.name = Name;
this.Description = Description;
this.Type = Type;
}
}
}
Loading…
Cancel
Save