Compare commits

...

8 Commits

Author SHA1 Message Date
Lucas Delanier 6b548647c5 Merge branch 'apiLOL' of https://codefirst.iut.uca.fr/git/lucas.delanier/LOLProject into apiLOL
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas Delanier afaa2124e2 new unit test
2 years ago
Lucas DELANIER b6be7e0acd Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas DELANIER b95c61e6ef Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is passing Details
2 years ago
Lucas DELANIER 79afc5798d Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is failing Details
2 years ago
Lucas DELANIER 1a6a5a34c4 Mise à jour de '.drone.yml'
continuous-integration/drone/push Build is failing Details
2 years ago
Lucas Delanier 7dd5cc0d60 test unitaire
continuous-integration/drone/push Build is failing Details
2 years ago
Lucas Delanier 945b3f3bd9 api working in this branch
continuous-integration/drone/push Build is failing Details
2 years ago

@ -31,17 +31,17 @@ steps:
commands: commands:
- cd Sources/ - cd Sources/
- dotnet restore LeagueOfLegends.sln - dotnet restore LeagueOfLegends.sln
- dotnet sonarscanner begin /k:LOLProject /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 sonarscanner begin /k:lol /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 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" - 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" - reportgenerator -reports:"**/coverage.cobertura.xml" -reporttypes:SonarQube -targetdir:"coveragereport"
- dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release - dotnet publish LeagueOfLegends.sln -c Release --no-restore -o CI_PROJECT_DIR/build/release
- dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN} - dotnet sonarscanner end /d:sonar.login=$${PLUGIN_SONAR_TOKEN}
secrets: [ SONAR_TOKEN ] secrets: [ SECRET_SONAR_LOGIN ]
settings: settings:
sonar_host: https://codefirst.iut.uca.fr/sonar/ sonar_host: https://codefirst.iut.uca.fr/sonar/
sonar_token: sonar_token:
from_secret: SONAR_TOKEN from_secret: SECRET_SONAR_LOGIN
depends_on: [tests] depends_on: [tests]

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

@ -126,8 +126,8 @@ namespace APILOL.Controllers.v1
{ {
if(champion2.Count() == 0) if(champion2.Count() == 0)
{ {
await dataManager.UpdateItem(champion.First(), championDTO.ToModel()); var newchampion = await dataManager.UpdateItem(champion.First(), championDTO.ToModel());
return Ok(); return Ok(newchampion);
} }
_logger.LogError("champion already exist with this unique name."); _logger.LogError("champion already exist with this unique name.");

@ -1,5 +1,4 @@
using DTO; using DTO;
using EntityFrameworkLOL.Entities;
using Model; using Model;
namespace APILOL.Mapper namespace APILOL.Mapper
@ -24,21 +23,6 @@ namespace APILOL.Mapper
return new Champion(champion.Name, champion.Class, champion.Icon, champion.Image.ToString(), champion.Bio); return new Champion(champion.Name, champion.Class, champion.Icon, champion.Image.ToString(), champion.Bio);
} }
public static ChampionEntity ToEntity(this Champion item)
{
return new()
{
Name = item.Name,
Bio = item.Bio,
Icon = item.Icon,
Class = item.Class,
Image = new() { Base64 = item.Image.Base64 },
};
}
public static Champion ToModel(this ChampionEntity entity)
{
return new(entity.Name, entity.Class, entity.Icon, entity.Image.Base64, entity.Bio);
}
} }
} }

@ -18,5 +18,6 @@ namespace APILOL.Mapper
{ {
return new RunePage(runePage.Name); return new RunePage(runePage.Name);
} }
} }
} }

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.OpenApi.Models;
using Model; using Model;
using StubLib; using StubLib;
using Swashbuckle.Swagger; using Swashbuckle.Swagger;
@ -14,7 +15,11 @@ builder.Services.AddSingleton<IDataManager, StubData>();
// Add services to the container. // Add services to the container.
builder.Services.AddControllers(); builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "My API v1", Version = "v1" });
options.SwaggerDoc("v2", new OpenApiInfo { Title = "My API v2", Version = "v2" });
});
builder.Services.AddApiVersioning(opt => builder.Services.AddApiVersioning(opt =>
{ {

@ -19,12 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APILOL", "APILOL\APILOL.csp
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{1434DEF6-0575-4C3D-BF14-AF29A444BC74}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{1434DEF6-0575-4C3D-BF14-AF29A444BC74}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EntityFrameworkLOL", "EntityFrameworkLOL\EntityFrameworkLOL.csproj", "{61D807B0-FA1A-439D-9810-9F31A0C47034}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUnitaire", "TestUnitaire\TestUnitaire.csproj", "{D24FBC48-F9C3-45CA-8D51-A851559C307F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestUnitaire", "TestUnitaire\TestUnitaire.csproj", "{D24FBC48-F9C3-45CA-8D51-A851559C307F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ManagersEF", "ManagersEF\ManagersEF.csproj", "{A8685E74-67E4-4382-AF91-38045AC0014B}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -55,18 +51,10 @@ Global
{1434DEF6-0575-4C3D-BF14-AF29A444BC74}.Debug|Any CPU.Build.0 = Debug|Any CPU {1434DEF6-0575-4C3D-BF14-AF29A444BC74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1434DEF6-0575-4C3D-BF14-AF29A444BC74}.Release|Any CPU.ActiveCfg = Release|Any CPU {1434DEF6-0575-4C3D-BF14-AF29A444BC74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1434DEF6-0575-4C3D-BF14-AF29A444BC74}.Release|Any CPU.Build.0 = Release|Any CPU {1434DEF6-0575-4C3D-BF14-AF29A444BC74}.Release|Any CPU.Build.0 = Release|Any CPU
{61D807B0-FA1A-439D-9810-9F31A0C47034}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61D807B0-FA1A-439D-9810-9F31A0C47034}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61D807B0-FA1A-439D-9810-9F31A0C47034}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61D807B0-FA1A-439D-9810-9F31A0C47034}.Release|Any CPU.Build.0 = Release|Any CPU
{D24FBC48-F9C3-45CA-8D51-A851559C307F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D24FBC48-F9C3-45CA-8D51-A851559C307F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D24FBC48-F9C3-45CA-8D51-A851559C307F}.Debug|Any CPU.Build.0 = Debug|Any CPU {D24FBC48-F9C3-45CA-8D51-A851559C307F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D24FBC48-F9C3-45CA-8D51-A851559C307F}.Release|Any CPU.ActiveCfg = Release|Any CPU {D24FBC48-F9C3-45CA-8D51-A851559C307F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D24FBC48-F9C3-45CA-8D51-A851559C307F}.Release|Any CPU.Build.0 = Release|Any CPU {D24FBC48-F9C3-45CA-8D51-A851559C307F}.Release|Any CPU.Build.0 = Release|Any CPU
{A8685E74-67E4-4382-AF91-38045AC0014B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8685E74-67E4-4382-AF91-38045AC0014B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8685E74-67E4-4382-AF91-38045AC0014B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8685E74-67E4-4382-AF91-38045AC0014B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -8,7 +8,6 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Model\Model.csproj" /> <ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\EntityFrameworkLOL\EntityFrameworkLOL.csproj" />
<ProjectReference Include="..\APILOL\APILOL.csproj" /> <ProjectReference Include="..\APILOL\APILOL.csproj" />
</ItemGroup> </ItemGroup>

@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging.Abstractions;
using Model; using Model;
using StubLib; using StubLib;
using System.Web.Http; using System.Web.Http;
using System.Web.Http.Results;
using ChampionsController = APILOL.Controllers.v1.ChampionsController; using ChampionsController = APILOL.Controllers.v1.ChampionsController;
namespace TestUnitaire namespace TestUnitaire
@ -16,81 +17,115 @@ namespace TestUnitaire
[TestClass] [TestClass]
public class UnitTestChampion public class UnitTestChampion
{ {
private readonly ChampionsController controller; [TestClass]
private readonly StubData stub; public class ChampionsControllerTest
public UnitTestChampion()
{ {
stub = new StubData(); private readonly StubData stub;
controller = new ChampionsController(stub, new NullLogger<ChampionsController>()); private readonly ChampionsController championsStub;
} public ChampionsControllerTest()
{
stub = new StubData();
championsStub = new ChampionsController(stub, new NullLogger<ChampionsController>());
}
[TestMethod] [TestMethod]
public async Task TestGet() public async Task TestGetChampions()
{ {
var champions = await controller.Get(new PageRequest()); //Arrange
//Assert //Act
var resultObject = champions as OkObjectResult; var total = await stub.ChampionsMgr.GetNbItems();
Assert.IsNotNull(resultObject); var champion = await championsStub.Get(new PageRequest() { Offset = 0, Limit = 2 });
var resultType = resultObject?.Value as IEnumerable<ChampionDTO>; //Assert
Assert.IsNotNull(resultType); var objectResult = champion as OkObjectResult;
Assert.IsNotNull(objectResult);
Assert.AreEqual(resultType.Count(), await stub.ChampionsMgr.GetNbItems());
}
[TestMethod] }
public async Task TestPost()
{
//Arange [TestMethod]
var champion = new ChampionDTO public async Task TestPostChampion()
{ {
Name = "Jinx", //Arange
Bio = "Awesome , great, fantastic Q", var ChampionDto = new ChampionDTO
}; {
Name = "Winrrard",
Bio = "The amazing champ",
Class = ChampionClass.Assassin,
Icon = "",
Image = new LargeImage(""),
Skills = new List<SkillDTO>()
{
new SkillDTO() {Name = "skill", Description="Empty", Type = SkillType.Unknown}
},
};
//Act //Act
var championsResult = await controller.Post(champion); var championsResult = await championsStub.Post(ChampionDto);
//Assert //Assert
var objectResult = championsResult as CreatedAtActionResult; var objectResult = championsResult as CreatedAtActionResult;
Assert.IsNotNull(objectResult); Assert.IsNotNull(objectResult);
var champions = objectResult?.Value as ChampionDTO; var champions = objectResult?.Value as ChampionDTO;
Assert.IsNotNull(champions); Assert.IsNotNull(champions);
}
[TestMethod] Assert.AreEqual("Winrrard", champions.Name);
public async Task TestDelete()
{
//Arange
string championName = "Aatrox";
// Act Assert.AreEqual("skill", champions.Skills.First().Name);
var result = await controller.Delete(championName); Assert.AreEqual("Empty", champions.Skills.First().Description);
// Assert }
Assert.IsInstanceOfType(result, typeof(OkObjectResult));
Assert.IsTrue((await stub.ChampionsMgr.GetItemsByName(championName, 0, await stub.ChampionsMgr.GetNbItems())).Count() == 0);
}
[TestMethod]
public async Task TestUpdate()
{
//Arange
string championName = "Aatrox";
var updatedChampion = new ChampionDTO {Name = "Bibouuu", Bio = "Updated Bio" };
[TestMethod]
public async Task TestPutChampion()
{
//Arange
var ChampionDto = new ChampionDTO
{
Name = "Aatrox",
Bio = "The amazing champ",
Class = ChampionClass.Assassin,
Icon = "",
Image = new LargeImage(""),
Skills = new List<SkillDTO>()
{
new SkillDTO() {Name = "skill", Description="Empty", Type = SkillType.Unknown}
},
};
//Act
var championsResult = await championsStub.PutAsync(ChampionDto.Name, ChampionDto);
//Assert
var objectResult = championsResult as OkObjectResult;
Assert.IsNull(objectResult);
}
[TestMethod]
public async Task TestDeleteChampion()
{
//Arange
//Act
var total = await stub.ChampionsMgr.GetNbItems();
var championsResult = await championsStub.Delete("Aatrox");
//Assert
var objectResult = championsResult as OkObjectResult;
Assert.IsNotNull(objectResult);
Assert.AreNotEqual(await stub.ChampionsMgr.GetNbItems(), total);
// Act }
var result = await controller.PutAsync(championName, updatedChampion);
// Assert
Assert.IsInstanceOfType(result, typeof(OkResult));
Assert.IsNotNull(stub.ChampionsMgr.GetItemsByName("Bibouuu",0, await stub.ChampionsMgr.GetNbItems()));
} }

@ -0,0 +1,107 @@
using APILOL.Controllers.Request;
using APILOL.Controllers.v1;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging.Abstractions;
using Model;
using StubLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestUnitaire
{
[TestClass]
public class UnitTestRune
{
[TestClass]
public class RuneControllerTest
{
private readonly StubData stub;
private readonly RuneController runesStub;
public RuneControllerTest()
{
stub = new StubData();
runesStub = new RuneController(stub, new NullLogger<RuneController>());
}
[TestMethod]
public async Task TestGetRunes()
{
//Arrange
//Act
var total = await stub.RunesMgr.GetNbItems();
var rune = await runesStub.Get(new PageRequest() { Offset = 0, Limit = 2 });
//Assert
var objectResult = rune as OkObjectResult;
Assert.IsNotNull(objectResult);
}
[TestMethod]
public async Task TestPostRune()
{
//Arange
var RuneDTO = new RuneDTO { Description = "aze",Name="zz", Image="ee", Family= RuneFamily.Precision };
//Act
var runesResult = await runesStub.Post(RuneDTO);
//Assert
var objectResult = runesResult as CreatedAtActionResult;
Assert.IsNotNull(objectResult);
var runes = objectResult?.Value as RuneDTO;
Assert.IsNotNull(runes);
Assert.AreEqual("zz", runes.Name);
Assert.AreEqual("aze", runes.Description);
Assert.AreEqual("ee", runes.Image);
}
[TestMethod]
public async Task TestPutRune()
{
//Arange
var RuneDTO = new RuneDTO { Description = "aze", Name = "zz", Image = "ee", Family = RuneFamily.Precision };
//Act
var runesResult = await runesStub.PutAsync(RuneDTO.Name, RuneDTO);
//Assert
var objectResult = runesResult as OkObjectResult;
Assert.IsNull(objectResult);
}
[TestMethod]
public async Task TestDeleteRune()
{
//Act
var total = await stub.RunesMgr.GetNbItems();
var runesResult = await runesStub.Delete("Conqueror");
//Assert
var objectResult = runesResult as OkObjectResult;
Assert.IsNotNull(objectResult);
Assert.AreNotEqual(await stub.RunesMgr.GetNbItems(), total);
}
}
}
}

@ -0,0 +1,106 @@
using APILOL.Controllers.Request;
using APILOL.Controllers.v1;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging.Abstractions;
using Model;
using StubLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestUnitaire
{
[TestClass]
public class UnitTestSkin
{
[TestClass]
public class RuneControllerTest
{
private readonly StubData stub;
private readonly SkinController skinsStub;
public RuneControllerTest()
{
stub = new StubData();
skinsStub = new SkinController(stub, new NullLogger<SkinController>());
}
[TestMethod]
public async Task TestGetSkins()
{
//Arrange
//Act
var total = await stub.SkinsMgr.GetNbItems();
var rune = await skinsStub.Get(new PageRequest() { Offset = 0, Limit = 2 });
//Assert
var objectResult = rune as OkObjectResult;
Assert.IsNotNull(objectResult);
}
public async Task TestPostSkins()
{
//Arange
var skinDTO = new SkinDTO { Description = "aze", Name = "zz", Image = "ee"};
//Act
var SkinsResult = await skinsStub.Post(skinDTO);
//Assert
var objectResult = SkinsResult as CreatedAtActionResult;
var Skins = objectResult?.Value as SkinDTO;
Assert.IsNotNull(Skins);
Assert.AreEqual("zz", Skins.Name);
Assert.AreEqual("aze", Skins.Description);
Assert.AreEqual("ee", Skins.Image);
}
[TestMethod]
public async Task TestPutRune()
{
//Arange
var skinDTO = new SkinDTO { Description = "aze", Name = "zz", Image = "ee" };
//Act
var SkinsResult = await skinsStub.PutAsync(skinDTO.Name, skinDTO);
//Assert
var objectResult = SkinsResult as OkObjectResult;
Assert.IsNull(objectResult);
}
[TestMethod]
public async Task TestDeleteRune()
{
//Act
var total = await stub.SkinsMgr.GetNbItems();
var SkinsResult = await skinsStub.Delete("Black");
//Assert
var objectResult = SkinsResult as OkObjectResult;
Assert.IsNotNull(objectResult);
Assert.AreNotEqual(await stub.SkinsMgr.GetNbItems(), total);
}
}
}
}
Loading…
Cancel
Save