From f0d5fb9b2604a052547f7c980f5ffbfb63743dce Mon Sep 17 00:00:00 2001
From: Pierre Ferreira
Date: Sun, 26 Feb 2023 14:55:08 +0100
Subject: [PATCH 1/6] :green_heart: ajout de l'image de build dans la CI
:bento:
---
.drone.yml | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/.drone.yml b/.drone.yml
index b773b1b..94a89f2 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -7,19 +7,31 @@ trigger:
- push
steps:
+
+ - name: build
+ image: mcr.microsoft.com/dotnet/sdk:6.0
+ volumes:
+ - name: docs
+ path: /docs
+ commands:
+ - cd Sources/
+ - dotnet restore LeagueOfLegends.sln
+ - 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
- name: docker-build-and-push
image: plugins/docker
settings:
- dockerfile: Sources/API_LoL/Dockerfile
- context: Sources/
- registry: hub.codefirst.iut.uca.fr
- repo: hub.codefirst.iut.uca.fr/corentin.richard/entityframework_consodeservices_tp
+ dockerfile: Sources/API_LoL/Dockerfile
+ context: Sources/
+ registry: hub.codefirst.iut.uca.fr
+ repo: hub.codefirst.iut.uca.fr/corentin.richard/entityframework_consodeservices_tp
- username:
- from_secret: SECRET_REGISTRY_USERNAME
- password:
- from_secret: SECRET_REGISTRY_PASSWORD
+ username:
+ from_secret: SECRET_REGISTRY_USERNAME
+ password:
+ from_secret: SECRET_REGISTRY_PASSWORD
# docker test
- name: tests
From 0f3e4a78086785b6e60ffa048ead9549030e3d7e Mon Sep 17 00:00:00 2001
From: Pierre Ferreira
Date: Sun, 26 Feb 2023 15:32:20 +0100
Subject: [PATCH 2/6] :green_heart: mise a jour de la CI avec ajout de
code-analysis, il faut penser a mettre le master a jour car les tests ne sont
pas fonctionnel, contrairement aux autres branches :bug:
---
.drone.yml | 20 ++++++++++++++++++++
Sources/EF_UT/EntityTest.cs | 8 +++++---
Sources/EntityFramework/Skill.cs | 2 ++
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/.drone.yml b/.drone.yml
index 94a89f2..e694160 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -42,3 +42,23 @@ steps:
- dotnet test LeagueOfLegends.sln --no-restore
depends_on: [docker-build-and-push]
+ - name: code-analysis
+ image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6
+ commands:
+ - cd Sources/
+ - dotnet restore LeagueOfLegends.sln
+ - dotnet sonarscanner begin /k:entityframework_consodeservices_tp /d:sonar.host.url=$${PLUGIN_SONAR_HOST} /d:sonar.coverageReportPaths="coveragereport/SonarQube.xml" /d:sonar.coverage.exclusions="Tests/**" /d:sonar.login=$${PLUGIN_SONAR_TOKEN}
+ - dotnet build LeagueOfLegends.sln -c Release --no-restore
+ - dotnet test LeagueOfLegends.sln --logger trx --no-restore /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura --collect "XPlat Code Coverage"
+ - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport"
+ - dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release
+ - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN}
+ secrets: [ SECRET_SONAR_LOGIN ]
+ settings:
+ # accessible en ligne de commande par ${PLUGIN_SONAR_HOST}
+ sonar_host: https://codefirst.iut.uca.fr/sonar/
+ # accessible en ligne de commande par ${PLUGIN_SONAR_TOKEN}
+ sonar_token:
+ from_secret: SECRET_SONAR_LOGIN
+ depends_on: [docker-build-and-push]
+
diff --git a/Sources/EF_UT/EntityTest.cs b/Sources/EF_UT/EntityTest.cs
index 4d4ce34..d1f87b5 100644
--- a/Sources/EF_UT/EntityTest.cs
+++ b/Sources/EF_UT/EntityTest.cs
@@ -23,7 +23,7 @@ namespace EF_UT
using (var context = new LoLDbContext(options))
{
- ChampionEntity chewie = new ChampionEntity("Chewbacca","","");
+ ChampionEntity chewie = new ChampionEntity("Chewbacca", "", "");
ChampionEntity yoda = new ChampionEntity("Yoda", "", "");
ChampionEntity ewok = new ChampionEntity("Ewok", "", "");
@@ -42,6 +42,8 @@ namespace EF_UT
Assert.AreEqual("Chewbacca", context.Champions.First().Name);
}
}
+
+
[TestMethod]
public void TestUpdate()
{
@@ -52,8 +54,8 @@ namespace EF_UT
//prepares the database with one instance of the context
using (var context = new LoLDbContext(options))
{
- ChampionEntity chewie = new ChampionEntity ("Chewbacca", "", "");
- ChampionEntity yoda = new ChampionEntity ("Yoda", "", "");
+ ChampionEntity chewie = new ChampionEntity("Chewbacca", "", "");
+ ChampionEntity yoda = new ChampionEntity("Yoda", "", "");
ChampionEntity ewok = new ChampionEntity("Ewok", "", "");
context.Add(chewie);
diff --git a/Sources/EntityFramework/Skill.cs b/Sources/EntityFramework/Skill.cs
index e9b1f32..be43702 100644
--- a/Sources/EntityFramework/Skill.cs
+++ b/Sources/EntityFramework/Skill.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -10,6 +11,7 @@ namespace EntityFramework
{
public SkillType Type { get; private set; }
+ [Key]
public string Name
{
get => name;
From 7050248ff8ea91b538e2dd5a206421186251c9f0 Mon Sep 17 00:00:00 2001
From: Pierre FERREIRA
Date: Sun, 26 Feb 2023 15:43:42 +0100
Subject: [PATCH 3/6] :green_heart: fix CI
---
.drone.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.drone.yml b/.drone.yml
index e694160..138a4d0 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -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:
From 14e72b7aaf0ff3f0dacf53c6539f26f39726201a Mon Sep 17 00:00:00 2001
From: Pierre FERREIRA
Date: Sun, 26 Feb 2023 15:46:45 +0100
Subject: [PATCH 4/6] :green_heart: fix CI
---
.drone.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.drone.yml b/.drone.yml
index 138a4d0..6aec404 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -60,5 +60,5 @@ 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]
From 01de760381d2a6faf40828196f70314082c4667e Mon Sep 17 00:00:00 2001
From: Corentin R <76619184+Koroh63@users.noreply.github.com>
Date: Sun, 26 Feb 2023 16:10:41 +0100
Subject: [PATCH 5/6] Ajout pagination et filtre
---
.../Controllers/ChampionsController.cs | 54 ++++++++----
Sources/Api_UT/ChampionControllerTest.cs | 85 +++++++++++++++++++
Sources/Api_UT/UnitTest1.cs | 45 ----------
3 files changed, 124 insertions(+), 60 deletions(-)
create mode 100644 Sources/Api_UT/ChampionControllerTest.cs
delete mode 100644 Sources/Api_UT/UnitTest1.cs
diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs
index 1d4efad..4494b94 100644
--- a/Sources/API_LoL/Controllers/ChampionsController.cs
+++ b/Sources/API_LoL/Controllers/ChampionsController.cs
@@ -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/
+ // GET api//5
+
[HttpGet]
- public async Task Get()
+ public async Task 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//5
- /*
- [HttpGet("{id}")]
- public string Get(String name)
- {
- return "value";
- }*/
-
// POST api/
[HttpPost]
public async Task Post(ChampionDTO champion)
diff --git a/Sources/Api_UT/ChampionControllerTest.cs b/Sources/Api_UT/ChampionControllerTest.cs
new file mode 100644
index 0000000..16fccaa
--- /dev/null
+++ b/Sources/Api_UT/ChampionControllerTest.cs
@@ -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 list = new List {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;
+ 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();
+ }
+
+ [TestMethod]
+ public async Task Get_2First_OkListOf2()
+ {
+ List list = new List { new ChampionDTO("Akali", "", ""), new ChampionDTO("Aatrox", "", "") };
+
+ IActionResult a = await api.Get(index: 0,size: 2);
+
+ a.Should().NotBeNull();
+ a.Should().BeOfType();
+ var aObject = a as OkObjectResult;
+ aObject.Should().NotBeNull();
+ var championresult = aObject.Value as IEnumerable;
+ list.Should().BeEquivalentTo(championresult);
+ }
+
+ [TestMethod]
+ public async Task Get_FilterAName_OkListOf5()
+ {
+ List list = new List { new ChampionDTO("Akali", "", ""), new ChampionDTO("Akshan", "", "") };
+
+ IActionResult a = await api.Get(name: "Ak");
+
+ a.Should().NotBeNull();
+ a.Should().BeOfType();
+ var aObject = a as OkObjectResult;
+ aObject.Should().NotBeNull();
+ var championresult = aObject.Value as IEnumerable;
+ 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));
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/Sources/Api_UT/UnitTest1.cs b/Sources/Api_UT/UnitTest1.cs
deleted file mode 100644
index 4c934b2..0000000
--- a/Sources/Api_UT/UnitTest1.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-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 UnitTest1
- {
- [TestMethod]
- public async Task TestGet()
- {
- List list = new List {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") };
- ChampionsController api = new ChampionsController(new StubData());
- IActionResult a = await api.Get();
-
- /// utilisation du nuggets fluentAssertion
- //Assert.IsNotNull(a);
- a.Should().NotBeNull();
- //Assert.AreEqual(list,((OkObjectResult)a).Value);
- var aObject = a as OkObjectResult;
- aObject.Should().NotBeNull();
- var championresult = aObject.Value as IEnumerable;
- list.Should().BeEquivalentTo(championresult);
- }
-
- [TestMethod]
- public async Task TestPostValid()
- {
- 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));
- }
-
- }
-}
\ No newline at end of file
From 3321d55c73a95553b6d2eb82c0dac1947814ecd2 Mon Sep 17 00:00:00 2001
From: Corentin R <76619184+Koroh63@users.noreply.github.com>
Date: Sun, 26 Feb 2023 16:19:45 +0100
Subject: [PATCH 6/6] =?UTF-8?q?R=C3=A9solution=20des=20probl=C3=A8mes=20de?=
=?UTF-8?q?=20skills?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Sources/EntityFramework/ChampionEntity.cs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Sources/EntityFramework/ChampionEntity.cs b/Sources/EntityFramework/ChampionEntity.cs
index 2f859e1..856100a 100644
--- a/Sources/EntityFramework/ChampionEntity.cs
+++ b/Sources/EntityFramework/ChampionEntity.cs
@@ -28,8 +28,8 @@ namespace EntityFramework
[Required]
public string Icon { get; set; }
- public ImmutableHashSet Skills => skills.ToImmutableHashSet();
- private HashSet skills = new HashSet();
+ //public ImmutableHashSet Skills => skills.ToImmutableHashSet();
+ //private HashSet skills = new HashSet();
public ChampionEntity(string name,string bio,string icon) {
this.Name = name;
@@ -43,11 +43,11 @@ namespace EntityFramework
}
-
+/*
public bool AddSkill(Skill skill)
=> skills.Add(skill);
public bool RemoveSkill(Skill skill)
- => skills.Remove(skill);
+ => skills.Remove(skill);*/
}
}