Merge pull request 'Documentation_UT_Client' (#1) from Documentation_UT_Client into master

Reviewed-on: #1
ET_Relation_Entity
Emre KARTAL 2 years ago
commit 559af0ef92

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,4 +1,99 @@
# LolProject
<div align = center>
Realization of an API and an ORM which will be linked to a database in the theme of League of legends
![Comment cloner](doc/Images/Banner.png)
</div>
**Thème du projet** : Réalisation d'une API et d'un ORM(Entity Framework) qui seront reliés à une base de données dans le thème de League of legends <img src="https://logo-marque.com/wp-content/uploads/2020/11/League-of-Legends-Embleme.png" width="40" >
</br>
<img src="doc/Images/Title-Répartition.png" width="400">
La racine de notre gitlab est composée de deux dossiers essentiels au projet:
[**src**](src) : **Toute la partie codage de l'application**
[**doc**](doc) : **Documentation de l'application**
👉 [**Solution de l'application**](src/EntityFramework_LoL/Sources/LeagueOfLegends.sln)
<img src="doc/Images/Title-Fonctionnement.png" width="460" >
- ### Comment récupérer le projet ?
Tout d'abord si ce n'est pas fait cloner le dépôt de la branche **master/main**, pour cela copier le lien URL du dépôt git :
<div align = center>
![Comment cloner](doc/Images/HowToClone.png)
</div>
Vous pouvez le cloner via un terminal dans le répertoire que vous souhaitez en tapant la commande : **git clone https://codefirst.iut.uca.fr/git/emre.kartal/LolProject.git** ou utiliser Visual Studio et cloner en entrant le lien :
<div align = center>
![Page Visual studio](doc/Images/PageVS.png)
</div>
:information_source: *Si vous ne disposez pas de Visual Studio, allé sur le site [Microsoft Visual Studio](https://visualstudio.microsoft.com/fr/downloads/) pour pouvoir le télécharger !!!*
- ### Comment lancer Le projet Entity Framework ?
Afin de générer les migrations et les tables.
<br>
Vous devez avoir installé correctement EntityFrameworkCore, pour cela il existe la commande : **dotnet tool install --global dotnet-ef** qui peut être lancé à partir d'un terminal, si il est déjà installer mais n'a pas la bonne version : **dotnet tool update --global dotnet-ef** (oui y que le *install* qui change vous êtes perspicace)!
Aussi assurer vous d'avoir installé sur Visual Studio au préalable les package Nuget suivants :
<div align = center>
![package nuget](doc/Images/Package_Nuget.png)
</div>
Ensuite sur le terminal PowerShell ou Visual Studio, lancer la migration via la commande : **dotnet ef migrations add monNomDeMigration** (n'oublier pas de vous situer dans le dossier "/MyFlib" lorsque vous l'exécuter)!
- ### Comment voir la base de données ?
C'est bien beau toutes ces étapes mais sil n'y a pas de résultat à quoi cela sert !
Afin de visualiser la migration dans la base de données, cliquer dans l'onglet **Affichage**->**Explorateur d'objets SQL Server** :
<div align = center>
![start BD](doc/Images/Start_BD.png)
</div>
Puis dans l'Explorateur d'objets SQL Server, cliquer sur **SQL Server**-> **(localdb)\MSSQLLocalDB ...**->**Bases de données**
:information_source: *Notez qu'il est également possible d'utiliser l'Explorateur d'objets SQL Server pour ajouter, modifier ou supprimer des données dans les tables.*
<img src="doc/Images/Title-Environnement.png" width="400" >
Mon environnement de travail se base sur un outil et un langage en particulier :👇
<div align = center>
---
&nbsp; ![Docnet](https://img.shields.io/badge/Docnet-000?style=for-the-badge&logo=Docnet&logoColor=white&color=white)
&nbsp; ![C#](https://img.shields.io/badge/Csharp-000?style=for-the-badge&logo=csharp&logoColor=white&color=blue)
---
</div>
<img src="doc/Images/Title-Technicien.png" width="400" >
⚙️ Emre KARTAL
<br>
<div align = center>
© PM2
</div>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

@ -2,7 +2,6 @@
using DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -12,41 +11,54 @@ namespace ApiLol.Controllers
[ApiController]
public class ChampionsController : ControllerBase
{
IChampionsManager dataManager = new StubData().ChampionsMgr;
private readonly IDataManager _manager;
public ChampionsController(IDataManager dataManager)
{
this._manager = dataManager;
}
// GET: api/<ValuesController>
[HttpGet]
public async Task<IActionResult> Get()
{
var champions = await dataManager.GetItems(0, await dataManager.GetNbItems()); // Le await va permettre que les lignes suivantes ne s'éxécute pas
return Ok(new { result = champions.Select(c => c.ToDto())});
IEnumerable<ChampionDto> dtos = (await _manager.ChampionsMgr.GetItems(0, await _manager.ChampionsMgr.GetNbItems()))
.Select(x => x.ToDto());
return Ok(dtos);
}
// GET api/<ValuesController>/5
[HttpGet("{name}")]
public IActionResult Get(string name)
public async Task<IActionResult> Get(string name)
{
dataManager.GetItemsByName(name, 0, 1);
return NotFound();
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name,0, await _manager.ChampionsMgr.GetNbItems()))
.Select(x => x.ToDto());
if(dtos == null)
{
return NotFound();
}
return Ok(dtos);
}
// POST api/<ValuesController>
[HttpPost]
public async Task<IActionResult> Post([FromBody] ChampionDto value)
public async Task<IActionResult> Post([FromBody] ChampionDto champion)
{
//await dataManager.AddItem(value.toModel());
return Ok();
return CreatedAtAction(nameof(Get),
(await _manager.ChampionsMgr.AddItem(champion.ToModel())).ToDto());
}
// PUT api/<ValuesController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
/* // PUT api/<ValuesController>/5
[HttpPut("{name}")]
public async void Put(string name, [FromBody] ChampionDto champion)
{
}
return Ok(await _manager.ChampionsMgr.UpdateItem(, champion.ToModel()));
}*/
// DELETE api/<ValuesController>/5
[HttpDelete("{id}")]
public void Delete(int id)
[HttpDelete]
public async Task<IActionResult> Delete([FromBody] ChampionDto champion)
{
return Ok(await _manager.ChampionsMgr.DeleteItem(champion.ToModel()));
}
}
}

@ -10,7 +10,17 @@ namespace ApiLol.Mapper
return new ChampionDto()
{
Name = champion.Name,
Bio = champion.Bio,
};
}
public static Champion ToModel(this ChampionDto championDto)
{
return new Champion(championDto.Name)
{
Bio = championDto.Bio,
};
}
}
}

@ -0,0 +1,25 @@
using DTO;
using Model;
namespace ApiLol.Mapper
{
public static class RuneMapper
{
public static RuneDto ToDto(this Rune rune)
{
return new RuneDto()
{
Name = rune.Name,
Description = rune.Description,
};
}
/* public static Rune ToModel(this RuneDto rune)
{
return new Rune(rune.Name)
{
Description = rune.Description,
};
}*/
}
}

@ -0,0 +1,25 @@
using DTO;
using Model;
namespace ApiLol.Mapper
{
public static class SkillMapper
{
public static SkillDto ToDto(this Skill skill)
{
return new SkillDto()
{
Name = skill.Name,
Description = skill.Description,
};
}
/* public static Skill ToModel(this SkillDto skill)
{
return new Skill(skill.Name)
{
Description = skill.Description
};
}*/
}
}

@ -1,3 +1,6 @@
using Model;
using StubLib;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
@ -6,6 +9,7 @@ builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddSingleton<IDataManager, StubData>();
var app = builder.Build();

@ -0,0 +1,42 @@
using DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
namespace Client
{
public class ChampionHttpClient
{
private const string ApiChampions = "api/champions";
private readonly HttpClient _httpClient;
public ChampionHttpClient(HttpClient httpClient)
{
_httpClient = httpClient;
httpClient.BaseAddress = new Uri("https://localhost:7252;http://localhost:5252");
}
public async Task<IEnumerable<ChampionDto>> GetChampion()
{
var champions = await _httpClient.GetFromJsonAsync<IEnumerable<ChampionDto>>(ApiChampions);
return champions;
}
public async void Add(ChampionDto champion)
{
await _httpClient.PostAsJsonAsync<ChampionDto>(ApiChampions, champion);
}
/* public async void Delete(ChampionDto champion)
{
await _httpClient.DeleteAsync(champion);
}
public async void Update(ChampionDto champion)
{
await _httpClient.PutAsJsonAsync<ChampionDto>(ApiChampions, champion);
}*/
}
}

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ApiLol\ApiLol.csproj" />
<ProjectReference Include="..\DTO\DTO.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

@ -3,5 +3,6 @@
public class ChampionDto
{
public string Name { get; set; }
public string Bio { get; set; }
}
}

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class RuneDto
{
public string Name { get; set; }
public string Description { get; set; }
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class SkillDto
{
public string Name { get; set; }
public string Description { get; set; }
}
}

@ -17,7 +17,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiLol", "ApiLol\ApiLol.csproj", "{D59C9C7B-9BC2-4601-959D-BFA97E46D017}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{3919E408-EB12-4422-989B-C6ED4816D465}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DTO", "DTO\DTO.csproj", "{3919E408-EB12-4422-989B-C6ED4816D465}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiTests", "Tests\ApiTests\ApiTests.csproj", "{1779D8A4-2E12-47F3-BDA2-2E7F04B758EB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{464DAB04-BE65-429D-9A39-3E1BB43C521A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -49,6 +53,14 @@ Global
{3919E408-EB12-4422-989B-C6ED4816D465}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3919E408-EB12-4422-989B-C6ED4816D465}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3919E408-EB12-4422-989B-C6ED4816D465}.Release|Any CPU.Build.0 = Release|Any CPU
{1779D8A4-2E12-47F3-BDA2-2E7F04B758EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1779D8A4-2E12-47F3-BDA2-2E7F04B758EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1779D8A4-2E12-47F3-BDA2-2E7F04B758EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1779D8A4-2E12-47F3-BDA2-2E7F04B758EB}.Release|Any CPU.Build.0 = Release|Any CPU
{464DAB04-BE65-429D-9A39-3E1BB43C521A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{464DAB04-BE65-429D-9A39-3E1BB43C521A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{464DAB04-BE65-429D-9A39-3E1BB43C521A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{464DAB04-BE65-429D-9A39-3E1BB43C521A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -56,6 +68,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170}
{1779D8A4-2E12-47F3-BDA2-2E7F04B758EB} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9}

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\ApiLol\ApiLol.csproj" />
<ProjectReference Include="..\..\StubLib\StubLib.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,62 @@
using ApiLol.Controllers;
using DTO;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
namespace ApiTests
{
[TestClass]
public class ChampionsControllerTest
{
private readonly StubData stub;
private readonly ChampionsController champs;
public ChampionsControllerTest()
{
stub = new StubData();
champs = new ChampionsController(stub);
}
[TestMethod]
public async Task TestGetChampions()
{
//Arrange
//Act
var champion = await champs.Get();
//Assert
var objectResult = champion as OkObjectResult;
Assert.IsNotNull(objectResult);
var champions = objectResult?.Value as IEnumerable<ChampionDto>;
Assert.IsNotNull(champions);
Assert.AreEqual(champions.Count(), await stub.ChampionsMgr.GetNbItems());
}
[TestMethod]
public async Task TestPostChampion()
{
//Arange
var ChampionDto = new ChampionDto
{
Name = "Sylas",
Bio = "Good"
};
//Act
var championsResult = await champs.Post(ChampionDto);
//Assert
var objectResult = championsResult as CreatedAtActionResult;
Assert.IsNotNull(objectResult);
var champions = objectResult?.Value as Champion;
Assert.IsNotNull(champions);
}
}
}

@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
Loading…
Cancel
Save