|
|
|
|
using EPAServeur.Context;
|
|
|
|
|
using EPAServeur.Exceptions;
|
|
|
|
|
using EPAServeur.IServices;
|
|
|
|
|
using EPAServeur.Services;
|
|
|
|
|
using IO.Swagger.ApiCollaborateur;
|
|
|
|
|
using IO.Swagger.DTO;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace EPAServeur.Tests.Services
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public class CollaborateurServiceTests
|
|
|
|
|
{
|
|
|
|
|
#region
|
|
|
|
|
private EpContext context;
|
|
|
|
|
private ICollaborateurApi collaborateurApi;
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Setup
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
// Utilisation d'une base de données en mémoire
|
|
|
|
|
var optionBuider = new DbContextOptionsBuilder<EpContext>()
|
|
|
|
|
.UseInMemoryDatabase("server_ep_test")
|
|
|
|
|
.Options;
|
|
|
|
|
|
|
|
|
|
context = new EpContext(optionBuider);
|
|
|
|
|
|
|
|
|
|
context.Database.EnsureDeleted();
|
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
|
|
// Ajout du jeu de données pour les tests
|
|
|
|
|
DataSeeder.AddNotes(context);
|
|
|
|
|
|
|
|
|
|
// Détache les entités du context car la base de données InMemory créé des conflits
|
|
|
|
|
// entre les clés primaires lors d'un Update ou d'un Insert
|
|
|
|
|
foreach (var entity in context.ChangeTracker.Entries())
|
|
|
|
|
{
|
|
|
|
|
entity.State = EntityState.Detached;
|
|
|
|
|
}
|
|
|
|
|
collaborateurApi = new CollaborateurApi();
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Tests getCollaborateur
|
|
|
|
|
|
|
|
|
|
[TestCase("842650db-a548-4472-a3af-4c5fff3c1ab8")]
|
|
|
|
|
[TestCase("301ba7f3-095e-4912-8998-a7c942dc5f23")]
|
|
|
|
|
[TestCase("4f3fcd23-a1e4-4c9e-afa2-d06ca9216491")]
|
|
|
|
|
public async Task GetCollaborateurById_Ok(Guid? id)
|
|
|
|
|
{
|
|
|
|
|
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context);
|
|
|
|
|
CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByIdAsync(id);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(collaborateurDTO);
|
|
|
|
|
Assert.AreEqual(collaborateurDTO.Id, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase("creola.nicolas@apside-groupe.com")]
|
|
|
|
|
[TestCase("lamar.rousseau@apside-groupe.com")]
|
|
|
|
|
[TestCase("coty.lemoine@apside-groupe.com")]
|
|
|
|
|
public async Task GetCollaborateurByMail_Ok(string mail)
|
|
|
|
|
{
|
|
|
|
|
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context);
|
|
|
|
|
CollaborateurDTO collaborateurDTO = await collaborateurService.GetCollaborateurByMailAsync(mail);
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(collaborateurDTO);
|
|
|
|
|
Assert.AreEqual(collaborateurDTO.MailApside, mail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase("006226f6-51b2-4a02-a302-7447f7fccc04")]
|
|
|
|
|
[TestCase("e5d36da4-df16-4d19-8a11-1ba2f6efc80c")]
|
|
|
|
|
[TestCase("92b29b9c-40a4-4aa0-9412-bc97a379e52f")]
|
|
|
|
|
public async Task GetCollaborateurById_CollaborateurNotFound(Guid? id)
|
|
|
|
|
{
|
|
|
|
|
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context);
|
|
|
|
|
|
|
|
|
|
AsyncTestDelegate exception = () => collaborateurService.GetCollaborateurByIdAsync(id);
|
|
|
|
|
Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase("nicolas@apside.fr")]
|
|
|
|
|
[TestCase("rousseau@apside.fr")]
|
|
|
|
|
[TestCase("lemoine@apside.fr")]
|
|
|
|
|
public async Task GetCollaborateurByMail_CollaborateurNotFound(string mail)
|
|
|
|
|
{
|
|
|
|
|
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context);
|
|
|
|
|
AsyncTestDelegate exception = () => collaborateurService.GetCollaborateurByMailAsync(mail);
|
|
|
|
|
Assert.ThrowsAsync(typeof(CollaborateurNotFoundException), exception);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Tests GetCollaborateurs Roles
|
|
|
|
|
|
|
|
|
|
[TestCase("RH")] //9
|
|
|
|
|
[TestCase("Collaborateur")] //7
|
|
|
|
|
[TestCase("Assistant")] //6
|
|
|
|
|
[TestCase("Manager")]//10
|
|
|
|
|
[TestCase("RA")]//5
|
|
|
|
|
public async Task GetCollaborateurs_UnRole(string role)
|
|
|
|
|
{
|
|
|
|
|
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context);
|
|
|
|
|
|
|
|
|
|
List<string> roles = new List<string>();
|
|
|
|
|
roles.Add(role);
|
|
|
|
|
|
|
|
|
|
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(roles, null, true, 1, 50, "", "", null, null);
|
|
|
|
|
int count = await collaborateurService.GetCollaborateursCountAsync(roles, null, "", null, null);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(count, collaborateurs.Count());
|
|
|
|
|
|
|
|
|
|
switch (role)
|
|
|
|
|
{
|
|
|
|
|
case "RH":
|
|
|
|
|
Assert.AreEqual(count, 9);
|
|
|
|
|
break;
|
|
|
|
|
case "Collaborateur":
|
|
|
|
|
Assert.AreEqual(count, 7);
|
|
|
|
|
break;
|
|
|
|
|
case "Assistant":
|
|
|
|
|
Assert.AreEqual(count, 6);
|
|
|
|
|
break;
|
|
|
|
|
case "Manager":
|
|
|
|
|
Assert.AreEqual(count, 10);
|
|
|
|
|
break;
|
|
|
|
|
case "RA":
|
|
|
|
|
Assert.AreEqual(count, 5);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task GetCollaborateurs_RoleRH_RoleAssistant()
|
|
|
|
|
{
|
|
|
|
|
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context);
|
|
|
|
|
|
|
|
|
|
List<string> roles = new List<string>();
|
|
|
|
|
roles.Add("Assistant");
|
|
|
|
|
roles.Add("RH");
|
|
|
|
|
|
|
|
|
|
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(roles, null, true, 1, 50, "", "", null, null);
|
|
|
|
|
int count = await collaborateurService.GetCollaborateursCountAsync(roles, null, "", null, null);
|
|
|
|
|
Assert.AreEqual(count, 15); Assert.AreEqual(count, collaborateurs.Count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task GetCollaborateurs_RoleRA_RoleManager()
|
|
|
|
|
{
|
|
|
|
|
ICollaborateurService collaborateurService = new CollaborateurService(collaborateurApi, context);
|
|
|
|
|
|
|
|
|
|
List<string> roles = new List<string>();
|
|
|
|
|
roles.Add("Manager");
|
|
|
|
|
roles.Add("RA");
|
|
|
|
|
|
|
|
|
|
IEnumerable<CollaborateurDTO> collaborateurs = await collaborateurService.GetCollaborateursAsync(roles, null, true, 1, 50, "", "", null, null);
|
|
|
|
|
int count = await collaborateurService.GetCollaborateursCountAsync(roles, null, "", null, null);
|
|
|
|
|
Assert.AreEqual(count, collaborateurs.Count());
|
|
|
|
|
Assert.AreEqual(count, 15);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|