Merge branch 'master' of https://codefirst.iut.uca.fr/git/Verax/Verax_API_EF
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
commit
db2aa4551d
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$" vcs="" />
|
||||
</component>
|
||||
</project>
|
@ -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<ArticleUserController> _logger;
|
||||
public ArticleUserController(IArticleUserService us, ILogger<ArticleUserController> logger)
|
||||
{
|
||||
this._us = us;
|
||||
this._logger = logger;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("/articleUsers")]
|
||||
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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"
|
@ -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; }
|
||||
}
|
@ -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<IEnumerable<ArticleUserEntity?>> GetAllArticleUsers()
|
||||
{
|
||||
var entities = _context.ArticleUserSet.ToList();
|
||||
if (entities == null) return await Task.FromResult<IEnumerable<ArticleUserEntity?>>(null);
|
||||
return await Task.FromResult(entities.AsEnumerable());
|
||||
}
|
||||
|
||||
public async Task<ArticleUserEntity?> GetArticleUser(string pseudo)
|
||||
{
|
||||
var entity = _context.ArticleUserSet.FirstOrDefault(a => a.UserEntityPseudo.Equals(pseudo));
|
||||
if (entity == null) return await Task.FromResult<ArticleUserEntity?>(null);
|
||||
return await Task.FromResult(entity);
|
||||
}
|
||||
|
||||
|
||||
public async Task<ArticleUserEntity?> CreateArticleUser(ArticleUserEntity articleUser)
|
||||
{
|
||||
var result = await GetArticleUser(articleUser.UserEntityPseudo);
|
||||
if (result != null) return await Task.FromResult<ArticleUserEntity?>(null);
|
||||
var entity = new ArticleUserEntity()
|
||||
{
|
||||
ArticleEntityId = articleUser.ArticleEntityId,
|
||||
UserEntityPseudo = articleUser.UserEntityPseudo
|
||||
};
|
||||
if (entity == null) return await Task.FromResult<ArticleUserEntity?>(null);
|
||||
_context.ArticleUserSet.Add(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
return await Task.FromResult(entity);
|
||||
}
|
||||
|
||||
public async Task<bool> 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<bool> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using Entities;
|
||||
|
||||
namespace API_Services;
|
||||
|
||||
public interface IArticleUserService
|
||||
{
|
||||
Task<IEnumerable<ArticleUserEntity>> GetAllArticleUsers();
|
||||
Task<ArticleUserEntity?> GetArticleUser(string pseudo);
|
||||
|
||||
Task<ArticleUserEntity?> CreateArticleUser(ArticleUserEntity articleUser);
|
||||
|
||||
Task<bool> DeleteArticleUser(string pseudo);
|
||||
|
||||
Task<bool> UpdateArticleUser(ArticleUserEntity articleUser);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
namespace Model;
|
||||
using API_Services;
|
||||
|
||||
public interface IDataManager
|
||||
{
|
||||
|
||||
|
||||
IArticleService ArticleService { get; }
|
||||
IUserService UserService { get; }
|
||||
IFormulaireService FormulaireService { get; }
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
|
||||
<PackageReference Include="Moq" Version="4.20.70" />
|
||||
<PackageReference Include="xunit" Version="2.4.2"/>
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\API_Services\API_Services.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1 @@
|
||||
global using Xunit;
|
@ -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<IArticleService>();
|
||||
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<IArticleService>();
|
||||
var expected = new List<Article>()
|
||||
{
|
||||
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<IArticleService>();
|
||||
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<IArticleService>();
|
||||
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<IArticleService>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -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<IFormulaireService>();
|
||||
var expected = new List<Formulaire>()
|
||||
{
|
||||
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<IFormulaireService>();
|
||||
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<IFormulaireService>();
|
||||
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<IFormulaireService>();
|
||||
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<IFormulaireService>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -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<IUserService>();
|
||||
var expected = new List<User>()
|
||||
{
|
||||
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<IUserService>();
|
||||
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<IUserService>();
|
||||
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<IUserService>();
|
||||
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<IUserService>();
|
||||
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<IUserService>();
|
||||
var expected = new List<User>()
|
||||
{
|
||||
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<IUserService>();
|
||||
var expected = new List<Article>()
|
||||
{
|
||||
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<IUserService>();
|
||||
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<IUserService>();
|
||||
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<IUserService>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
Binary file not shown.
@ -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<LibraryContext>()
|
||||
.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<LibraryContext>()
|
||||
.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<LibraryContext>()
|
||||
.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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
Loading…
Reference in new issue