parent
1f43723b07
commit
a07e54c6bc
@ -1,18 +1,145 @@ |
||||
using EPAServeur.Context; |
||||
using EPAServeur.Exceptions; |
||||
using EPAServeur.Models.Formation; |
||||
using EPAServeur.Services; |
||||
using IO.Swagger.DTO; |
||||
using Microsoft.EntityFrameworkCore; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace EPAServeur.Tests |
||||
{ |
||||
public class FormationServiceTests |
||||
{ |
||||
private EpContext epContext; |
||||
|
||||
[SetUp] |
||||
public void Setup() |
||||
{ |
||||
var optionBuider = new DbContextOptionsBuilder<EpContext>() |
||||
.UseInMemoryDatabase("server_ep_test") |
||||
.Options; |
||||
|
||||
epContext = new EpContext(optionBuider); |
||||
|
||||
epContext.Database.EnsureDeleted(); |
||||
epContext.Database.EnsureCreated(); |
||||
epContext.SaveChanges(); |
||||
|
||||
DataSeeder.AddFormations(epContext); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetFormationById_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictifs_RetourneUneFormation() |
||||
{ |
||||
// Arrange |
||||
FormationService formationService = new FormationService(epContext); |
||||
|
||||
// Act |
||||
FormationDTO formationDTO = formationService.GetFormationById(1); |
||||
|
||||
// Assert |
||||
Assert.AreEqual(1, formationDTO.Id); |
||||
Assert.AreEqual("Formation1", formationDTO.Intitule); |
||||
Assert.AreEqual(1, formationDTO.IdAgence); |
||||
Assert.AreEqual(new DateTime(2020, 9, 16, 10, 0, 0), formationDTO.DateDebut); |
||||
Assert.AreEqual(new DateTime(2020, 9, 16), formationDTO.DateFin); |
||||
Assert.AreEqual(2, formationDTO.Heure); |
||||
Assert.AreEqual(1, formationDTO.Jour); |
||||
Assert.AreEqual("Organisme1", formationDTO.Organisme); |
||||
Assert.False(formationDTO.EstCertifie); |
||||
Assert.AreEqual(new OrigineFormationDTO { Id = 2, Libelle = "Exigence client" }, formationDTO.Origine); |
||||
Assert.AreEqual(new StatutFormationDTO { Id = 1, Libelle = "Planifiée" }, formationDTO.Statut); |
||||
Assert.AreEqual(new ModeFormationDTO { Id = 4, Libelle = "E-learning" }, formationDTO.Mode); |
||||
Assert.AreEqual(new TypeFormationDTO { Id = 3, Libelle = "E-learning" }, formationDTO.Type); |
||||
} |
||||
|
||||
[TestCase(-1)] |
||||
[TestCase(0)] |
||||
[TestCase(999999)] |
||||
[TestCase(null)] |
||||
public void GetFormationById_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictifs_LeveUneFormationNotFoundException(long? value) |
||||
{ |
||||
// Arrange |
||||
FormationService formationService = new FormationService(epContext); |
||||
|
||||
// Act |
||||
TestDelegate throwException = () => formationService.GetFormationById(value); |
||||
|
||||
// Assert |
||||
Assert.Throws(typeof(FormationNotFoundException), throwException); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetFormationById_PasseEnParamUnIdExistantDansLeJeuDeDonnees_RetourneUneFormation() |
||||
public async Task GetFormationByIdAsync_PasseEnParamUnIdExistantDansLeJeuDeDonneesFictifs_RetourneUneFormation() |
||||
{ |
||||
Assert.Pass(); |
||||
// Arrange |
||||
FormationService formationService = new FormationService(epContext); |
||||
|
||||
// Act |
||||
FormationDTO formationDTO = await formationService.GetFormationByIdAsync(1); |
||||
|
||||
// Assert |
||||
Assert.AreEqual(1, formationDTO.Id); |
||||
Assert.AreEqual("Formation1", formationDTO.Intitule); |
||||
Assert.AreEqual(1, formationDTO.IdAgence); |
||||
Assert.AreEqual(new DateTime(2020, 9, 16, 10, 0, 0), formationDTO.DateDebut); |
||||
Assert.AreEqual(new DateTime(2020, 9, 16), formationDTO.DateFin); |
||||
Assert.AreEqual(2, formationDTO.Heure); |
||||
Assert.AreEqual(1, formationDTO.Jour); |
||||
Assert.AreEqual("Organisme1", formationDTO.Organisme); |
||||
Assert.False(formationDTO.EstCertifie); |
||||
Assert.AreEqual(new OrigineFormationDTO { Id = 2, Libelle = "Exigence client" }, formationDTO.Origine); |
||||
Assert.AreEqual(new StatutFormationDTO { Id = 1, Libelle = "Planifiée" }, formationDTO.Statut); |
||||
Assert.AreEqual(new ModeFormationDTO { Id = 4, Libelle = "E-learning" }, formationDTO.Mode); |
||||
Assert.AreEqual(new TypeFormationDTO { Id = 3, Libelle = "E-learning" }, formationDTO.Type); |
||||
} |
||||
|
||||
[TestCase(-1)] |
||||
[TestCase(0)] |
||||
[TestCase(999999)] |
||||
[TestCase(null)] |
||||
public void GetFormationByIdAsync_PasseEnParamUnIdInexistantDansLeJeuDeDonneesFictifs_LeveUneFormationNotFoundException(long? value) |
||||
{ |
||||
// Arrange |
||||
FormationService formationService = new FormationService(epContext); |
||||
|
||||
// Act |
||||
AsyncTestDelegate throwException = () => formationService.GetFormationByIdAsync(value); |
||||
|
||||
// Assert |
||||
Assert.ThrowsAsync(typeof(FormationNotFoundException), throwException); |
||||
} |
||||
|
||||
//[TestCase(true, 1, 2, 1, 1, "f", null)] |
||||
//[TestCase(null, null, null, null, null, null, null)] |
||||
//public void GetFormations_PasseDesParamsQuiVont_RetourneDesFormations(bool? asc, int? numPage, int? parPAge, int? idAgence, int? statutFormation, string texte, string tri) |
||||
//{ |
||||
// // Arrange |
||||
// FormationService formationService = new FormationService(epContext); |
||||
|
||||
// // Act |
||||
// IEnumerable<FormationDTO> formationDTOs = formationService.GetFormations(asc, numPage, parPAge, idAgence, statutFormation, texte, tri); |
||||
|
||||
// // Assert |
||||
// Assert.Less(0, formationDTOs.Count()); |
||||
//} |
||||
|
||||
//[TestCase(null,-1,-1,-1,-1,"azerty",null)] |
||||
//public void GetFormations_PasseDesParamsInvalides_RetourneZeroFormation(bool? asc, int? numPage, int? parPAge, int? idAgence, int? statutFormation, string texte, string tri) |
||||
//{ |
||||
// // Arrange |
||||
// FormationService formationService = new FormationService(epContext); |
||||
|
||||
// // Act |
||||
// IEnumerable<FormationDTO> formationDTOs = formationService.GetFormations(asc, numPage, parPAge, idAgence, statutFormation,texte,tri); |
||||
|
||||
// // Assert |
||||
// Assert.AreEqual(0, formationDTOs.Count()); |
||||
//} |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue