|
|
@ -0,0 +1,101 @@ |
|
|
|
|
|
|
|
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.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 Test 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |