diff --git a/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/vcs.xml b/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/vcs.xml
index 6c0b863..830a534 100644
--- a/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/vcs.xml
+++ b/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs
index 940469f..77caa98 100644
--- a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs
+++ b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleController.cs
@@ -11,22 +11,24 @@ namespace API.Controllers
public class ArticleController : ControllerBase
{
- private readonly IArticleService _articleService;
+ //private readonly IArticleService _articleService;
+ private readonly IDataManager _dataManager;
private readonly ILogger _logger;
- public ArticleController(IArticleService articleService, ILogger logger)
+ public ArticleController(IDataManager dataManager, ILogger logger)
{
- this._articleService = articleService;
+ this._dataManager = dataManager;
this._logger = logger;
}
+ [Route("/articles")]
[HttpGet]
public async Task GetAllArticles([FromQuery] int index = 0, [FromQuery] int count = 10, [FromQuery] ArticleOrderCriteria orderCriterium = ArticleOrderCriteria.None)
{
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticles), index, count, orderCriterium);
try
{
- var result = (await _articleService.GetAllArticles(index, count, orderCriterium)).Select(a => a.ToDTO());
+ var result = (await _dataManager.ArticleService.GetAllArticles(index, count, orderCriterium)).Select(a => a.ToDTO());
if (result == null)
{
return NotFound();
@@ -46,7 +48,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleById), id);
try
{
- var result = (await _articleService.GetArticleById(id)).ToDTO();
+ var result = (await _dataManager.ArticleService.GetArticleById(id)).ToDTO();
if (result == null)
{
return NotFound($"Article ID {id} not found");
@@ -68,7 +70,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(CreateArticle), article);
try
{
- var result = (await _articleService.CreateArticle(article)).ToDTO();
+ var result = (await _dataManager.ArticleService.CreateArticle(article)).ToDTO();
if (result == null)
{
return BadRequest($"Article not created");
@@ -88,7 +90,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteArticle), id);
try
{
- var result = await _articleService.DeleteArticle(id);
+ var result = await _dataManager.ArticleService.DeleteArticle(id);
if (result == null)
{
return NotFound($"Article ID {id} not found");
@@ -108,8 +110,8 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticle), id, a);
try
{
- var result = await _articleService.UpdateArticle(id, a);
- if (result == false)
+ var result = (await _dataManager.ArticleService.UpdateArticle(id, a)).ToDTO();
+ if (result == null)
{
return NotFound($"Article ID {id} not found");
}
diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs
deleted file mode 100644
index d8baa78..0000000
--- a/Verax_API_EF/Verax_API_EF/API/Controllers/ArticleUserController.cs
+++ /dev/null
@@ -1,121 +0,0 @@
-using API_Services;
-using Entities;
-using Microsoft.AspNetCore.Mvc;
-
-namespace API.Controllers;
-
-[Route("api/[controller]")]
-[ApiController]
-public class ArticleUserController : ControllerBase
-{
-
- private readonly IArticleUserService _us;
- private readonly ILogger _logger;
- public ArticleUserController(IArticleUserService us, ILogger logger)
- {
- this._us = us;
- this._logger = logger;
- }
-
-
- [HttpGet("/articleUsers")]
- public async Task GetAllArticleUsers()
- {
- _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticleUsers), "");
- try
- {
- var result = await _us.GetAllArticleUsers();
- if (result == null)
- {
- return NoContent();
- }
- return Ok(result);
- }
- catch (Exception error)
- {
- _logger.LogError(error.Message);
- return BadRequest(error.Message);
- }
- }
-
- [HttpGet("/user/{pseudo}/article")]
- public async Task GetArticleUser(string pseudo)
- {
- _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleUser), pseudo);
- try
- {
- var result = await _us.GetArticleUser(pseudo);
- if (result == null)
- {
- return NoContent();
- }
- return Ok(result);
- }
- catch (Exception error)
- {
- _logger.LogError(error.Message);
- return BadRequest(error.Message);
- }
- }
-
- [HttpPost("/user/{pseudo}/article")]
- public async Task CreateArticleUser(ArticleUserEntity articleUser)
- {
- _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(CreateArticleUser), articleUser);
- try
- {
- var result = await _us.CreateArticleUser(articleUser);
- if (result == null)
- {
- return BadRequest($"ArticleUser {articleUser.UserEntityPseudo} already exists");
- }
- return Ok(result);
- }
- catch (Exception error)
- {
- _logger.LogError(error.Message);
- return BadRequest(error.Message);
- }
- }
-
- [HttpDelete("/user/{pseudo}/article")]
- public async Task DeleteArticleUser(string pseudo)
- {
- _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteArticleUser), pseudo);
- try
- {
- var result = await _us.DeleteArticleUser(pseudo);
- if (!result)
- {
- return BadRequest($"ArticleUser {pseudo} does not exist");
- }
- return Ok(result);
- }
- catch (Exception error)
- {
- _logger.LogError(error.Message);
- return BadRequest(error.Message);
- }
- }
-
- [HttpPut("/user/{pseudo}/article")]
- public async Task UpdateArticleUser(ArticleUserEntity articleUser)
- {
- _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticleUser), articleUser);
- try
- {
- var result = await _us.UpdateArticleUser(articleUser);
- if (!result)
- {
- return BadRequest($"ArticleUser {articleUser.UserEntityPseudo} does not exist");
- }
- return Ok(result);
- }
- catch (Exception error)
- {
- _logger.LogError(error.Message);
- return BadRequest(error.Message);
- }
- }
-
-}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/FormulaireController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/FormulaireController.cs
index 1e793a9..fcf25aa 100644
--- a/Verax_API_EF/Verax_API_EF/API/Controllers/FormulaireController.cs
+++ b/Verax_API_EF/Verax_API_EF/API/Controllers/FormulaireController.cs
@@ -12,12 +12,13 @@ namespace API.Controllers
[ApiController]
public class FormulaireController : ControllerBase
{
- private readonly IFormulaireService _form;
+ //private readonly IFormulaireService _form;
+ private readonly IDataManager _dataManager;
private readonly ILogger _logger;
- public FormulaireController(IFormulaireService iform, ILogger logger)
+ public FormulaireController(IDataManager dataManager, ILogger logger)
{
- this._form = iform;
+ this._dataManager = dataManager;
this._logger = logger;
}
@@ -27,7 +28,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllForm), index, count, orderCriteria);
try
{
- var result = (await _form.GetAllForm(index, count, orderCriteria)).Select(f => f.ToDTO());
+ var result = (await _dataManager.FormulaireService.GetAllForm(index, count, orderCriteria)).Select(f => f.ToDTO());
if (result == null)
{
return NotFound($"No form found");
@@ -48,7 +49,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetById), id);
try
{
- var result = (await _form.GetById(id)).ToDTO();
+ var result = (await _dataManager.FormulaireService.GetById(id)).ToDTO();
if (result == null)
{
return NotFound($"form ID {id} not found");
@@ -70,7 +71,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(CreateForm), formulaire);
try
{
- var result = (await _form.CreateForm(formulaire)).ToDTO();
+ var result = (await _dataManager.FormulaireService.CreateForm(formulaire)).ToDTO();
if (result == null)
{
return BadRequest($"Form Id {formulaire.Id} already exists");
@@ -90,8 +91,8 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteForm), id);
try
{
- var result = await _form.DeleteForm(id);
- if (result == false)
+ var result = (await _dataManager.FormulaireService.DeleteForm(id)).ToDTO();
+ if (result == null)
{
return NotFound($"Form Id {id} not found");
}
@@ -111,8 +112,8 @@ namespace API.Controllers
try
{
- var result = await _form.UpdateForm(id, formulaire);
- if (result == false)
+ var result = (await _dataManager.FormulaireService.UpdateForm(id, formulaire)).ToDTO();
+ if (result == null)
{
return NotFound($"form Id {id} not found");
}
diff --git a/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs b/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs
index b874e9e..5ca51f4 100644
--- a/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs
+++ b/Verax_API_EF/Verax_API_EF/API/Controllers/UserController.cs
@@ -12,12 +12,13 @@ namespace API.Controllers
[ApiController]
public class UserController : ControllerBase
{
- private readonly IUserService _us;
+ //private readonly IUserService _us;
+ private readonly IDataManager _dataManager;
private readonly ILogger _logger;
- public UserController(IUserService us, ILogger logger)
+ public UserController(IDataManager dataManager, ILogger logger)
{
- this._us = us;
this._logger = logger;
+ this._dataManager = dataManager;
}
[HttpGet("/users")]
@@ -26,7 +27,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAll), index, count, orderCriteria);
try
{
- var result = (await _us.GetAll(index, count, orderCriteria)).Select(u => u.ToDTO());
+ var result = (await _dataManager.UserService.GetAll(index, count, orderCriteria)).Select(u => u.ToDTO());
if (result == null)
{
return NotFound($"No user found with the given parameters");
@@ -46,7 +47,7 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetByPseudo), pseudo);
try
{
- var result = (await _us.GetByPseudo(pseudo)).ToDTO();
+ var result = (await _dataManager.UserService.GetByPseudo(pseudo)).ToDTO();
if (result == null)
{
return NotFound($"Psuedo {pseudo} not found");
@@ -67,8 +68,8 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(Create), user);
try
{
- var result = await _us.Create(user);
- if (result == false)
+ var result = (await _dataManager.UserService.Create(user)).ToDTO();
+ if (result == null)
{
return BadRequest($"User {user.Pseudo} already exists");
}
@@ -89,8 +90,8 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(Update), user, pseudo);
try
{
- var result = await _us.Update(user,pseudo);
- if (result == false)
+ var result = (await _dataManager.UserService.Update(user, pseudo)).ToDTO();
+ if (result == null)
{
return NotFound();
}
@@ -110,8 +111,8 @@ namespace API.Controllers
_logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(Delete), pseudo);
try
{
- var result = await _us.Delete(pseudo);
- if (result == false)
+ var result = (await _dataManager.UserService.Delete(pseudo)).ToDTO();
+ if (result == null)
{
return NotFound();
}
@@ -124,7 +125,106 @@ namespace API.Controllers
}
}
-
+ [HttpGet("/articleUsers")]
+ public async Task GetAllArticleUsers()
+ {
+ _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetAllArticleUsers), "");
+ try
+ {
+ var result = (await _dataManager.UserService.GetAllArticleUsers()).Select(u => u.ToDTO());
+ if (result == null)
+ {
+ return NoContent();
+ }
+ return Ok(result);
+ }
+ catch (Exception error)
+ {
+ _logger.LogError(error.Message);
+ return BadRequest(error.Message);
+ }
+ }
+
+ [HttpGet("/user/{pseudo}/article")]
+ public async Task GetArticleUser(string pseudo)
+ {
+ _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(GetArticleUser), pseudo);
+ try
+ {
+ var result = (await _dataManager.UserService.GetArticleUser(pseudo)).Select(a => a.ToDTO());
+ if (result == null)
+ {
+ return NoContent();
+ }
+ return Ok(result);
+ }
+ catch (Exception error)
+ {
+ _logger.LogError(error.Message);
+ return BadRequest(error.Message);
+ }
+ }
+
+ [HttpPost("/user/article")]
+ public async Task CreateArticleUser(ArticleUserEntity articleUser)
+ {
+ _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(CreateArticleUser), articleUser);
+ try
+ {
+ Console.WriteLine(articleUser);
+ var result = await _dataManager.UserService.CreateArticleUser(articleUser);
+ if (result == null)
+ {
+ return BadRequest($"ArticleUser {articleUser.UserEntityPseudo} already exists");
+ }
+ return Ok(result);
+ }
+ catch (Exception error)
+ {
+ _logger.LogError(error.Message);
+ return BadRequest(error.Message);
+ }
+ }
+
+ [HttpDelete("/user/{pseudo}/{id}")]
+ public async Task DeleteArticleUser(string pseudo, long id)
+ {
+ _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(DeleteArticleUser), pseudo);
+ try
+ {
+ var result = await _dataManager.UserService.DeleteArticleUser(pseudo, id);
+ if (!result)
+ {
+ return BadRequest($"User {pseudo} or {id} does not exist");
+ }
+ return Ok(result);
+ }
+ catch (Exception error)
+ {
+ _logger.LogError(error.Message);
+ return BadRequest(error.Message);
+ }
+ }
+
+ [HttpPut("/user/{pseudo}/article")]
+ public async Task UpdateArticleUser(ArticleUserEntity articleUser)
+ {
+ _logger.LogInformation("Executing {Action} - with parameters: {Parameters}",nameof(UpdateArticleUser), articleUser);
+ try
+ {
+ var result = (await _dataManager.UserService.UpdateArticleUser(articleUser));
+ if (!result)
+ {
+ return BadRequest($"ArticleUser {articleUser.UserEntityPseudo} does not exist");
+ }
+ return Ok(result);
+ }
+ catch (Exception error)
+ {
+ _logger.LogError(error.Message);
+ return BadRequest(error.Message);
+ }
+ }
}
diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db
index 9a47220..175a9e3 100644
Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db differ
diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm
index 6776387..d5fc9fb 100644
Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-shm differ
diff --git a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal
index 99a315d..7605da6 100644
Binary files a/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal and b/Verax_API_EF/Verax_API_EF/API/Entity_FrameWork.Article.db-wal differ
diff --git a/Verax_API_EF/Verax_API_EF/API/Program.cs b/Verax_API_EF/Verax_API_EF/API/Program.cs
index b1ae889..06fffd8 100644
--- a/Verax_API_EF/Verax_API_EF/API/Program.cs
+++ b/Verax_API_EF/Verax_API_EF/API/Program.cs
@@ -2,6 +2,7 @@ using API_Services;
using DbContextLib;
using DbDataManager;
using Microsoft.EntityFrameworkCore;
+using Model;
using StubbedContextLib;
var builder = WebApplication.CreateBuilder(args);
@@ -20,10 +21,9 @@ builder.Services.AddDbContext(options =>
options.UseSqlite("Data Source=Entity_FrameWork.Article.db");
});
-builder.Services.AddScoped();
-builder.Services.AddScoped();
-builder.Services.AddScoped();
-builder.Services.AddScoped();
+builder.Services.AddScoped();
+
+
var app = builder.Build();
@@ -39,8 +39,8 @@ app.MapControllers();
using var scoped = app.Services.CreateScope();
var libraryContext = scoped.ServiceProvider.GetService();
-libraryContext.Database.EnsureCreated();
-//libraryContext.Database.Migrate();
+//libraryContext.Database.EnsureCreated();
+libraryContext.Database.Migrate();
app.Run();
diff --git a/Verax_API_EF/Verax_API_EF/API/log.txt b/Verax_API_EF/Verax_API_EF/API/log.txt
new file mode 100644
index 0000000..7d66f59
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/API/log.txt
@@ -0,0 +1,34 @@
+info: 03/15/2024 16:59:22.173 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
+ Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
+ SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
+info: 03/15/2024 16:59:22.176 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
+ Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
+ SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
+info: 03/15/2024 16:59:22.182 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
+ Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
+ SELECT "MigrationId", "ProductVersion"
+ FROM "__EFMigrationsHistory"
+ ORDER BY "MigrationId";
+info: 03/15/2024 16:59:22.190 RelationalEventId.MigrationsNotApplied[20405] (Microsoft.EntityFrameworkCore.Migrations)
+ No migrations were applied. The database is already up to date.
+info: 03/15/2024 16:59:30.063 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
+ Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
+ SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title"
+ FROM "ArticleSet" AS "a"
+info: 03/15/2024 17:08:29.557 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
+ Executed DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
+ SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
+info: 03/15/2024 17:08:29.561 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
+ Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
+ SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
+info: 03/15/2024 17:08:29.567 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
+ Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
+ SELECT "MigrationId", "ProductVersion"
+ FROM "__EFMigrationsHistory"
+ ORDER BY "MigrationId";
+info: 03/15/2024 17:08:29.575 RelationalEventId.MigrationsNotApplied[20405] (Microsoft.EntityFrameworkCore.Migrations)
+ No migrations were applied. The database is already up to date.
+info: 03/15/2024 17:08:33.305 RelationalEventId.CommandExecuted[20101] (Microsoft.EntityFrameworkCore.Database.Command)
+ Executed DbCommand (0ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
+ SELECT "a"."Id", "a"."Author", "a"."DatePublished", "a"."Description", "a"."LectureTime", "a"."Title"
+ FROM "ArticleSet" AS "a"
diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManager.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManager.cs
index 6e4990b..d147171 100644
--- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManager.cs
+++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManager.cs
@@ -1,12 +1,30 @@
+using API_Services;
using DbContextLib;
+using Model;
namespace DbDataManager;
-public class DbManager
+public class DbManager : IDataManager
{
- protected LibraryContext _context;
+ protected LibraryContext _context { get; set; }
+
public DbManager()
{
_context = new LibraryContext();
+ ArticleService = new DbManagerArticle(_context);
+ UserService = new DbManagerUser(_context);
+ FormulaireService = new DbManagerFormulaire(_context);
}
+
+ public DbManager(LibraryContext context)
+ {
+ _context = context;
+ ArticleService = new DbManagerArticle(_context);
+ UserService = new DbManagerUser(_context);
+ FormulaireService = new DbManagerFormulaire(_context);
+ }
+
+ public IArticleService ArticleService { get; set; }
+ public IUserService UserService { get; set; }
+ public IFormulaireService FormulaireService { get; set; }
}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs
index 81405d9..9daf046 100644
--- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs
+++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticle.cs
@@ -11,9 +11,7 @@ public class DbManagerArticle : IArticleService
private readonly LibraryContext _context;
public DbManagerArticle(LibraryContext context)
- {
- _context = context;
- }
+ => this._context = context;
public async Task> GetAllArticles(int index, int count, ArticleOrderCriteria orderCriterium)
{
List articles = new List();
@@ -65,8 +63,8 @@ public class DbManagerArticle : IArticleService
LectureTime = article.LectureTime,
};
_context.ArticleSet.Add(entity);
- await _context.SaveChangesAsync();
-
+ var result = await _context.SaveChangesAsync();
+ if (result == 0) return await Task.FromResult(null);
return entity.ToModel();
}
@@ -76,22 +74,25 @@ public class DbManagerArticle : IArticleService
Console.WriteLine(entity);
if (entity == null) return null;
_context.ArticleSet.Remove(entity);
- await _context.SaveChangesAsync();
+ var result = await _context.SaveChangesAsync();
+ if (result == 0) return await Task.FromResult(null);
return entity.ToModel();
}
- public async Task UpdateArticle(long id, Article? a)
+ public async Task UpdateArticle(long id, Article? a)
{
var entity = _context.ArticleSet.FirstOrDefault(a => a.Id == id);
- if (entity == null) return false;
+ if (entity == null) return await Task.FromResult(null);
entity.Title = a.Title;
entity.Description = a.Description;
entity.Author = a.Author;
entity.DatePublished = a.DatePublished;
entity.LectureTime = a.LectureTime;
- await _context.SaveChangesAsync();
- return true;
+ var result = await _context.SaveChangesAsync();
+ if (result == 0) return await Task.FromResult(null);
+ return entity.ToModel();
}
-
+
+
}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs
deleted file mode 100644
index cad3888..0000000
--- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerArticleUser.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-using API_Services;
-using DbContextLib;
-using Entities;
-using Model;
-
-namespace DbDataManager;
-
-public class DbManagerArticleUser : IArticleUserService
-{
- private readonly LibraryContext _context;
-
- public DbManagerArticleUser(LibraryContext context)
- {
- _context = context;
- }
-
- public async Task> GetAllArticleUsers()
- {
- var entities = _context.ArticleUserSet.ToList();
- if (entities == null) return await Task.FromResult>(null);
- return await Task.FromResult(entities.AsEnumerable());
- }
-
- public async Task GetArticleUser(string pseudo)
- {
- var entity = _context.ArticleUserSet.FirstOrDefault(a => a.UserEntityPseudo.Equals(pseudo));
- if (entity == null) return await Task.FromResult(null);
- return await Task.FromResult(entity);
- }
-
-
- public async Task CreateArticleUser(ArticleUserEntity articleUser)
- {
- var result = await GetArticleUser(articleUser.UserEntityPseudo);
- if (result != null) return await Task.FromResult(null);
- var entity = new ArticleUserEntity()
- {
- ArticleEntityId = articleUser.ArticleEntityId,
- UserEntityPseudo = articleUser.UserEntityPseudo
- };
- if (entity == null) return await Task.FromResult(null);
- _context.ArticleUserSet.Add(entity);
- await _context.SaveChangesAsync();
- return await Task.FromResult(entity);
- }
-
- public async Task DeleteArticleUser(string pseudo)
- {
- var entity = _context.ArticleUserSet.FirstOrDefault(a => a.UserEntityPseudo.Equals(pseudo));
- if (entity == null) return await Task.FromResult(false);
- _context.ArticleUserSet.Remove(entity);
- await _context.SaveChangesAsync();
- return await Task.FromResult(true);
- }
-
- public async Task UpdateArticleUser(ArticleUserEntity articleUser)
- {
- var entity = _context.ArticleUserSet.FirstOrDefault(a => a.UserEntityPseudo.Equals(articleUser.UserEntityPseudo));
- if (entity == null) return await Task.FromResult(false);
- entity.ArticleEntityId = articleUser.ArticleEntityId;
- entity.UserEntityPseudo = articleUser.UserEntityPseudo;
- await _context.SaveChangesAsync();
- return await Task.FromResult(true);
- }
-
-
-}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs
index d84f9ba..914a606 100644
--- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs
+++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerFormulaire.cs
@@ -11,9 +11,7 @@ public class DbManagerFormulaire : IFormulaireService
private readonly LibraryContext _context;
public DbManagerFormulaire(LibraryContext context)
- {
- _context = context;
- }
+ => this._context = context;
public async Task> GetAllForm(int index, int count, FormOrderCriteria orderCriteria)
{
@@ -61,28 +59,31 @@ public class DbManagerFormulaire : IFormulaireService
};
_context.FormSet.Add(entity);
- await _context.SaveChangesAsync();
+ var result = await _context.SaveChangesAsync();
+ if (result == 0) return await Task.FromResult(null);
return entity.ToModel();
}
- public async Task DeleteForm(long id)
+ public async Task DeleteForm(long id)
{
var entity = _context.FormSet.FirstOrDefault(f => f.Id == id);
- if (entity == null) return false;
+ if (entity == null) return Task.FromResult(null).Result;
_context.FormSet.Remove(entity);
- await _context.SaveChangesAsync();
- return true;
+ var result = await _context.SaveChangesAsync();
+ if (result == 0) return await Task.FromResult(null);
+ return entity.ToModel();
}
- public async Task UpdateForm(long id, Formulaire formulaire)
+ public async Task UpdateForm(long id, Formulaire formulaire)
{
var entity = _context.FormSet.FirstOrDefault(f => f.Id == id);
- if (entity == null) return false;
+ if (entity == null) return Task.FromResult(null).Result;
entity.Theme = formulaire.Theme;
entity.DatePublication = formulaire.Date;
entity.Link = formulaire.Lien;
entity.UserEntityPseudo = formulaire.UserPseudo;
- await _context.SaveChangesAsync();
- return true;
+ var result = await _context.SaveChangesAsync();
+ if (result == 0) return await Task.FromResult(null);
+ return entity.ToModel();
}
}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerUser.cs b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerUser.cs
index b3928ae..5c196d7 100644
--- a/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerUser.cs
+++ b/Verax_API_EF/Verax_API_EF/API_DbDataManager/DbManagerUser.cs
@@ -11,9 +11,7 @@ public class DbManagerUser: IUserService
private readonly LibraryContext _context;
public DbManagerUser(LibraryContext context)
- {
- _context = context;
- }
+ => this._context = context;
public async Task> GetAll(int index, int count, UserOrderCriteria orderCriteria)
{
@@ -41,10 +39,11 @@ public class DbManagerUser: IUserService
public async Task GetByPseudo(string pseudo)
{
var entity = _context.UserSet.FirstOrDefault(u => u.Pseudo == pseudo);
+ if (entity == null) return await Task.FromResult(null);
return await Task.FromResult(entity.ToModel());
}
- public async Task Create(User user)
+ public async Task Create(User user)
{
var entity = new UserEntity()
{
@@ -56,32 +55,97 @@ public class DbManagerUser: IUserService
Role = user.Role
};
_context.UserSet.Add(entity);
- await _context.SaveChangesAsync();
- return true;
+ var result = await _context.SaveChangesAsync();
+ if (result == 0) return await Task.FromResult(null);
+ return await Task.FromResult(entity.ToModel());
}
- public async Task Update(User user, string pseudo)
+ public async Task Update(User user, string pseudo)
{
var entity = _context.UserSet.FirstOrDefault(u => u.Pseudo == pseudo);
- if (entity == null) return false;
+ if (entity == null) return await Task.FromResult(null);
entity.Mdp = user.Mdp;
entity.Mail = user.Mail;
entity.Role = user.Role;
entity.Prenom = user.Prenom;
entity.Nom = user.Nom;
- await _context.SaveChangesAsync();
- return true;
+ var result = await _context.SaveChangesAsync();
+ if (result == 0) return await Task.FromResult(null);
+ return await Task.FromResult(entity.ToModel());
}
- public async Task Delete(string pseudo)
+ public async Task Delete(string pseudo)
{
var entity = _context.UserSet.FirstOrDefault(u => u.Pseudo == pseudo);
- if (entity == null) return await Task.FromResult(false);
+ if (entity == null) return await Task.FromResult(null);
_context.UserSet.Remove(entity);
+ var result = await _context.SaveChangesAsync();
+ if (result == 0) return await Task.FromResult(null);
+ return await Task.FromResult(entity.ToModel());
+ }
+
+ public async Task> GetAllArticleUsers()
+ {
+ var entities = _context.ArticleUserSet.ToList();
+ List users = new List();
+ foreach( var articleUser in entities)
+ {
+ var user = _context.UserSet.FirstOrDefault(u => u.Pseudo.Equals(articleUser.UserEntityPseudo));
+ if (user != null) users.Add(user);
+ }
+ if (users == null) return await Task.FromResult>(null);
+ return await Task.FromResult(users.Select(u => u.ToModel()).AsEnumerable());
+ }
+
+
+ public async Task> GetArticleUser(string pseudo)
+ {
+ var entities = _context.ArticleUserSet.Where(a => a.UserEntityPseudo.Equals(pseudo));
+ List articles = new List();
+ foreach (var article in entities)
+ {
+ var art = _context.ArticleSet.FirstOrDefault(a => a.Id.Equals(article.ArticleEntityId));
+ if (art != null) articles.Add(art);
+ }
+ if (articles == null) return await Task.FromResult>(null);
+ return await Task.FromResult(articles.Select(a => a.ToModel()).AsEnumerable());
+ }
+
+
+ public async Task CreateArticleUser(ArticleUserEntity articleUser)
+ {
+ var result = await GetByPseudo(articleUser.UserEntityPseudo);
+ if (result == null) return await Task.FromResult(false);
+ var entity = new ArticleUserEntity()
+ {
+ ArticleEntityId = articleUser.ArticleEntityId,
+ UserEntityPseudo = articleUser.UserEntityPseudo
+ };
+ if (entity == null) return await Task.FromResult(false);
+ _context.ArticleUserSet.Add(entity);
+ await _context.SaveChangesAsync();
+ return await Task.FromResult(true);
+ }
+
+ public async Task DeleteArticleUser(string pseudo, long id)
+ {
+
+ var entity = _context.ArticleUserSet.FirstOrDefault(a => a.UserEntityPseudo.Equals(pseudo) && a.ArticleEntityId.Equals(id));
+ if (entity == null) return await Task.FromResult(false);
+ _context.ArticleUserSet.Remove(entity);
await _context.SaveChangesAsync();
return await Task.FromResult(true);
}
+ public async Task UpdateArticleUser(ArticleUserEntity articleUser)
+ {
+ var entity = _context.ArticleUserSet.FirstOrDefault(a => a.UserEntityPseudo.Equals(articleUser.UserEntityPseudo));
+ if (entity == null) return await Task.FromResult(false);
+ entity.ArticleEntityId = articleUser.ArticleEntityId;
+ entity.UserEntityPseudo = articleUser.UserEntityPseudo;
+ await _context.SaveChangesAsync();
+ return await Task.FromResult(true);
+ }
diff --git a/Verax_API_EF/Verax_API_EF/API_Mapping/FormulaireMapping.cs b/Verax_API_EF/Verax_API_EF/API_Mapping/FormulaireMapping.cs
index 8a0e631..7a779ab 100644
--- a/Verax_API_EF/Verax_API_EF/API_Mapping/FormulaireMapping.cs
+++ b/Verax_API_EF/Verax_API_EF/API_Mapping/FormulaireMapping.cs
@@ -5,7 +5,7 @@ namespace API_Mapping;
public static class FormulaireMapping
{
- public static FormulaireDTO ToDTO(this Formulaire f) => new()
+ public static FormulaireDTO ToDTO(this Formulaire? f) => new()
{
Id = f.Id,
Theme = f.Theme,
diff --git a/Verax_API_EF/Verax_API_EF/API_Mapping/UserMapping.cs b/Verax_API_EF/Verax_API_EF/API_Mapping/UserMapping.cs
index ef5cd9c..53789e6 100644
--- a/Verax_API_EF/Verax_API_EF/API_Mapping/UserMapping.cs
+++ b/Verax_API_EF/Verax_API_EF/API_Mapping/UserMapping.cs
@@ -5,7 +5,7 @@ namespace API_Mapping;
public static class UserMapping
{
- public static UserDTO ToDTO(this User u) => new()
+ public static UserDTO ToDTO(this User? u) => new()
{
Pseudo = u.Pseudo,
Mdp = u.Mdp,
diff --git a/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs b/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs
index 712ab2e..967eddf 100644
--- a/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs
+++ b/Verax_API_EF/Verax_API_EF/API_Services/IArticleService.cs
@@ -14,7 +14,7 @@ namespace API_Services
Task DeleteArticle(long id);
- Task UpdateArticle(long id, Article? a);
+ Task UpdateArticle(long id, Article? a);
}
diff --git a/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs b/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs
deleted file mode 100644
index 3a07594..0000000
--- a/Verax_API_EF/Verax_API_EF/API_Services/IArticleUserService.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Entities;
-
-namespace API_Services;
-
-public interface IArticleUserService
-{
- Task> GetAllArticleUsers();
- Task GetArticleUser(string pseudo);
-
- Task CreateArticleUser(ArticleUserEntity articleUser);
-
- Task DeleteArticleUser(string pseudo);
-
- Task UpdateArticleUser(ArticleUserEntity articleUser);
-}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_Services/IDataManager.cs b/Verax_API_EF/Verax_API_EF/API_Services/IDataManager.cs
new file mode 100644
index 0000000..d5abbc8
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/API_Services/IDataManager.cs
@@ -0,0 +1,13 @@
+namespace Model;
+using API_Services;
+
+public interface IDataManager
+{
+
+
+ IArticleService ArticleService { get; }
+ IUserService UserService { get; }
+ IFormulaireService FormulaireService { get; }
+
+}
+
diff --git a/Verax_API_EF/Verax_API_EF/API_Services/IFormulaireService.cs b/Verax_API_EF/Verax_API_EF/API_Services/IFormulaireService.cs
index 9374d8b..0b0d444 100644
--- a/Verax_API_EF/Verax_API_EF/API_Services/IFormulaireService.cs
+++ b/Verax_API_EF/Verax_API_EF/API_Services/IFormulaireService.cs
@@ -12,7 +12,7 @@ public interface IFormulaireService
Task CreateForm(Formulaire formulaire);
- Task DeleteForm(long id);
+ Task DeleteForm(long id);
- Task UpdateForm(long id, Formulaire formulaire);
+ Task UpdateForm(long id, Formulaire formulaire);
}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_Services/IUserService.cs b/Verax_API_EF/Verax_API_EF/API_Services/IUserService.cs
index 771947f..ed48afb 100644
--- a/Verax_API_EF/Verax_API_EF/API_Services/IUserService.cs
+++ b/Verax_API_EF/Verax_API_EF/API_Services/IUserService.cs
@@ -8,10 +8,19 @@ namespace API_Services
Task> GetAll(int index, int count, UserOrderCriteria orderCriteria);
Task GetByPseudo(string pseudo);
- Task Create(User user);
- Task Update(User user, string pseudo);
+ Task Create(User user);
+ Task Update(User user, string pseudo);
- Task Delete(string pseudo);
+ Task Delete(string pseudo);
+
+ Task> GetAllArticleUsers();
+ Task> GetArticleUser(string pseudo);
+
+ Task CreateArticleUser(ArticleUserEntity articleUser);
+
+ Task DeleteArticleUser(string pseudo, long id);
+
+ Task UpdateArticleUser(ArticleUserEntity articleUser);
diff --git a/Verax_API_EF/Verax_API_EF/API_Tests_Console/API_Tests_Console.csproj b/Verax_API_EF/Verax_API_EF/API_Tests_Console/API_Tests_Console.csproj
new file mode 100644
index 0000000..1faee3d
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/API_Tests_Console/API_Tests_Console.csproj
@@ -0,0 +1,15 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/Verax_API_EF/Verax_API_EF/API_Tests_Console/Tests_Console.cs b/Verax_API_EF/Verax_API_EF/API_Tests_Console/Tests_Console.cs
new file mode 100644
index 0000000..aff59a0
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/API_Tests_Console/Tests_Console.cs
@@ -0,0 +1,427 @@
+// See https://aka.ms/new-console-template for more information
+
+using System.Text;
+using System.Text.Json;
+using Entities;
+using Model;
+
+class Tests_Console
+{
+ static readonly HttpClient client = new HttpClient();
+
+
+ static async Task Main(string[] args)
+ {
+ //await TestUser();
+ await TestFormulaire();
+ //await TestArticle();
+ }
+
+ private static async Task TestFormulaire()
+ {
+ await TestFormulaireGetAll();
+ //await TestFormulaireGetId();
+ //await TestFormulaireCreate();
+ //await TestFormulaireDelete();
+ //await TestFormulaireUpdate();
+ }
+
+ private static async Task TestUser()
+ {
+ //await TestUserGetAll();
+ //await TestUserGetId();
+ //await TestUserCreate();
+ //await TestUserDelete();
+ //await TestUserUpdate();
+ //await TestGetAllArticleUser();
+ //await TestGetArticleByUser();
+ //await TestCreateArticleUser();
+ //await TestDeleteArticleUser();
+ //await TestUpdateArticleUser();
+ }
+
+
+ static async Task TestArticle()
+ {
+ await TestArticleGetId();
+ await TestArticleCreate();
+ await TestArticleGetAll();
+ await TestArticleDelete();
+ await TestArticleUpdate();
+ }
+
+ static async Task TestArticleGetAll()
+ {
+ try
+ {
+ var response = await client.GetAsync("http://localhost:5052/api/Article");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestArticleGetId()
+ {
+ try
+ {
+ var response = await client.GetAsync("http://localhost:5052/article/1");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestArticleCreate()
+ {
+ try
+ {
+ var article = new Article()
+ {
+ Title = "Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 0
+ };
+ var json = JsonSerializer.Serialize(article);
+ var data = new StringContent(json, Encoding.UTF8, "application/json");
+ var response = await client.PostAsync("http://localhost:5052/article", data);
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestArticleDelete()
+ {
+ try
+ {
+ var response = await client.DeleteAsync("http://localhost:5052/article/4");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestArticleUpdate()
+ {
+ try
+ {
+ var article = new Article()
+ {
+ Title = "Louis",
+ Description = "Je",
+ Author = "T'",
+ DatePublished = "aime",
+ LectureTime = 0
+ };
+ var json = JsonSerializer.Serialize(article);
+ var data = new StringContent(json, Encoding.UTF8, "application/json");
+ var response = await client.PutAsync("http://localhost:5052/article/1", data);
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestFormulaireGetAll()
+ {
+ try
+ {
+ var response = await client.GetAsync("http://localhost:5052/formulaires");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestFormulaireGetId()
+ {
+ try
+ {
+ var response = await client.GetAsync("http://localhost:5052/formulaire/2");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestFormulaireCreate()
+ {
+ try
+ {
+ var formulaire = new Formulaire()
+ {
+ Theme = "Test",
+ Date = "Test",
+ Lien = "Test",
+ UserPseudo = "Sha"
+ };
+ var json = JsonSerializer.Serialize(formulaire);
+ var data = new StringContent(json, Encoding.UTF8, "application/json");
+ var response = await client.PostAsync("http://localhost:5052/formulaire", data);
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestFormulaireDelete()
+ {
+ try
+ {
+ var response = await client.DeleteAsync("http://localhost:5052/formulaire/5");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestFormulaireUpdate()
+ {
+ try
+ {
+ var formulaire = new Formulaire()
+ {
+ Theme = "J'",
+ Date = "aime",
+ Lien = "Les",
+ UserPseudo = "Sha"
+ };
+ var json = JsonSerializer.Serialize(formulaire);
+ var data = new StringContent(json, Encoding.UTF8, "application/json");
+ var response = await client.PutAsync("http://localhost:5052/formulaire/4", data);
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestUserGetAll()
+ {
+ try
+ {
+ var response = await client.GetAsync("http://localhost:5052/users");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestUserGetId()
+ {
+ try
+ {
+ var response = await client.GetAsync("http://localhost:5052/user/Sha");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestUserCreate()
+ {
+ try
+ {
+ var user = new User()
+ {
+ Pseudo = "J",
+ Nom = "'",
+ Prenom = "aime",
+ Mail = "les",
+ Mdp = "pieds",
+ Role = "Admin"
+ };
+ var json = JsonSerializer.Serialize(user);
+ var data = new StringContent(json, Encoding.UTF8, "application/json");
+ var response = await client.PostAsync("http://localhost:5052/user", data);
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestUserDelete()
+ {
+ try
+ {
+ var response = await client.DeleteAsync("http://localhost:5052/user/J");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestUserUpdate()
+ {
+ try
+ {
+ var user = new User()
+ {
+ Pseudo = "Sha",
+ Nom = "J'",
+ Prenom = "aime",
+ Mail = "les",
+ Mdp = "pieds",
+ Role = "Admin"
+ };
+ var json = JsonSerializer.Serialize(user);
+ var data = new StringContent(json, Encoding.UTF8, "application/json");
+ var response = await client.PutAsync("http://localhost:5052/user/Sha", data);
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestGetAllArticleUser()
+ {
+ try
+ {
+ var response = await client.GetAsync("http://localhost:5052/ArticleUsers");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestGetArticleByUser()
+ {
+ try
+ {
+ var response = await client.GetAsync("http://localhost:5052/user/Sha/article");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestCreateArticleUser()
+ {
+ try
+ {
+ var articleUser = new ArticleUserEntity()
+ {
+ ArticleEntityId = 1,
+ UserEntityPseudo = "Sha"
+ };
+ var json = JsonSerializer.Serialize(articleUser);
+ var data = new StringContent(json, Encoding.UTF8, "application/json");
+ var response = await client.PostAsync("http://localhost:5052/user/article", data);
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestDeleteArticleUser()
+ {
+ try
+ {
+ var response = await client.DeleteAsync("http://localhost:5052/user/Sha/article");
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+ static async Task TestUpdateArticleUser()
+ {
+ try
+ {
+ var articleUser = new ArticleUserEntity()
+ {
+ ArticleEntityId = 1,
+ UserEntityPseudo = "Sha"
+ };
+ var json = JsonSerializer.Serialize(articleUser);
+ var data = new StringContent(json, Encoding.UTF8, "application/json");
+ var response = await client.PutAsync("http://localhost:5052/user/Sha/article", data);
+ response.EnsureSuccessStatusCode();
+ var responseBody = await response.Content.ReadAsStringAsync();
+ Console.WriteLine(responseBody);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine(e.Message);
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_Unit_Test/API_Unit_Test.csproj b/Verax_API_EF/Verax_API_EF/API_Unit_Test/API_Unit_Test.csproj
new file mode 100644
index 0000000..bf9fa2b
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/API_Unit_Test/API_Unit_Test.csproj
@@ -0,0 +1,30 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+ false
+ true
+
+
+
+
+
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
+
+
+
+
+
+
+
diff --git a/Verax_API_EF/Verax_API_EF/API_Unit_Test/GlobalUsings.cs b/Verax_API_EF/Verax_API_EF/API_Unit_Test/GlobalUsings.cs
new file mode 100644
index 0000000..8c927eb
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/API_Unit_Test/GlobalUsings.cs
@@ -0,0 +1 @@
+global using Xunit;
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_Unit_Test/UnitTest_Article.cs b/Verax_API_EF/Verax_API_EF/API_Unit_Test/UnitTest_Article.cs
new file mode 100644
index 0000000..0219dbd
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/API_Unit_Test/UnitTest_Article.cs
@@ -0,0 +1,129 @@
+using API_Services;
+using Model;
+using Moq;
+
+namespace API_Unit_Test;
+
+public class UnitTest_Article
+{
+
+
+
+
+
+ [Fact]
+ public void TestGetArticleById()
+ {
+ var mockArticleService = new Mock();
+ var expected = new Article()
+ {
+ Id = 1,
+ Title = "Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 10
+ };
+ mockArticleService.Setup(x => x.GetArticleById(1)).ReturnsAsync(expected);
+ var result = mockArticleService.Object.GetArticleById(1);
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ public void TestGetAllArticles()
+ {
+ var mockArticleService = new Mock();
+ var expected = new List()
+ {
+ new Article()
+ {
+ Id = 1,
+ Title = "Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 10
+ },
+ new Article()
+ {
+ Id = 2,
+ Title = "Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 10
+ }
+ };
+ mockArticleService.Setup(x => x.GetAllArticles(0, 10, ArticleOrderCriteria.None)).ReturnsAsync(expected);
+ var result = mockArticleService.Object.GetAllArticles(0, 10, ArticleOrderCriteria.None);
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ public void TestAddArticle()
+ {
+ var mockArticleService = new Mock();
+ var expected = new Article()
+ {
+ Id = 1,
+ Title = "Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 10
+ };
+ mockArticleService.Setup(x => x.CreateArticle(expected)).ReturnsAsync(expected);
+ var result = mockArticleService.Object.CreateArticle(expected);
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ public void UpdateArticle()
+ {
+ var mockArticleService = new Mock();
+ var expected = new Article()
+ {
+ Title = "Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 10
+ };
+ mockArticleService.Setup(x => x.CreateArticle(expected));
+ var result = mockArticleService.Object.CreateArticle(expected);
+ Assert.Equal(1, result.Id );
+ var updated = new Article()
+ {
+ Title = "Updated Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 10
+ };
+ mockArticleService.Setup(x => x.UpdateArticle(1, updated)).ReturnsAsync(updated);
+ var resultUpdated = mockArticleService.Object.UpdateArticle(1, updated);
+ Assert.Equal(updated ,resultUpdated.Result);
+ }
+
+ [Fact]
+ static void DeletedArticle()
+ {
+ var mockArticleService = new Mock();
+ var expected = new Article()
+ {
+ Id = 1,
+ Title = "Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 10
+ };
+ mockArticleService.Setup(x => x.CreateArticle(expected)).ReturnsAsync(expected);
+ var result = mockArticleService.Object.CreateArticle(expected);
+ Assert.Equal(expected, result.Result);
+ mockArticleService.Setup(x => x.DeleteArticle(1)).ReturnsAsync(expected);
+ var resultDeleted = mockArticleService.Object.DeleteArticle(1);
+ Assert.Equal(expected, result.Result);
+ }
+
+}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_Unit_Test/UnitTest_Form.cs b/Verax_API_EF/Verax_API_EF/API_Unit_Test/UnitTest_Form.cs
new file mode 100644
index 0000000..bc9b615
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/API_Unit_Test/UnitTest_Form.cs
@@ -0,0 +1,99 @@
+using API_Services;
+using Model;
+using Moq;
+
+namespace API_Unit_Test;
+
+public class UnitTest_Form
+{
+ [Fact]
+ public void TestGetAllForm()
+ {
+ var mockFormService = new Mock();
+ var expected = new List()
+ {
+ new Formulaire()
+ {
+ Lien = "Test",
+ Theme = "Test",
+ Date = "Test",
+ UserPseudo = "Test"
+ },
+ new Formulaire()
+ {
+ Lien = "Test",
+ Theme = "Test",
+ Date = "Test",
+ UserPseudo = "Test"
+ }
+ };
+ mockFormService.Setup(x => x.GetAllForm(0, 10, FormOrderCriteria.None)).ReturnsAsync(expected);
+ var result = mockFormService.Object.GetAllForm(0, 10, FormOrderCriteria.None);
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ public void TestGetFormById()
+ {
+ var mockFormService = new Mock();
+ var expected = new Formulaire()
+ {
+ Lien = "Test",
+ Theme = "Test",
+ Date = "Test",
+ UserPseudo = "Test"
+ };
+ mockFormService.Setup(x => x.GetById(1)).ReturnsAsync(expected);
+ var result = mockFormService.Object.GetById(1);
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ public void TestCreateForm()
+ {
+ var mockFormService = new Mock();
+ var expected = new Formulaire()
+ {
+ Lien = "Test",
+ Theme = "Test",
+ Date = "Test",
+ UserPseudo = "Test"
+ };
+ mockFormService.Setup(x => x.CreateForm(expected)).ReturnsAsync(expected);
+ var result = mockFormService.Object.CreateForm(expected);
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ public void TestUpdateForm()
+ {
+ var mockFormService = new Mock();
+ var expected = new Formulaire()
+ {
+ Lien = "Test",
+ Theme = "Test",
+ Date = "Test",
+ UserPseudo = "Test"
+ };
+ mockFormService.Setup(x => x.CreateForm(expected)).ReturnsAsync(expected);
+ var result = mockFormService.Object.CreateForm(expected);
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ public void TestDeleteForm()
+ {
+ var mockFormService = new Mock();
+ var expected = new Formulaire()
+ {
+ Lien = "Test",
+ Theme = "Test",
+ Date = "Test",
+ UserPseudo = "Test"
+ };
+ mockFormService.Setup(x => x.DeleteForm(1)).ReturnsAsync(expected);
+ var result = mockFormService.Object.DeleteForm(1);
+ Assert.Equal(expected, result.Result);
+ }
+
+}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/API_Unit_Test/UnitTest_User.cs b/Verax_API_EF/Verax_API_EF/API_Unit_Test/UnitTest_User.cs
new file mode 100644
index 0000000..9634bcd
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/API_Unit_Test/UnitTest_User.cs
@@ -0,0 +1,215 @@
+using API_Services;
+using Entities;
+using Model;
+using Moq;
+
+namespace API_Unit_Test;
+
+public class UnitTest_User
+{
+
+ [Fact]
+ static void TestAllUser()
+ {
+ var mockUserService = new Mock();
+ var expected = new List()
+ {
+ new User()
+ {
+ Pseudo = "Tofgasy",
+ Prenom = "Tony",
+ Nom = "Fages",
+ Mail = "mail@mail.com",
+ Mdp = "1234",
+ Role = "Admin"
+ },
+ new User()
+ {
+ Pseudo = "Blizzard",
+ Prenom = "Louis",
+ Nom = "Laborie",
+ Mail = "mail@mail.com",
+ Mdp = "1234",
+ Role = "Admin",
+ },
+ };
+ mockUserService.Setup(x => x.GetAll(0, 10, UserOrderCriteria.None)).ReturnsAsync(expected);
+ var result = mockUserService.Object.GetAll(0, 10, UserOrderCriteria.None);
+ Assert.Equal(expected, result.Result);
+
+ }
+
+ [Fact]
+ static void TestGetUserByPseudo()
+ {
+ var mockUserService = new Mock();
+ var expected = new User()
+ {
+ Pseudo = "Tofgasy",
+ Prenom = "Tony",
+ Nom = "Fages",
+ Mail = "mail@mail.com",
+ Mdp = "1234",
+ Role = "Admin"
+ };
+ mockUserService.Setup(x => x.GetByPseudo("Tofgasy")).ReturnsAsync(expected);
+ var result = mockUserService.Object.GetByPseudo("Tofgasy");
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ static void TestCreateUser()
+ {
+ var mockUserService = new Mock();
+ var user = new User()
+ {
+ Pseudo = "Tofgasy",
+ Prenom = "Tony",
+ Nom = "Fages",
+ Mail = "mail@mail.com",
+ Mdp = "1234",
+ Role = "Admin"
+ };
+ mockUserService.Setup(x => x.Create(user)).ReturnsAsync(user);
+ var result = mockUserService.Object.Create(user);
+ Assert.Equal( user,result.Result);
+ }
+
+ [Fact]
+ static void TestUpdateUser()
+ {
+ var mockUserService = new Mock();
+ var user = new User()
+ {
+ Pseudo = "Tofgasy",
+ Prenom = "Tonio",
+ Nom = "Fages",
+ Mail = "mail@mail.com",
+ Mdp = "1234",
+ Role = "Admin"
+ };
+ mockUserService.Setup(x => x.Update(user, "Tofgasy")).ReturnsAsync(user);
+ var result = mockUserService.Object.Update(user, "Tofgasy");
+ Assert.Equal( user,result.Result);
+ }
+
+ [Fact]
+ static void TestDeleteUser()
+ {
+ var mockUserService = new Mock();
+ var user = new User()
+ {
+ Pseudo = "Tofgasy",
+ Prenom = "Tonio",
+ Nom = "Fages",
+ Mail = "mail@mail.com",
+ Mdp = "1234",
+ Role = "Admin"
+ };
+ mockUserService.Setup(x => x.Delete("Tofgasy")).ReturnsAsync(user);
+ var result = mockUserService.Object.Delete("Tofgasy");
+ Assert.Equal( user,result.Result);
+ }
+
+
+ [Fact]
+ static void TestGetAllArticleUsers()
+ {
+ var mockUserService = new Mock();
+ var expected = new List()
+ {
+ new User()
+ {
+ Pseudo = "Tofgasy",
+ Prenom = "Tony",
+ Nom = "Fages",
+ Mail = "",
+ Mdp = "",
+ Role = "",
+ },
+ new User()
+ {
+ Pseudo = "Blizzard",
+ Prenom = "Louis",
+ Nom = "Laborie",
+ Mail = "",
+ Mdp = "",
+ Role = "",
+ },
+ };
+ mockUserService.Setup(x => x.GetAllArticleUsers()).ReturnsAsync(expected);
+ var result = mockUserService.Object.GetAllArticleUsers();
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ static void TestGetArticleUser()
+ {
+ var mockUserService = new Mock();
+ var expected = new List()
+ {
+ new Article()
+ {
+ Id = 1,
+ Title = "Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 10
+ },
+ new Article()
+ {
+ Id = 2,
+ Title = "Test",
+ Description = "Test",
+ Author = "Test",
+ DatePublished = "Test",
+ LectureTime = 10
+ }
+ };
+ mockUserService.Setup(x => x.GetArticleUser("Tofgasy")).ReturnsAsync(expected);
+ var result = mockUserService.Object.GetArticleUser("Tofgasy");
+ Assert.Equal(expected, result.Result);
+ }
+
+ [Fact]
+ static void TestCreateArticleUser()
+ {
+ var mockUserService = new Mock();
+ var articleUser = new ArticleUserEntity()
+ {
+ ArticleEntityId = 1,
+ UserEntityPseudo = "Tofgasy"
+ };
+ mockUserService.Setup(x => x.CreateArticleUser(articleUser)).ReturnsAsync(true);
+ var result = mockUserService.Object.CreateArticleUser(articleUser);
+ Assert.True(result.Result);
+ }
+
+ [Fact]
+ static void TestDeleteArticleUser()
+ {
+ var mockUserService = new Mock();
+ mockUserService.Setup(x => x.DeleteArticleUser("Tofgasy", 1)).ReturnsAsync(true);
+ var result = mockUserService.Object.DeleteArticleUser("Tofgasy", 1);
+ Assert.True(result.Result);
+ }
+
+ [Fact]
+ static void TestUpdateArticleUser()
+ {
+ var mockUserService = new Mock();
+ var articleUser = new ArticleUserEntity()
+ {
+ ArticleEntityId = 1,
+ UserEntityPseudo = "Tofgasy"
+ };
+ mockUserService.Setup(x => x.UpdateArticleUser(articleUser)).ReturnsAsync(true);
+ var result = mockUserService.Object.UpdateArticleUser(articleUser);
+ Assert.True(result.Result);
+ }
+
+
+
+}
+
diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs
index 08e8dba..c62563b 100644
--- a/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs
+++ b/Verax_API_EF/Verax_API_EF/DbContextLib/LibraryContext.cs
@@ -1,28 +1,37 @@
using Entities;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Logging;
namespace DbContextLib;
public class LibraryContext : DbContext
{
+
public LibraryContext()
: base()
- { }
+ {
+ }
public LibraryContext(DbContextOptions options)
: base(options)
- { }
-
-
-
+ {
+ }
+
+
+
public DbSet ArticleSet { get; set; }
public DbSet UserSet { get; set; }
public DbSet FormSet { get; set; }
-
+
public DbSet ArticleUserSet { get; set; }
-
+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
+ optionsBuilder.LogTo(message =>
+ {
+ using var logFile = new StreamWriter("log.txt", append: true);
+ logFile.WriteLine(message);
+ }, LogLevel.Information);
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite($"Data Source=Entity_FrameWork.Article.db");
@@ -37,17 +46,17 @@ public class LibraryContext : DbContext
.HasMany(a => a.Users)
.WithMany(a => a.Articles)
.UsingEntity();
-
+
modelBuilder.Entity()
.HasMany(u => u.Forms)
.WithOne(f => f.User)
.HasForeignKey(f => f.UserEntityPseudo);
-
+
modelBuilder.Entity()
.HasOne(f => f.User)
.WithMany(u => u.Forms)
.HasForeignKey(f => f.UserEntityPseudo);
-
+ /*
modelBuilder.Entity().HasData(
new ArticleEntity
{
@@ -76,7 +85,7 @@ public class LibraryContext : DbContext
Description = "M&M's new recipe is out and it's the best chocolate ever",
DatePublished = "2022-02-06",
LectureTime = 1,
- Author = "M&M's Red"
+ Author = "M&M's Red"
}
);
@@ -103,7 +112,7 @@ public class LibraryContext : DbContext
Nom = "Sillard", Prenom = "Noa", Pseudo = "NoaSil", Mail = "", Mdp = "1234", Role = "Admin"
}
);
-
+
modelBuilder.Entity().HasData(
new ArticleUserEntity
{
@@ -131,11 +140,11 @@ public class LibraryContext : DbContext
UserEntityPseudo = "TomS"
}
);
-
+
modelBuilder.Entity().HasData(
new FormEntity
{
- Id = 1,
+ Id = 1,
DatePublication = "Form 1 Description",
Link = "hhtp://form1.com",
UserEntityPseudo = "Sha"
@@ -155,5 +164,6 @@ public class LibraryContext : DbContext
UserEntityPseudo = "Sha"
}
);
+ */
}
}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.Designer.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240312155559_mrg1.Designer.cs
similarity index 86%
rename from Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.Designer.cs
rename to Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240312155559_mrg1.Designer.cs
index 6c21748..850cf0c 100644
--- a/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.Designer.cs
+++ b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240312155559_mrg1.Designer.cs
@@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace DbContextLib.Migrations
{
[DbContext(typeof(LibraryContext))]
- [Migration("20240311132206_mrg1")]
+ [Migration("20240312155559_mrg1")]
partial class mrg1
{
///
@@ -83,12 +83,12 @@ namespace DbContextLib.Migrations
b.Property("ArticleEntityId")
.HasColumnType("INTEGER");
- b.Property("UserEntityId")
- .HasColumnType("INTEGER");
+ b.Property("UserEntityPseudo")
+ .HasColumnType("TEXT");
- b.HasKey("ArticleEntityId", "UserEntityId");
+ b.HasKey("ArticleEntityId", "UserEntityPseudo");
- b.HasIndex("UserEntityId");
+ b.HasIndex("UserEntityPseudo");
b.ToTable("ArticleUserSet");
@@ -96,27 +96,27 @@ namespace DbContextLib.Migrations
new
{
ArticleEntityId = 1L,
- UserEntityId = 1L
+ UserEntityPseudo = "TonyF"
},
new
{
ArticleEntityId = 2L,
- UserEntityId = 2L
+ UserEntityPseudo = "NoaSil"
},
new
{
ArticleEntityId = 3L,
- UserEntityId = 3L
+ UserEntityPseudo = "Sha"
},
new
{
ArticleEntityId = 3L,
- UserEntityId = 1L
+ UserEntityPseudo = "RedM"
},
new
{
ArticleEntityId = 2L,
- UserEntityId = 3L
+ UserEntityPseudo = "TomS"
});
});
@@ -134,20 +134,17 @@ namespace DbContextLib.Migrations
.IsRequired()
.HasColumnType("TEXT");
- b.Property("Pseudo")
+ b.Property("Theme")
.IsRequired()
.HasColumnType("TEXT");
- b.Property("Theme")
+ b.Property("UserEntityPseudo")
.IsRequired()
.HasColumnType("TEXT");
- b.Property("UserEntityId")
- .HasColumnType("INTEGER");
-
b.HasKey("Id");
- b.HasIndex("UserEntityId");
+ b.HasIndex("UserEntityPseudo");
b.ToTable("FormSet");
@@ -157,35 +154,31 @@ namespace DbContextLib.Migrations
Id = 1L,
DatePublication = "Form 1 Description",
Link = "hhtp://form1.com",
- Pseudo = "Form 1",
Theme = "",
- UserEntityId = 1L
+ UserEntityPseudo = "Sha"
},
new
{
Id = 2L,
DatePublication = "Form 2 Description",
Link = "hhtp://form2.com",
- Pseudo = "Form 2",
Theme = "",
- UserEntityId = 2L
+ UserEntityPseudo = "Sha"
},
new
{
Id = 3L,
DatePublication = "Form 3 Description",
Link = "hhtp://form3.com",
- Pseudo = "Form 3",
Theme = "",
- UserEntityId = 3L
+ UserEntityPseudo = "Sha"
});
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
+ b.Property("Pseudo")
+ .HasColumnType("TEXT");
b.Property("Mail")
.IsRequired()
@@ -203,67 +196,58 @@ namespace DbContextLib.Migrations
.IsRequired()
.HasColumnType("TEXT");
- b.Property("Pseudo")
- .IsRequired()
- .HasColumnType("TEXT");
-
b.Property("Role")
.IsRequired()
.HasColumnType("TEXT");
- b.HasKey("Id");
+ b.HasKey("Pseudo");
b.ToTable("UserSet");
b.HasData(
new
{
- Id = 1L,
+ Pseudo = "TonyF",
Mail = "tony@gmail.com",
Mdp = "1234",
Nom = "Fages",
Prenom = "Tony",
- Pseudo = "TonyF",
Role = "Admin"
},
new
{
- Id = 2L,
+ Pseudo = "TomS",
Mail = "tom@mail.com",
Mdp = "1234",
Nom = "Smith",
Prenom = "Tom",
- Pseudo = "TomS",
Role = "User"
},
new
{
- Id = 3L,
+ Pseudo = "RedM",
Mail = "M&M#mail.com",
Mdp = "1234",
Nom = "M&M's",
Prenom = "Red",
- Pseudo = "RedM",
Role = "Modérator"
},
new
{
- Id = 4L,
+ Pseudo = "Sha",
Mail = "ShaCasca@gmail.com",
Mdp = "1234",
Nom = "Cascarra",
Prenom = "Cascarra",
- Pseudo = "Sha",
Role = "Admin"
},
new
{
- Id = 5L,
+ Pseudo = "NoaSil",
Mail = "",
Mdp = "1234",
Nom = "Sillard",
Prenom = "Noa",
- Pseudo = "NoaSil",
Role = "Admin"
});
});
@@ -278,7 +262,7 @@ namespace DbContextLib.Migrations
b.HasOne("Entities.UserEntity", null)
.WithMany()
- .HasForeignKey("UserEntityId")
+ .HasForeignKey("UserEntityPseudo")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
@@ -287,7 +271,7 @@ namespace DbContextLib.Migrations
{
b.HasOne("Entities.UserEntity", "User")
.WithMany("Forms")
- .HasForeignKey("UserEntityId")
+ .HasForeignKey("UserEntityPseudo")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240312155559_mrg1.cs
similarity index 75%
rename from Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.cs
rename to Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240312155559_mrg1.cs
index b9278d6..df6fd44 100644
--- a/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240311132206_mrg1.cs
+++ b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/20240312155559_mrg1.cs
@@ -33,8 +33,6 @@ namespace DbContextLib.Migrations
name: "UserSet",
columns: table => new
{
- Id = table.Column(type: "INTEGER", nullable: false)
- .Annotation("Sqlite:Autoincrement", true),
Pseudo = table.Column(type: "TEXT", nullable: false),
Mdp = table.Column(type: "TEXT", nullable: false),
Nom = table.Column(type: "TEXT", nullable: false),
@@ -44,19 +42,19 @@ namespace DbContextLib.Migrations
},
constraints: table =>
{
- table.PrimaryKey("PK_UserSet", x => x.Id);
+ table.PrimaryKey("PK_UserSet", x => x.Pseudo);
});
migrationBuilder.CreateTable(
name: "ArticleUserSet",
columns: table => new
{
- UserEntityId = table.Column(type: "INTEGER", nullable: false),
+ UserEntityPseudo = table.Column(type: "TEXT", nullable: false),
ArticleEntityId = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
- table.PrimaryKey("PK_ArticleUserSet", x => new { x.ArticleEntityId, x.UserEntityId });
+ table.PrimaryKey("PK_ArticleUserSet", x => new { x.ArticleEntityId, x.UserEntityPseudo });
table.ForeignKey(
name: "FK_ArticleUserSet_ArticleSet_ArticleEntityId",
column: x => x.ArticleEntityId,
@@ -64,10 +62,10 @@ namespace DbContextLib.Migrations
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
- name: "FK_ArticleUserSet_UserSet_UserEntityId",
- column: x => x.UserEntityId,
+ name: "FK_ArticleUserSet_UserSet_UserEntityPseudo",
+ column: x => x.UserEntityPseudo,
principalTable: "UserSet",
- principalColumn: "Id",
+ principalColumn: "Pseudo",
onDelete: ReferentialAction.Cascade);
});
@@ -80,17 +78,16 @@ namespace DbContextLib.Migrations
Theme = table.Column(type: "TEXT", nullable: false),
DatePublication = table.Column(type: "TEXT", nullable: false),
Link = table.Column(type: "TEXT", nullable: false),
- Pseudo = table.Column(type: "TEXT", nullable: false),
- UserEntityId = table.Column(type: "INTEGER", nullable: false)
+ UserEntityPseudo = table.Column(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FormSet", x => x.Id);
table.ForeignKey(
- name: "FK_FormSet_UserSet_UserEntityId",
- column: x => x.UserEntityId,
+ name: "FK_FormSet_UserSet_UserEntityPseudo",
+ column: x => x.UserEntityPseudo,
principalTable: "UserSet",
- principalColumn: "Id",
+ principalColumn: "Pseudo",
onDelete: ReferentialAction.Cascade);
});
@@ -106,47 +103,47 @@ namespace DbContextLib.Migrations
migrationBuilder.InsertData(
table: "UserSet",
- columns: new[] { "Id", "Mail", "Mdp", "Nom", "Prenom", "Pseudo", "Role" },
+ columns: new[] { "Pseudo", "Mail", "Mdp", "Nom", "Prenom", "Role" },
values: new object[,]
{
- { 1L, "tony@gmail.com", "1234", "Fages", "Tony", "TonyF", "Admin" },
- { 2L, "tom@mail.com", "1234", "Smith", "Tom", "TomS", "User" },
- { 3L, "M&M#mail.com", "1234", "M&M's", "Red", "RedM", "Modérator" },
- { 4L, "ShaCasca@gmail.com", "1234", "Cascarra", "Cascarra", "Sha", "Admin" },
- { 5L, "", "1234", "Sillard", "Noa", "NoaSil", "Admin" }
+ { "NoaSil", "", "1234", "Sillard", "Noa", "Admin" },
+ { "RedM", "M&M#mail.com", "1234", "M&M's", "Red", "Modérator" },
+ { "Sha", "ShaCasca@gmail.com", "1234", "Cascarra", "Cascarra", "Admin" },
+ { "TomS", "tom@mail.com", "1234", "Smith", "Tom", "User" },
+ { "TonyF", "tony@gmail.com", "1234", "Fages", "Tony", "Admin" }
});
migrationBuilder.InsertData(
table: "ArticleUserSet",
- columns: new[] { "ArticleEntityId", "UserEntityId" },
+ columns: new[] { "ArticleEntityId", "UserEntityPseudo" },
values: new object[,]
{
- { 1L, 1L },
- { 2L, 2L },
- { 2L, 3L },
- { 3L, 1L },
- { 3L, 3L }
+ { 1L, "TonyF" },
+ { 2L, "NoaSil" },
+ { 2L, "TomS" },
+ { 3L, "RedM" },
+ { 3L, "Sha" }
});
migrationBuilder.InsertData(
table: "FormSet",
- columns: new[] { "Id", "DatePublication", "Link", "Pseudo", "Theme", "UserEntityId" },
+ columns: new[] { "Id", "DatePublication", "Link", "Theme", "UserEntityPseudo" },
values: new object[,]
{
- { 1L, "Form 1 Description", "hhtp://form1.com", "Form 1", "", 1L },
- { 2L, "Form 2 Description", "hhtp://form2.com", "Form 2", "", 2L },
- { 3L, "Form 3 Description", "hhtp://form3.com", "Form 3", "", 3L }
+ { 1L, "Form 1 Description", "hhtp://form1.com", "", "Sha" },
+ { 2L, "Form 2 Description", "hhtp://form2.com", "", "Sha" },
+ { 3L, "Form 3 Description", "hhtp://form3.com", "", "Sha" }
});
migrationBuilder.CreateIndex(
- name: "IX_ArticleUserSet_UserEntityId",
+ name: "IX_ArticleUserSet_UserEntityPseudo",
table: "ArticleUserSet",
- column: "UserEntityId");
+ column: "UserEntityPseudo");
migrationBuilder.CreateIndex(
- name: "IX_FormSet_UserEntityId",
+ name: "IX_FormSet_UserEntityPseudo",
table: "FormSet",
- column: "UserEntityId");
+ column: "UserEntityPseudo");
}
///
diff --git a/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs
index 4e992dc..8cff281 100644
--- a/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs
+++ b/Verax_API_EF/Verax_API_EF/DbContextLib/Migrations/LibraryContextModelSnapshot.cs
@@ -80,12 +80,12 @@ namespace DbContextLib.Migrations
b.Property("ArticleEntityId")
.HasColumnType("INTEGER");
- b.Property("UserEntityId")
- .HasColumnType("INTEGER");
+ b.Property("UserEntityPseudo")
+ .HasColumnType("TEXT");
- b.HasKey("ArticleEntityId", "UserEntityId");
+ b.HasKey("ArticleEntityId", "UserEntityPseudo");
- b.HasIndex("UserEntityId");
+ b.HasIndex("UserEntityPseudo");
b.ToTable("ArticleUserSet");
@@ -93,27 +93,27 @@ namespace DbContextLib.Migrations
new
{
ArticleEntityId = 1L,
- UserEntityId = 1L
+ UserEntityPseudo = "TonyF"
},
new
{
ArticleEntityId = 2L,
- UserEntityId = 2L
+ UserEntityPseudo = "NoaSil"
},
new
{
ArticleEntityId = 3L,
- UserEntityId = 3L
+ UserEntityPseudo = "Sha"
},
new
{
ArticleEntityId = 3L,
- UserEntityId = 1L
+ UserEntityPseudo = "RedM"
},
new
{
ArticleEntityId = 2L,
- UserEntityId = 3L
+ UserEntityPseudo = "TomS"
});
});
@@ -131,20 +131,17 @@ namespace DbContextLib.Migrations
.IsRequired()
.HasColumnType("TEXT");
- b.Property("Pseudo")
+ b.Property("Theme")
.IsRequired()
.HasColumnType("TEXT");
- b.Property("Theme")
+ b.Property("UserEntityPseudo")
.IsRequired()
.HasColumnType("TEXT");
- b.Property("UserEntityId")
- .HasColumnType("INTEGER");
-
b.HasKey("Id");
- b.HasIndex("UserEntityId");
+ b.HasIndex("UserEntityPseudo");
b.ToTable("FormSet");
@@ -154,35 +151,31 @@ namespace DbContextLib.Migrations
Id = 1L,
DatePublication = "Form 1 Description",
Link = "hhtp://form1.com",
- Pseudo = "Form 1",
Theme = "",
- UserEntityId = 1L
+ UserEntityPseudo = "Sha"
},
new
{
Id = 2L,
DatePublication = "Form 2 Description",
Link = "hhtp://form2.com",
- Pseudo = "Form 2",
Theme = "",
- UserEntityId = 2L
+ UserEntityPseudo = "Sha"
},
new
{
Id = 3L,
DatePublication = "Form 3 Description",
Link = "hhtp://form3.com",
- Pseudo = "Form 3",
Theme = "",
- UserEntityId = 3L
+ UserEntityPseudo = "Sha"
});
});
modelBuilder.Entity("Entities.UserEntity", b =>
{
- b.Property("Id")
- .ValueGeneratedOnAdd()
- .HasColumnType("INTEGER");
+ b.Property("Pseudo")
+ .HasColumnType("TEXT");
b.Property("Mail")
.IsRequired()
@@ -200,67 +193,58 @@ namespace DbContextLib.Migrations
.IsRequired()
.HasColumnType("TEXT");
- b.Property("Pseudo")
- .IsRequired()
- .HasColumnType("TEXT");
-
b.Property("Role")
.IsRequired()
.HasColumnType("TEXT");
- b.HasKey("Id");
+ b.HasKey("Pseudo");
b.ToTable("UserSet");
b.HasData(
new
{
- Id = 1L,
+ Pseudo = "TonyF",
Mail = "tony@gmail.com",
Mdp = "1234",
Nom = "Fages",
Prenom = "Tony",
- Pseudo = "TonyF",
Role = "Admin"
},
new
{
- Id = 2L,
+ Pseudo = "TomS",
Mail = "tom@mail.com",
Mdp = "1234",
Nom = "Smith",
Prenom = "Tom",
- Pseudo = "TomS",
Role = "User"
},
new
{
- Id = 3L,
+ Pseudo = "RedM",
Mail = "M&M#mail.com",
Mdp = "1234",
Nom = "M&M's",
Prenom = "Red",
- Pseudo = "RedM",
Role = "Modérator"
},
new
{
- Id = 4L,
+ Pseudo = "Sha",
Mail = "ShaCasca@gmail.com",
Mdp = "1234",
Nom = "Cascarra",
Prenom = "Cascarra",
- Pseudo = "Sha",
Role = "Admin"
},
new
{
- Id = 5L,
+ Pseudo = "NoaSil",
Mail = "",
Mdp = "1234",
Nom = "Sillard",
Prenom = "Noa",
- Pseudo = "NoaSil",
Role = "Admin"
});
});
@@ -275,7 +259,7 @@ namespace DbContextLib.Migrations
b.HasOne("Entities.UserEntity", null)
.WithMany()
- .HasForeignKey("UserEntityId")
+ .HasForeignKey("UserEntityPseudo")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
@@ -284,7 +268,7 @@ namespace DbContextLib.Migrations
{
b.HasOne("Entities.UserEntity", "User")
.WithMany("Forms")
- .HasForeignKey("UserEntityId")
+ .HasForeignKey("UserEntityPseudo")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db
index 730f5f3..175a9e3 100644
Binary files a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db and b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Entity_FrameWork.Article.db differ
diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs b/Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_EF.cs
similarity index 100%
rename from Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_Article.cs
rename to Verax_API_EF/Verax_API_EF/Test_Console_EF/Test_Console_EF.cs
diff --git a/Verax_API_EF/Verax_API_EF/Test_Console_EF/log.txt b/Verax_API_EF/Verax_API_EF/Test_Console_EF/log.txt
new file mode 100644
index 0000000..e69de29
diff --git a/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleEntity.cs
similarity index 80%
rename from Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs
rename to Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleEntity.cs
index fce41a3..7fd74b0 100644
--- a/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsArticleEntity.cs
+++ b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsArticleEntity.cs
@@ -2,11 +2,10 @@ using DbContextLib;
using Entities;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
-using Xunit;
-namespace Tests;
+namespace TestsUnitaires;
-public class ArticleDB_Tests
+public class TestsArticleEntity
{
[Fact]
public void Add_Test()
@@ -21,13 +20,13 @@ public class ArticleDB_Tests
using (var context = new LibraryContext(options))
{
context.Database.EnsureCreated();
- ArticleEntity a1 = new ArticleEntity { Id = 1, Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" };
- ArticleEntity a2 = new ArticleEntity { Id = 2, Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" };
- ArticleEntity a3 = new ArticleEntity { Id = 3, Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" };
+ ArticleEntity a1 = new ArticleEntity { Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" };
+ ArticleEntity a2 = new ArticleEntity { Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" };
+ ArticleEntity a3 = new ArticleEntity { Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" };
- context.Add(a1);
- context.Add(a2);
- context.Add(a3);
+ context.ArticleSet.Add(a1);
+ context.ArticleSet.Add(a2);
+ context.ArticleSet.Add(a3);
context.SaveChanges();
@@ -52,9 +51,9 @@ public class ArticleDB_Tests
ArticleEntity a1 = new ArticleEntity { Id = 1, Title = "Breaking News Elisabeth 2 Died", Description = "The queen of England died today at the age of 95", DatePublished = "2022-02-06", LectureTime = 2, Author = "Tom Smith" };
ArticleEntity a2 = new ArticleEntity { Id = 2, Title = "The new iPhone 15", Description = "The new iPhone 15 is out and it's the best phone ever", DatePublished = "2022-02-06", LectureTime = 3, Author = "Tom Smith" };
ArticleEntity a3 = new ArticleEntity { Id = 3, Title = "M&M's new recipe", Description = "M&M's new recipe is out and it's the best chocolate ever", DatePublished = "2022-02-06", LectureTime = 1, Author = "M&M's Red" };
- context.Add(a1);
- context.Add(a2);
- context.Add(a3);
+ context.ArticleSet.Add(a1);
+ context.ArticleSet.Add(a2);
+ context.ArticleSet.Add(a3);
context.SaveChanges();
diff --git a/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsUserEntity.cs b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsUserEntity.cs
new file mode 100644
index 0000000..4119245
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/TestsUserEntity.cs
@@ -0,0 +1,182 @@
+using DbContextLib;
+using Entities;
+using Microsoft.Data.Sqlite;
+using Microsoft.EntityFrameworkCore;
+
+namespace Tests;
+
+public class TestsUserEntity
+{
+ [Fact]
+ public void Add_Test()
+ {
+ var connection = new SqliteConnection("DataSource=:memory:");
+ connection.Open();
+
+ var options = new DbContextOptionsBuilder()
+ .UseSqlite(connection)
+ .Options;
+
+ using (var context = new LibraryContext(options))
+ {
+ context.Database.EnsureCreated();
+ UserEntity u1 = new UserEntity
+ {
+ Pseudo = "Tofgasy", Prenom = "Tony", Nom = "Fages", Mail = "he@gmail.com", Mdp = "1234", Role = "Admin"
+ };
+ UserEntity u2 = new UserEntity
+ {
+ Pseudo = "Blizzard", Prenom = "Louis", Nom = "Laborie", Mail = "he@gmail.com", Mdp = "1234",
+ Role = "Admin"
+ };
+ UserEntity u3 = new UserEntity
+ {
+ Pseudo = "TomS", Prenom = "Tom", Nom = "Smith", Mail = "TomS@gmail.com", Mdp = "1234", Role = "User"
+ };
+ UserEntity u4 = new UserEntity
+ {
+ Pseudo = "Siwa", Prenom = "Jean", Nom = "Marcillac", Mail = "occitan@gmail.com", Mdp = "1234",
+ Role = "Amin"
+ };
+ UserEntity u5 = new UserEntity
+ {
+ Pseudo = "Sha", Prenom = "Shana", Nom = "Cascarra", Mail = "shacas@gmail.com", Mdp = "1234",
+ Role = "Modérator"
+ };
+ UserEntity u6 = new UserEntity
+ {
+ Pseudo = "NoaSil", Prenom = "Noa", Nom = "Sillard", Mail = "noaSillar@gmail.com", Mdp = "1234",
+ Role = "Admin"
+ };
+ context.UserSet.Add(u1);
+ context.UserSet.Add(u2);
+ context.UserSet.Add(u3);
+ context.UserSet.Add(u4);
+ context.UserSet.Add(u5);
+ context.UserSet.Add(u6);
+ context.SaveChanges();
+
+ Assert.Equal(6, context.UserSet.Count());
+ Assert.Equal("Blizzard", context.UserSet.First().Pseudo);
+ connection.Close();
+ }
+ }
+
+ [Fact]
+ public void Modify_Test()
+ {
+ var connection = new SqliteConnection("DataSource=:memory:");
+ connection.Open();
+
+ var options = new DbContextOptionsBuilder()
+ .UseSqlite(connection)
+ .Options;
+ using (var context = new LibraryContext(options))
+ {
+ context.Database.EnsureCreated();
+ UserEntity u1 = new UserEntity
+ {
+ Pseudo = "Tofgasy", Prenom = "Tony", Nom = "Fages", Mail = "he@gmail.com", Mdp = "1234", Role = "Admin"
+ };
+ UserEntity u2 = new UserEntity
+ {
+ Pseudo = "Blizzard", Prenom = "Louis", Nom = "Laborie", Mail = "he@gmail.com", Mdp = "1234",
+ Role = "Admin"
+ };
+ UserEntity u3 = new UserEntity
+ {
+ Pseudo = "TomS", Prenom = "Tom", Nom = "Smith", Mail = "TomS@gmail.com", Mdp = "1234", Role = "User"
+ };
+ UserEntity u4 = new UserEntity
+ {
+ Pseudo = "Siwa", Prenom = "Jean", Nom = "Marcillac", Mail = "occitan@gmail.com", Mdp = "1234",
+ Role = "Amin"
+ };
+ UserEntity u5 = new UserEntity
+ {
+ Pseudo = "Sha", Prenom = "Shana", Nom = "Cascarra", Mail = "shacas@gmail.com", Mdp = "1234",
+ Role = "Modérator"
+ };
+ UserEntity u6 = new UserEntity
+ {
+ Pseudo = "NoaSil", Prenom = "Noa", Nom = "Sillard", Mail = "noaSillar@gmail.com", Mdp = "1234",
+ Role = "Admin"
+ };
+ context.UserSet.Add(u1);
+ context.UserSet.Add(u2);
+ context.UserSet.Add(u3);
+ context.UserSet.Add(u4);
+ context.UserSet.Add(u5);
+ context.UserSet.Add(u6);
+ context.SaveChanges();
+
+ var user = context.UserSet.First(u => u.Pseudo.Equals("Tofgasy"));
+ user.Prenom = "Tof";
+ context.SaveChanges();
+ string persRemove = "Tony";
+ string persNew = "Tof";
+ Assert.Equal(1, context.UserSet.Count(u => u.Prenom.Equals(persNew)));
+ Assert.Equal(0, context.UserSet.Count(u => u.Prenom.Equals(persRemove)));
+ connection.Close();
+
+ }
+ }
+
+ [Fact]
+ public void Remove_Test()
+ {
+ var connection = new SqliteConnection("DataSource=:memory:");
+ connection.Open();
+
+ var options = new DbContextOptionsBuilder()
+ .UseSqlite(connection)
+ .Options;
+ using (var context = new LibraryContext(options))
+ {
+ context.Database.EnsureCreated();
+ UserEntity u1 = new UserEntity
+ {
+ Pseudo = "Tofgasy", Prenom = "Tony", Nom = "Fages", Mail = "he@gmail.com", Mdp = "1234", Role = "Admin"
+ };
+ UserEntity u2 = new UserEntity
+ {
+ Pseudo = "Blizzard", Prenom = "Louis", Nom = "Laborie", Mail = "he@gmail.com", Mdp = "1234",
+ Role = "Admin"
+ };
+ UserEntity u3 = new UserEntity
+ {
+ Pseudo = "TomS", Prenom = "Tom", Nom = "Smith", Mail = "TomS@gmail.com", Mdp = "1234", Role = "User"
+ };
+ UserEntity u4 = new UserEntity
+ {
+ Pseudo = "Siwa", Prenom = "Jean", Nom = "Marcillac", Mail = "occitan@gmail.com", Mdp = "1234",
+ Role = "Amin"
+ };
+ UserEntity u5 = new UserEntity
+ {
+ Pseudo = "Sha", Prenom = "Shana", Nom = "Cascarra", Mail = "shacas@gmail.com", Mdp = "1234",
+ Role = "Modérator"
+ };
+ UserEntity u6 = new UserEntity
+ {
+ Pseudo = "NoaSil", Prenom = "Noa", Nom = "Sillard", Mail = "noaSillar@gmail.com", Mdp = "1234",
+ Role = "Admin"
+ };
+ context.UserSet.Add(u1);
+ context.UserSet.Add(u2);
+ context.UserSet.Add(u3);
+ context.UserSet.Add(u4);
+ context.UserSet.Add(u5);
+ context.UserSet.Add(u6);
+ context.SaveChanges();
+
+ Assert.Equal(6, context.UserSet.Count());
+ var user = context.UserSet.First(u => u.Pseudo.Equals("Tofgasy"));
+ context.Remove(user);
+ context.SaveChanges();
+ Assert.Equal(5, context.UserSet.Count());
+ Assert.Equal(0, context.UserSet.Count(u => u.Pseudo.Equals("Tofgasy")));
+ connection.Close();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/Unit_Test_EF.csproj
similarity index 96%
rename from Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj
rename to Verax_API_EF/Verax_API_EF/Unit_Test_EF/Unit_Test_EF.csproj
index d068dfd..fc4de9b 100644
--- a/Verax_API_EF/Verax_API_EF/TestsUnitaires/TestsUnitaires.csproj
+++ b/Verax_API_EF/Verax_API_EF/Unit_Test_EF/Unit_Test_EF.csproj
@@ -7,6 +7,7 @@
false
true
+ TestsUnitaires
diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln b/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln
index 6fdbffa..473c412 100644
--- a/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln
+++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF.sln
@@ -23,7 +23,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{6AACD337-70A0-429B-979C-1B1E004BF2E0}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsUnitaires", "TestsUnitaires\TestsUnitaires.csproj", "{C1982C7C-AE09-4E96-B1A9-B6ADE4097452}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unit_Test_EF", "Unit_Test_EF\Unit_Test_EF.csproj", "{C1982C7C-AE09-4E96-B1A9-B6ADE4097452}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Unit_Test", "API_Unit_Test\API_Unit_Test.csproj", "{B3B9C0F5-98A3-438B-A22A-ECFF33DA8F23}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API_Tests_Console", "API_Tests_Console\API_Tests_Console.csproj", "{EEB45245-5B65-4C99-A2B4-942991AE5F1A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -75,6 +79,14 @@ Global
{C1982C7C-AE09-4E96-B1A9-B6ADE4097452}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C1982C7C-AE09-4E96-B1A9-B6ADE4097452}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C1982C7C-AE09-4E96-B1A9-B6ADE4097452}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B3B9C0F5-98A3-438B-A22A-ECFF33DA8F23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B3B9C0F5-98A3-438B-A22A-ECFF33DA8F23}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B3B9C0F5-98A3-438B-A22A-ECFF33DA8F23}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B3B9C0F5-98A3-438B-A22A-ECFF33DA8F23}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EEB45245-5B65-4C99-A2B4-942991AE5F1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EEB45245-5B65-4C99-A2B4-942991AE5F1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EEB45245-5B65-4C99-A2B4-942991AE5F1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EEB45245-5B65-4C99-A2B4-942991AE5F1A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/.gitignore b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/.gitignore
new file mode 100644
index 0000000..477ae27
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/.gitignore
@@ -0,0 +1,15 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Rider ignored files
+/modules.xml
+/projectSettingsUpdater.xml
+/.idea.Verax_API_EF.iml
+/contentModel.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# GitHub Copilot persisted chat sessions
+/copilot/chatSessions
diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/indexLayout.xml b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/vcs.xml b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/vcs.xml
new file mode 100644
index 0000000..b2bdec2
--- /dev/null
+++ b/Verax_API_EF/Verax_API_EF/Verax_API_EF/.idea/.idea.Verax_API_EF.dir/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file