Compare commits
98 Commits
David_next
...
master
@ -1,77 +0,0 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- push
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: mcr.microsoft.com/dotnet/sdk:6.0
|
||||
volumes:
|
||||
- name: docs
|
||||
path: /docs
|
||||
commands:
|
||||
- cd EntityFramework_LoL/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: EntityFramework_LoL/Sources/Dockerfile
|
||||
context: EntityFramework_LoL/Sources/
|
||||
registry: hub.codefirst.iut.uca.fr
|
||||
repo: hub.codefirst.iut.uca.fr/git/arthur.valin/League-of-Legends_Project
|
||||
username:
|
||||
from_secret: SECRET_REGISTRY_USERNAME
|
||||
password:
|
||||
from_secret: SECRET_REGISTRY_PASSWORD
|
||||
- name: tests
|
||||
image: mcr.microsoft.com/dotnet/sdk:6.0
|
||||
commands:
|
||||
- cd EntityFramework_LoL/Sources/
|
||||
- dotnet restore LeagueOfLegends.sln
|
||||
- dotnet test LeagueOfLegends.sln --no-restore
|
||||
depends_on: [build]
|
||||
|
||||
- name: code-analysis
|
||||
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-dotnet6
|
||||
commands:
|
||||
- cd EntityFramework_LoL/Sources/
|
||||
- dotnet restore LeagueOfLegends.sln
|
||||
- dotnet sonarscanner begin /k:droneTemplate /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: [tests]
|
||||
|
||||
- name: generate-and-deploy-docs
|
||||
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer
|
||||
failure: ignore
|
||||
volumes:
|
||||
- name: docs
|
||||
path: /docs
|
||||
commands:
|
||||
#- cd Documentation/doxygen
|
||||
#- doxygen Doxyfile
|
||||
- /entrypoint.sh
|
||||
when:
|
||||
branch:
|
||||
- master
|
||||
depends_on: [ build ]
|
||||
|
||||
volumes:
|
||||
- name: docs
|
||||
temp: {}
|
Binary file not shown.
@ -1,33 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace API_LoL_Project.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
private readonly ILogger<WeatherForecastController> _logger;
|
||||
|
||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateTime.Now.AddDays(index),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +1,27 @@
|
||||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["API_LoL_Project/API_LoL_Project.csproj", "API_LoL_Project/"]
|
||||
COPY ["StubLib/StubLib.csproj", "StubLib/"]
|
||||
COPY ["Model/Model.csproj", "Model/"]
|
||||
COPY ["Shared/Shared.csproj", "Shared/"]
|
||||
COPY ["DTO/DTO.csproj", "DTO/"]
|
||||
RUN dotnet restore "API_LoL_Project/API_LoL_Project.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/API_LoL_Project"
|
||||
RUN dotnet build "API_LoL_Project.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "API_LoL_Project.csproj" -c Release -o /app/publish
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
EXPOSE 443
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["API_LoL_Project/API_LoL_Project.csproj", "API_LoL_Project/"]
|
||||
COPY ["StubLib/StubLib.csproj", "StubLib/"]
|
||||
COPY ["Model/Model.csproj", "Model/"]
|
||||
COPY ["Shared/Shared.csproj", "Shared/"]
|
||||
COPY ["DTO/DTO.csproj", "DTO/"]
|
||||
RUN dotnet restore "API_LoL_Project/API_LoL_Project.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/API_LoL_Project"
|
||||
RUN dotnet build "API_LoL_Project.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "API_LoL_Project.csproj" -c Release -o /app/publish
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
RUN ls -R
|
||||
ENTRYPOINT ["dotnet", "API_LoL_Project.dll"]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,13 +0,0 @@
|
||||
namespace API_LoL_Project
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"LolDatabase": "Data Source=Entities.LolDatabase.db"
|
||||
}
|
||||
}
|
@ -1,9 +1,16 @@
|
||||
{
|
||||
|
||||
"Authentification": {
|
||||
"ApiKey" : "ViveC#"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"LolDatabase": "Data Source=Entities.LolDatabase.db"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ApiMappeur\ApiMappeur.csproj" />
|
||||
<ProjectReference Include="..\DTO\DTO.csproj" />
|
||||
<ProjectReference Include="..\Model\Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Mapper\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DTO\DTO.csproj" />
|
||||
<ProjectReference Include="..\Entities\Entities.csproj" />
|
||||
<ProjectReference Include="..\Model\Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Entities\Entities.csproj" />
|
||||
<ProjectReference Include="..\Model\Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Model": {
|
||||
"commandName": "Project"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,197 @@
|
||||
using Business;
|
||||
using Entities;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Model;
|
||||
using Shared;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace TestEF
|
||||
{
|
||||
public class TestChampions
|
||||
{
|
||||
|
||||
[Fact]
|
||||
public async void Test_Add()
|
||||
{
|
||||
//connection must be opened to use In-memory database
|
||||
var connection = new SqliteConnection("DataSource=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<LolDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
|
||||
using (var context = new LolDbContext(options))
|
||||
{
|
||||
var manager = new DbData(context).ChampionsMgr;
|
||||
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
Champion batman = new("Batman", ChampionClass.Assassin, "icon_1", "image_1", "L'ombre de la nuit");
|
||||
batman.AddSkill(new("Bat-signal", SkillType.Basic, "Envoie le signal"));
|
||||
batman.AddCharacteristics(new[] {
|
||||
Tuple.Create("Force", 150),
|
||||
Tuple.Create("Agilité", 500)
|
||||
});
|
||||
Champion endeavor = new("Endeavor", ChampionClass.Tank, "icon_2", "image_2", "Feu brûlant énernel");
|
||||
endeavor.AddSkill(new("Final flames", SkillType.Ultimate, "Dernière flamme d'un héro"));
|
||||
endeavor.AddCharacteristics(new[] {
|
||||
Tuple.Create("Force", 200),
|
||||
Tuple.Create("Défense", 300),
|
||||
Tuple.Create("Alter", 800)
|
||||
});
|
||||
|
||||
|
||||
Champion escanor = new("Escanor", ChampionClass.Fighter, "icon_3", "image_3", "1, 2, 3, Soleil");
|
||||
escanor.AddSkill(new("Croissance solaire", SkillType.Passive, "Le soleil rends plus fort !"));
|
||||
escanor.AddCharacteristics(new[] {
|
||||
Tuple.Create("Force", 500),
|
||||
Tuple.Create("Défense", 500)
|
||||
});
|
||||
|
||||
await manager.AddItem(batman);
|
||||
await manager.AddItem(endeavor);
|
||||
await manager.AddItem(escanor);
|
||||
}
|
||||
|
||||
//uses another instance of the context to do the tests
|
||||
using (var context = new LolDbContext(options))
|
||||
{
|
||||
var manager = new DbData(context).ChampionsMgr;
|
||||
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
var nbItems = await manager.GetNbItems();
|
||||
Assert.Equal(3, nbItems);
|
||||
|
||||
var items = await manager.GetItemsByName("Batman", 0, nbItems);
|
||||
Assert.Equal("Batman", items.First().Name);
|
||||
|
||||
|
||||
Assert.Equal(2, await manager.GetNbItemsByName("E"));
|
||||
|
||||
items = await manager.GetItemsBySkill("Croissance solaire", 0, nbItems);
|
||||
Assert.Equal("Escanor", items.First().Name);
|
||||
|
||||
items = await manager.GetItemsBySkill(new Skill("Final flames", SkillType.Ultimate, "Dernière flamme d'un héro"),
|
||||
0, nbItems);
|
||||
Assert.Equal("Endeavor", items.First().Name);
|
||||
|
||||
items = await manager.GetItemsByCharacteristic("Alter", 0, nbItems);
|
||||
Assert.Equal("Endeavor", items.First().Name);
|
||||
|
||||
Assert.Equal(2, await manager.GetNbItemsByCharacteristic("Défense"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Test_Update()
|
||||
{
|
||||
//connection must be opened to use In-memory database
|
||||
var connection = new SqliteConnection("DataSource=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<LolDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
|
||||
//prepares the database with one instance of the context
|
||||
using (var context = new LolDbContext(options))
|
||||
{
|
||||
var manager = new DbData(context).ChampionsMgr;
|
||||
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
Champion batman = new("Batman", ChampionClass.Assassin, "icon_1", "image_1", "L'ombre de la nuit");
|
||||
Champion endeavor = new("Endeavor", ChampionClass.Tank, "icon_2", "image_2", "Feu brûlant énernel");
|
||||
Champion escanor = new("Escanor", ChampionClass.Fighter, "icon_3", "image_3", "1, 2, 3, Soleil");
|
||||
|
||||
await manager.AddItem(batman);
|
||||
await manager.AddItem(endeavor);
|
||||
await manager.AddItem(escanor);
|
||||
}
|
||||
|
||||
//uses another instance of the context to do the tests
|
||||
using (var context = new LolDbContext(options))
|
||||
{
|
||||
var manager = new DbData(context).ChampionsMgr;
|
||||
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
|
||||
var items = await manager.GetItemsByName("E", 0, 3);
|
||||
Assert.Equal(2, items.Count());
|
||||
|
||||
var escanor = context.champions.Where(n => n.Name.Contains("Esc")).First();
|
||||
escanor.Class = ChampionClass.Tank;
|
||||
context.SaveChanges();
|
||||
|
||||
items = await manager.GetItemsByClass(ChampionClass.Tank, 0, 3);
|
||||
Assert.Contains("Escanor", items.Select(x => x.Name));
|
||||
|
||||
Assert.Equal(2, await manager.GetNbItemsByClass(ChampionClass.Tank));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void Test_Delete()
|
||||
{
|
||||
//connection must be opened to use In-memory database
|
||||
var connection = new SqliteConnection("DataSource=:memory:");
|
||||
connection.Open();
|
||||
|
||||
var options = new DbContextOptionsBuilder<LolDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
|
||||
//prepares the database with one instance of the context
|
||||
using (var context = new LolDbContext(options))
|
||||
{
|
||||
var manager = new DbData(context).ChampionsMgr;
|
||||
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
|
||||
Champion batman = new("Batman", ChampionClass.Assassin, "icon_1", "image_1", "L'ombre de la nuit");
|
||||
batman.AddSkill(new("Charge", SkillType.Basic, "Coup de base"));
|
||||
batman.AddSkill(new("Double Saut", SkillType.Basic, ""));
|
||||
|
||||
Champion endeavor = new("Endeavor", ChampionClass.Tank, "icon_2", "image_2", "Feu brûlant énernel");
|
||||
endeavor.AddSkill(new("Charge", SkillType.Basic, "Coup de base"));
|
||||
|
||||
Champion escanor = new("Escanor", ChampionClass.Fighter, "icon_3", "image_3", "1, 2, 3, Soleil");
|
||||
escanor.AddSkill(new("Charge", SkillType.Basic, "Coup de base"));
|
||||
batman.AddSkill(new("Double Saut", SkillType.Basic, ""));
|
||||
|
||||
await manager.AddItem(batman);
|
||||
await manager.AddItem(endeavor);
|
||||
await manager.AddItem(escanor);
|
||||
}
|
||||
|
||||
//uses another instance of the context to do the tests
|
||||
using (var context = new LolDbContext(options))
|
||||
{
|
||||
var manager = new DbData(context).ChampionsMgr;
|
||||
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
var endeavor = (await manager.GetItemsByName("Endeavor", 0, 3)).First();
|
||||
|
||||
var itemsByName = await manager.DeleteItem(endeavor);
|
||||
Assert.Equal(2, await manager.GetNbItems());
|
||||
|
||||
var items = await manager.GetItems(0, await manager.GetNbItems());
|
||||
Assert.DoesNotContain("Endeavor", items.Select(x => x.Name));
|
||||
|
||||
Assert.Equal(1, await manager.GetNbItemsBySkill(new Skill("Double Saut", SkillType.Basic, "")));
|
||||
Assert.Equal(2, await manager.GetNbItemsBySkill("Charge"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,29 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Business\Business.csproj" />
|
||||
<ProjectReference Include="..\Entities\Entities.csproj" />
|
||||
<ProjectReference Include="..\Model\Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -0,0 +1 @@
|
||||
global using Xunit;
|
@ -1,46 +1,399 @@
|
||||
using API_LoL_Project.Controllers;
|
||||
using DTO;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Model;
|
||||
using StubLib;
|
||||
using System.Net;
|
||||
|
||||
namespace Test_Api
|
||||
{
|
||||
[TestClass]
|
||||
public class ChampionControllerTest
|
||||
{
|
||||
public readonly ChampionsController championCtrl;
|
||||
|
||||
public readonly IDataManager stubMgr;
|
||||
public ChampionControllerTest()
|
||||
{
|
||||
var stubMgr = new StubData();
|
||||
|
||||
championCtrl = new ChampionsController(stubMgr);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestGetChampions()
|
||||
{
|
||||
var getResult = await championCtrl.Get();
|
||||
Console.WriteLine(getResult);
|
||||
var objectRes = getResult as OkObjectResult;
|
||||
|
||||
Assert.AreEqual(200, objectRes.StatusCode);
|
||||
|
||||
Assert.IsNotNull(objectRes);
|
||||
|
||||
var champions = objectRes?.Value as IEnumerable<ChampionDTO>;
|
||||
|
||||
Assert.IsNotNull(champions);
|
||||
|
||||
/*
|
||||
Assert.AreEqual(champions.Count(), await stubMgr.ChampionsMgr.GetNbItems());*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
using API_LoL_Project.Controllers;
|
||||
using API_LoL_Project.Controllers.Request;
|
||||
using API_LoL_Project.Controllers.Response;
|
||||
using API_LoL_Project.Controllers.version2;
|
||||
using API_LoL_Project.Middleware;
|
||||
using DTO;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Model;
|
||||
using Shared;
|
||||
using StubLib;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Net;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Test_Api
|
||||
{
|
||||
[TestClass]
|
||||
public class ChampionControllerTest
|
||||
{
|
||||
public readonly ChampionsController championCtrl;
|
||||
private readonly ILogger<ChampionsController> logger = new NullLogger<ChampionsController>();
|
||||
|
||||
public readonly IDataManager stubMgr;
|
||||
public ChampionControllerTest()
|
||||
{
|
||||
stubMgr = new StubData();
|
||||
|
||||
championCtrl = new ChampionsController(stubMgr, logger);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestGetSuccesChampions()
|
||||
{
|
||||
var totalcountTest = await stubMgr.ChampionsMgr.GetNbItems();
|
||||
|
||||
// Arrange
|
||||
var request = new PageRequest
|
||||
{
|
||||
index = 0,
|
||||
count = 10,
|
||||
orderingPropertyName = "Name",
|
||||
descending = false
|
||||
};
|
||||
|
||||
// Create some test data
|
||||
var champions = new List<Champion>
|
||||
{
|
||||
|
||||
new Champion("Brand", ChampionClass.Mage),
|
||||
new Champion("Caitlyn", ChampionClass.Marksman),
|
||||
new Champion("Cassiopeia", ChampionClass.Mage)
|
||||
};
|
||||
foreach (var c in champions)
|
||||
{
|
||||
await stubMgr.ChampionsMgr.AddItem(c);
|
||||
}
|
||||
|
||||
// Act
|
||||
var getResult = await championCtrl.Get(request);
|
||||
|
||||
// Assert
|
||||
|
||||
Assert.IsInstanceOfType(getResult.Result, typeof(OkObjectResult));
|
||||
var objectRes = getResult.Result as OkObjectResult;
|
||||
Assert.AreEqual(200, objectRes.StatusCode);
|
||||
Assert.IsNotNull(objectRes);
|
||||
|
||||
var pageResponse = objectRes.Value as PageResponse<ChampionDTO>;
|
||||
Assert.IsNotNull(pageResponse);
|
||||
Assert.IsInstanceOfType(pageResponse, typeof(PageResponse<ChampionDTO>));
|
||||
Assert.AreEqual(totalcountTest + champions.Count, pageResponse.TotalCount);
|
||||
Assert.AreEqual(totalcountTest + champions.Count, pageResponse.Data.Count());
|
||||
|
||||
var endpoints = pageResponse.Data.Select(r => r.Links);
|
||||
foreach (var endpointList in endpoints)
|
||||
{
|
||||
Assert.AreEqual(4, endpointList.Count());
|
||||
Assert.IsTrue(endpointList.Any(e => e.Href.Contains("/api/[controller]/")));
|
||||
}
|
||||
|
||||
var championsDTO = pageResponse.Data.Select(r => r.Data);
|
||||
foreach (var c in championsDTO)
|
||||
{
|
||||
Assert.IsInstanceOfType(c, typeof(ChampionDTO));
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestGetChampions_When_Count_Index_Too_High()
|
||||
{
|
||||
|
||||
var totalcountTest = await stubMgr.ChampionsMgr.GetNbItems();
|
||||
|
||||
|
||||
var request = new PageRequest
|
||||
{
|
||||
index = 999,
|
||||
count = 9,
|
||||
orderingPropertyName = "Name",
|
||||
descending = false
|
||||
};
|
||||
// Act
|
||||
var getResult = await championCtrl.Get(request);
|
||||
// Assert
|
||||
var badRequestResult = getResult.Result as BadRequestObjectResult;
|
||||
Assert.IsNotNull(badRequestResult);
|
||||
Assert.AreEqual($"To many object is asked the max is : {totalcountTest}", badRequestResult.Value);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestGetBadRequest_WhenNoChampionsFound()
|
||||
{
|
||||
|
||||
// need to be empty
|
||||
List<Champion> champions = new()
|
||||
{
|
||||
new Champion("Akali", ChampionClass.Assassin),
|
||||
new Champion("Aatrox", ChampionClass.Fighter),
|
||||
new Champion("Ahri", ChampionClass.Mage),
|
||||
new Champion("Akshan", ChampionClass.Marksman),
|
||||
new Champion("Bard", ChampionClass.Support),
|
||||
new Champion("Alistar", ChampionClass.Tank),
|
||||
};
|
||||
foreach(var c in champions)
|
||||
{
|
||||
stubMgr.ChampionsMgr.DeleteItem(c);
|
||||
}
|
||||
|
||||
|
||||
var request = new PageRequest
|
||||
{
|
||||
index = 0,
|
||||
count = 10,
|
||||
orderingPropertyName = "Name",
|
||||
descending = false
|
||||
};
|
||||
|
||||
|
||||
// Act
|
||||
|
||||
var getResult = await championCtrl.Get(request);
|
||||
Console.WriteLine(getResult);
|
||||
// Assert
|
||||
var badRequestResult = getResult.Result as BadRequestObjectResult;
|
||||
Assert.IsNotNull(badRequestResult);
|
||||
Assert.AreEqual("To many object is asked the max is : 0", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestGetChampionByName_ExistingName()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
var championName = "lopalinda";
|
||||
var champion = new Champion(championName, ChampionClass.Assassin);
|
||||
await stubMgr.ChampionsMgr.AddItem(champion);
|
||||
// Act
|
||||
var getResult = await championCtrl.GetChampionsByName(championName);
|
||||
|
||||
// Assert
|
||||
/* Assert.IsInstanceOfType(getResult, typeof(OkObjectResult));
|
||||
var objectRes = getResult.Result as OkObjectResult;
|
||||
Assert.AreEqual(200, objectRes.StatusCode);
|
||||
Assert.IsInstanceOfType(okResult.Value, typeof(IEnumerable<LolResponse<ChampionFullDTO>>));
|
||||
Assert.IsNotNull(objectRes);*/
|
||||
|
||||
|
||||
Assert.IsInstanceOfType(getResult.Result, typeof(OkObjectResult));
|
||||
var okResult = getResult.Result as OkObjectResult;
|
||||
Assert.IsInstanceOfType(okResult.Value, typeof(IEnumerable<LolResponse<ChampionFullDTO>>));
|
||||
var responseList = okResult.Value as IEnumerable<LolResponse<ChampionFullDTO>>;
|
||||
Assert.AreEqual(1, responseList.Count());
|
||||
var response = responseList.First();
|
||||
Assert.AreEqual(champion.Name, response.Data.Name);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestGetChampionsByName_ReturnsBadRequest_WhenNameIsEmpty()
|
||||
{
|
||||
// Arrange
|
||||
var name = "";
|
||||
|
||||
// Act
|
||||
var result = await championCtrl.GetChampionsByName(name);
|
||||
|
||||
// Assert
|
||||
Assert.IsInstanceOfType(result.Result, typeof(BadRequestObjectResult));
|
||||
var badRequestResult = result.Result as BadRequestObjectResult;
|
||||
Assert.AreEqual("Can not get champions without the name (is empty)", badRequestResult.Value);
|
||||
}
|
||||
[TestMethod]
|
||||
public async Task TestGetChampionsByName_ReturnsBadRequest_WhenNoChampionsFound()
|
||||
{
|
||||
// Arrange
|
||||
var name = "NonExistentChampionName";
|
||||
|
||||
// Act
|
||||
var result = await championCtrl.GetChampionsByName(name);
|
||||
|
||||
// Assert
|
||||
Assert.IsInstanceOfType(result.Result, typeof(NotFoundObjectResult));
|
||||
var badRequestResult = result.Result as NotFoundObjectResult;
|
||||
Assert.AreEqual("No chamions found with this name: NonExistentChampionNamein the dataContext", badRequestResult.Value);
|
||||
}
|
||||
|
||||
|
||||
/*[TestMethod]
|
||||
public async Task TestPostChampionsSucess()
|
||||
{
|
||||
var championName = "bhbhb";
|
||||
var expectedChampion = new ChampionFullDTO()
|
||||
{
|
||||
Characteristics = new ReadOnlyDictionary<string, int>(new Dictionary<string, int>() {
|
||||
{ "health", 500 },
|
||||
{ "attack damage", 60 },
|
||||
{ "ability power", 0 }
|
||||
}),
|
||||
Name = championName,
|
||||
Bio = "Garen is a strong and noble warrior, the pride of Demacia.",
|
||||
Class = ChampionClass.Fighter,
|
||||
Icon = "https://example.com/garen-icon.png",
|
||||
LargeImage = new ImageDTO() { base64 = "xyz" },
|
||||
Skins = new List<SkinDto>() {
|
||||
new SkinDto() {
|
||||
Name = "Classic Garen",
|
||||
Description = "The default skin for Garen.",
|
||||
Icon = "https://example.com/garen-classic-icon.png",
|
||||
Price = 1350,
|
||||
LargeImage = new ImageDTO() { base64 = "xyz" }
|
||||
},
|
||||
new SkinDto() {
|
||||
Name = "God-King Garen",
|
||||
Description = "Garen as a divine being.",
|
||||
Icon = "https://example.com/garen-god-king-icon.png",
|
||||
Price = 1820,
|
||||
LargeImage = new ImageDTO() { base64 = "xyz" }
|
||||
}
|
||||
},
|
||||
Skills = new List<Skill>() {
|
||||
new Skill("Decisive Strike", SkillType.Basic, "Garen's next attack strikes a vital area of his foe, dealing bonus damage and silencing them."),
|
||||
new Skill("Courage", SkillType.Basic, "Garen passively increases his armor and magic resistance by killing enemies. He may also activate this ability to gain additional defensive statistics."),
|
||||
new Skill("Judgment", SkillType.Basic, "Garen rapidly spins his sword around his body, dealing physical damage to nearby enemies and reducing the duration of all incoming crowd control effects."),
|
||||
new Skill("Demacian Justice", SkillType.Ultimate, "Garen calls upon the might of Demacia to deal a finishing blow to an enemy champion, dealing massive damage based on their missing health.")
|
||||
}
|
||||
};
|
||||
var rep = await championCtrl.Post(expectedChampion);
|
||||
|
||||
|
||||
|
||||
Assert.AreEqual(200, objectRes.StatusCode);
|
||||
|
||||
Assert.IsNotNull(objectRes);
|
||||
|
||||
var champions = objectRes?.Value as IEnumerable<ChampionDTO>;
|
||||
|
||||
Assert.IsNotNull(champions);
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
[TestMethod]
|
||||
public async Task TestPost_ReturnsCreatedAndSavedChampion()
|
||||
{
|
||||
// Arrange
|
||||
var expectedChampion = new ChampionFullDTO()
|
||||
{
|
||||
Characteristics = new ReadOnlyDictionary<string, int>(new Dictionary<string, int>() {
|
||||
{ "health", 500 },
|
||||
{ "attack damage", 60 },
|
||||
{ "ability power", 0 }
|
||||
}),
|
||||
Name = "iuhbbhs",
|
||||
Bio = "Garen is a strong and noble warrior, the pride of Demacia.",
|
||||
Class = ChampionClass.Fighter,
|
||||
Icon = "https://example.com/garen-icon.png",
|
||||
LargeImage = new ImageDTO() { base64 = "xyz" },
|
||||
Skins = new List<SkinDto>() {
|
||||
new SkinDto() {
|
||||
Name = "Classic Garen",
|
||||
Description = "The default skin for Garen.",
|
||||
Icon = "https://example.com/garen-classic-icon.png",
|
||||
Price = 1350,
|
||||
LargeImage = new ImageDTO() { base64 = "xyz" }
|
||||
},
|
||||
new SkinDto() {
|
||||
Name = "God-King Garen",
|
||||
Description = "Garen as a divine being.",
|
||||
Icon = "https://example.com/garen-god-king-icon.png",
|
||||
Price = 1820,
|
||||
LargeImage = new ImageDTO() { base64 = "xyz" }
|
||||
}
|
||||
},
|
||||
Skills = new List<Skill>() {
|
||||
new Skill("Decisive Strike", SkillType.Basic, "Garen's next attack strikes a vital area of his foe, dealing bonus damage and silencing them."),
|
||||
new Skill("Courage", SkillType.Basic, "Garen passively increases his armor and magic resistance by killing enemies. He may also activate this ability to gain additional defensive statistics."),
|
||||
new Skill("Judgment", SkillType.Basic, "Garen rapidly spins his sword around his body, dealing physical damage to nearby enemies and reducing the duration of all incoming crowd control effects."),
|
||||
new Skill("Demacian Justice", SkillType.Ultimate, "Garen calls upon the might of Demacia to deal a finishing blow to an enemy champion, dealing massive damage based on their missing health.")
|
||||
}
|
||||
};
|
||||
|
||||
// Act
|
||||
var postResult = await championCtrl.Post(expectedChampion);
|
||||
|
||||
// Assert
|
||||
Assert.IsInstanceOfType(postResult, typeof(CreatedAtActionResult));
|
||||
var objectRes = postResult as CreatedAtActionResult;
|
||||
Assert.AreEqual(201, objectRes.StatusCode);
|
||||
Assert.IsNotNull(objectRes);
|
||||
Assert.AreEqual(nameof(championCtrl.Get), objectRes.ActionName);
|
||||
var createdChampion = objectRes.Value as ChampionDTO;
|
||||
Assert.IsNotNull(createdChampion);
|
||||
Assert.AreEqual(expectedChampion.Name, createdChampion.Name);
|
||||
Assert.AreEqual(expectedChampion.Class, createdChampion.Class);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestPutChampion()
|
||||
{
|
||||
// Arrange
|
||||
var championName = "kakarot";
|
||||
var updatedChampion = new ChampionDTO
|
||||
{
|
||||
Name = championName,
|
||||
Class = ChampionClass.Mage,
|
||||
Icon = "dsodm",
|
||||
Bio = "totto",
|
||||
};
|
||||
|
||||
await stubMgr.ChampionsMgr.AddItem(new Champion(championName, ChampionClass.Assassin));
|
||||
// Act
|
||||
var result = await championCtrl.Put(championName, updatedChampion);
|
||||
|
||||
// Assert
|
||||
Assert.IsInstanceOfType(result, typeof(OkObjectResult));
|
||||
var champion = await stubMgr.ChampionsMgr.GetItemsByName(championName, 0, 1);
|
||||
Assert.AreEqual(updatedChampion.Name, champion.First().Name);
|
||||
Assert.AreEqual(updatedChampion.Class, champion.First().Class);
|
||||
Assert.AreEqual(updatedChampion.Bio, champion.First().Bio);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestDeleteChampion()
|
||||
{
|
||||
// Arrange
|
||||
var championToDelete = new Champion("Yasuo", ChampionClass.Fighter);
|
||||
await stubMgr.ChampionsMgr.AddItem(championToDelete);
|
||||
|
||||
// Act
|
||||
var result = await championCtrl.Delete(championToDelete.Name);
|
||||
|
||||
// Assert
|
||||
Assert.IsInstanceOfType(result, typeof(OkResult));
|
||||
Assert.AreEqual(200, (result as OkResult).StatusCode);
|
||||
|
||||
var championsAfterDelete = await stubMgr.ChampionsMgr.GetItems(0, await stubMgr.ChampionsMgr.GetNbItems());
|
||||
Assert.IsFalse(championsAfterDelete.Any(c => c.Name == championToDelete.Name));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestDeleteChampionWithInvalidName()
|
||||
{
|
||||
// Arrange
|
||||
var invalidName = "Invalid Name";
|
||||
|
||||
// Act
|
||||
var result = await championCtrl.Delete(invalidName);
|
||||
|
||||
// Assert
|
||||
Assert.IsInstanceOfType(result, typeof(NotFoundObjectResult));
|
||||
Assert.AreEqual(404, (result as NotFoundObjectResult).StatusCode);
|
||||
Assert.AreEqual($"No chamions found with {invalidName} cannot delete", (result as NotFoundObjectResult).Value);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task TestDeleteChampionWithEmptyName()
|
||||
{
|
||||
// Arrange
|
||||
var emptyName = string.Empty;
|
||||
|
||||
// Act
|
||||
var result = await championCtrl.Delete(emptyName);
|
||||
|
||||
// Assert
|
||||
Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
|
||||
Assert.AreEqual(400, (result as BadRequestObjectResult).StatusCode);
|
||||
Assert.AreEqual("Can not delelte champions without the name (is empty)", (result as BadRequestObjectResult).Value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue