Merge pull request 'Tests unitaires' (#1) from API into master
continuous-integration/drone/push Build is failing Details

Reviewed-on: #1
master
Théo DUPIN 2 years ago
commit 8f4e43998b

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

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

@ -20,6 +20,7 @@
<ItemGroup>
<ProjectReference Include="..\DBEntitiesWithStub\DBEntitiesWithStub.csproj" />
<ProjectReference Include="..\EntityFrameworkLib\EntityFrameworkLib.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>
</Project>

@ -13,6 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\EntityFrameworkLib\EntityFrameworkLib.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>
</Project>

@ -9,14 +9,14 @@ using System.Threading.Tasks;
namespace DBDataManager
{
public class DBDataManager //: IDataManager-
public class DbDataManager : IDataManager
{
//public IChampionsManager ChampionsManager => new DBChampionManager();
public IChampionsManager ChampionsMgr => throw new NotImplementedException();
//public ISkinsManager SkinsManager => throw new NotImplementedException();
public ISkinsManager SkinsMgr => throw new NotImplementedException();
//public IRunesManager RunesManager=> throw new NotImplementedException();
public IRunesManager RunesMgr => throw new NotImplementedException();
//public IRunePagesManager RunePagesManager=> throw new NotImplementedException();
public IRunePagesManager RunePagesMgr => throw new NotImplementedException();
}
}

@ -48,7 +48,7 @@ namespace Model
Description = description;
}
public Rune(string name, string description)
public Rune(string name, string description, LargeImage image)
{
this.name = name;
this.description = description;

@ -69,7 +69,7 @@ namespace Model
Price = price;
}
public Skin(string name, string description, float price)
public Skin(string name, string description, float price, LargeImage image)
{
this.name = name;
this.description = description;

@ -15,7 +15,7 @@ namespace Web_Api.Controllers
public class ChampionsController : ControllerBase
{
private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
private ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
private readonly LolContext _context;
@ -47,8 +47,7 @@ namespace Web_Api.Controllers
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
if (championSelected.Count() == 0)
{
Console.WriteLine("Aucun champion ne correspond au nom { " + name + " } !");
throw new Exception("Aucun champion ne correspond au nom { " + name + " } !");
return NotFound("Aucun champion ne correspond au nom { " + name + " } !");
}
Console.WriteLine("Le champion { " + name + " } existe");
return Ok(championSelected.Select(champion => champion?.toDTO()));
@ -63,8 +62,7 @@ namespace Web_Api.Controllers
{
champion.Bio = "Aucune bio";
}
Console.WriteLine("Le champion { " + champion.Name + " } avec pour bio { " + champion.Bio + " } a bien été ajouté");
return Ok();
return Ok("Le champion { " + champion.Name + " } avec pour bio { " + champion.Bio + " } a bien été ajouté");
}
[HttpPut("UPDATE")]
@ -74,8 +72,7 @@ namespace Web_Api.Controllers
var existingChampion = championSelected.FirstOrDefault();
if (existingChampion == null)
{
Console.WriteLine("Le champion { " + name + " } n'existe pas !");
return NotFound();
return NotFound("Le champion { " + name + " } n'existe pas !");
}
var updatedChampion = champion.toModel();
await ChampionsManager.UpdateItem(existingChampion, updatedChampion);
@ -83,8 +80,7 @@ namespace Web_Api.Controllers
{
updatedChampion.Bio = "Aucune bio";
}
Console.WriteLine("Le champion { " + name + " } a été modifié en { " + updatedChampion.Name + " } avec pour bio { " + updatedChampion.Bio + " }");
return Ok();
return Ok("Le champion { " + name + " } a été modifié en { " + updatedChampion.Name + " } avec pour bio { " + updatedChampion.Bio + " }");
}
[HttpDelete("DELETE")]
@ -93,91 +89,9 @@ namespace Web_Api.Controllers
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
if(!await ChampionsManager.DeleteItem(championSelected.FirstOrDefault()))
{
Console.WriteLine("champion { " + name + " } non trouvé !");
return NotFound();
return NotFound("champion { " + name + " } non trouvé !");
}
Console.WriteLine("champion { " + name + " } supprimé");
return Ok();
return Ok("champion { " + name + " } supprimé");
}
/*[HttpGet(Name = "GetChampionsById")]
public async Task<IActionResult> GetById()
{
}*/
/*// GET: ChampionsController
public ActionResult Index()
{
return View();
}
// GET: ChampionsController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: ChampionsController/Create
public ActionResult Create()
{
return View();
}
// POST: ChampionsController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: ChampionsController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: ChampionsController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: ChampionsController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: ChampionsController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}*/
}
}

@ -10,7 +10,7 @@ namespace Web_Api.Controllers
[Route("api/[controller]")]
public class RunesController : Controller
{
private StubData.RunesManager RunesManager { get; set; } = new StubData.RunesManager(new StubData());
private RunesManager RunesManager { get; set; } = new StubData.RunesManager(new StubData());
private readonly ILogger<RunesController> _logger;
@ -32,8 +32,7 @@ namespace Web_Api.Controllers
var runesSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
if (runesSelected.Count() == 0)
{
Console.WriteLine("Aucune rune ne correspond au nom { " + name + " } !");
throw new Exception("Aucune rune ne correspond au nom { " + name + " } !");
return NotFound("Aucune rune ne correspond au nom { " + name + " } !");
}
Console.WriteLine("La rune { " + name + " } existe");
return Ok(runesSelected.Select(runes => runes?.toDTO()));
@ -59,8 +58,7 @@ namespace Web_Api.Controllers
var existingRune = runeSelected.FirstOrDefault();
if (existingRune == null)
{
Console.WriteLine("La rune { " + name + " } n'existe pas !");
return NotFound();
return NotFound("La rune { " + name + " } n'existe pas !");
}
var updatedRune = rune.toModel();
await RunesManager.UpdateItem(existingRune, updatedRune);
@ -68,8 +66,7 @@ namespace Web_Api.Controllers
{
rune.Description = "Aucune bio";
}
Console.WriteLine("La rune { " + name + " } a été modifiée en { " + updatedRune.Name + " } avec pour description { " + rune.Description + " }");
return Ok();
return Ok("La rune { " + name + " } a été modifiée en { " + updatedRune.Name + " } avec pour description { " + rune.Description + " }");
}
[HttpDelete("DELETE")]
@ -78,85 +75,9 @@ namespace Web_Api.Controllers
var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null);
if(!await RunesManager.DeleteItem(runeSelected.FirstOrDefault()))
{
Console.WriteLine("rune { " + name + " } non trouvée !");
return NotFound();
return NotFound("rune { " + name + " } non trouvée !");
}
Console.WriteLine("rune { " + name + " } supprimée");
return Ok();
return Ok("rune { " + name + " } supprimée");
}
/*// GET: RuneController
public ActionResult Index()
{
return View();
}
// GET: RuneController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: RuneController/Create
public ActionResult Create()
{
return View();
}
// POST: RuneController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: RuneController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: RuneController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: RuneController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: RuneController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}*/
}
}

@ -9,7 +9,7 @@ namespace Web_Api.Controllers
[Route("api/[controller]")]
public class SkinsController : Controller
{
private StubData.SkinsManager SkinsManager { get; set; } = new StubData.SkinsManager(new StubData());
private SkinsManager SkinsManager { get; set; } = new StubData.SkinsManager(new StubData());
private readonly ILogger<SkinsController> _logger;
@ -58,8 +58,7 @@ namespace Web_Api.Controllers
var existingSkin = skinSelected.FirstOrDefault();
if(existingSkin == null)
{
Console.WriteLine("Le skin { " + name + " } n'existe pas !");
return NotFound();
return NotFound("Le skin { " + name + " } n'existe pas !");
}
var updatedSkin = skin.toModel();
@ -68,8 +67,7 @@ namespace Web_Api.Controllers
{
skin.Description = "Aucune bio";
}
Console.WriteLine("Le skin { " + name + " } a été modifié en " + " { " + updatedSkin.Name + " } avec pour description { " + updatedSkin.Description + " }<");
return Ok();
return Ok("Le skin { " + name + " } a été modifié en " + " { " + updatedSkin.Name + " } avec pour description { " + updatedSkin.Description + " }<");
}
[HttpDelete("DELETE")]
@ -78,85 +76,10 @@ namespace Web_Api.Controllers
var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null);
if (!await SkinsManager.DeleteItem(skinSelected.FirstOrDefault()))
{
Console.WriteLine("skin { " + name + " } non trouvé !");
return NotFound();
return NotFound("skin { " + name + " } non trouvé !");
}
Console.WriteLine("skin { " + name + " } supprimé");
return Ok();
}
/*// GET: SkinsController
public ActionResult Index()
{
return View();
}
// GET: SkinsController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: SkinsController/Create
public ActionResult Create()
{
return View();
}
// POST: SkinsController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: SkinsController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: SkinsController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: SkinsController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: SkinsController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}*/
}
}

@ -2,12 +2,22 @@ using EntityFrameworkLib;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Model;
using Web_Api.Controllers;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<LolContext>(options =>
options.UseSqlite($"DataSource=projet.Champions.db"));
builder.Services.AddDbContext<LolContext>();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetService<LolContext>();
context.Database.EnsureCreated();
}
builder.Services.AddHttpClient();
// Add services to the container.

@ -10,9 +10,11 @@ namespace Web_Api
public string Description { get; set; }
public LargeImage Image { get; set; }
public Rune toModel()
{
return new Rune(Name, Description);
return new Rune(Name, Description, Image);
}
}
}

@ -12,9 +12,11 @@ namespace Web_Api
public float Price { get; set; }
public LargeImage Image { get; set; }
public Skin toModel()
{
return new Skin(Name, Description, Price);
return new Skin(Name, Description, Price, Image);
}
}
}

@ -12,6 +12,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DBDataManager\DBDataManager.csproj" />
<ProjectReference Include="..\EntityFrameworkLib\EntityFrameworkLib.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>

Loading…
Cancel
Save