You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
188 lines
3.6 KiB
188 lines
3.6 KiB
using EPAServeur.Context;
|
|
using EPAServeur.Exceptions;
|
|
using EPAServeur.Models.Formation;
|
|
using EPAServeur.Services;
|
|
using IO.Swagger.Controllers;
|
|
using IO.Swagger.DTO;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using NUnit.Framework;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace EPAServeur.Tests.Controllers
|
|
{
|
|
[TestFixture]
|
|
public class FormationApiTests
|
|
{
|
|
#region Variables
|
|
|
|
private FormationService formationService;
|
|
private readonly ILogger<FormationsApiController> logger;
|
|
|
|
#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;
|
|
|
|
EpContext epContext = new EpContext(optionBuider);
|
|
|
|
epContext.Database.EnsureDeleted();
|
|
epContext.Database.EnsureCreated();
|
|
epContext.SaveChanges();
|
|
|
|
// Ajout du jeu de données pour les tests
|
|
DataSeeder.AddFormations(epContext);
|
|
|
|
// 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 epContext.ChangeTracker.Entries())
|
|
{
|
|
entity.State = EntityState.Detached;
|
|
}
|
|
|
|
// Instanciation du service qui sera utilisé dans le controleur
|
|
formationService = new FormationService(epContext);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Tests GetFormationById
|
|
|
|
[Test]
|
|
public void GetFormationById_PasseEnParamUnIdPresentDansLaBDD_RetourneUnObjetOkResult()
|
|
{
|
|
//// Arrange
|
|
//FormationsApiController formationsApiController = new FormationsApiController(formationService, new NullLogger<FormationsApiController>());
|
|
|
|
// // Act
|
|
// var okResult = formationsApiController.GetFormationById(1);
|
|
|
|
//// Assert
|
|
//Assert.IsInstanceOf<OkObjectResult>(okResult.Result);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Tests GetFormations
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests GetFormationAnnulees
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests GetFormationRealisee
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests GetProchainesFormation
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests GetModesFormation
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests GetOriginesFormation
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests GetStatutsFormation
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests GetTypesFormation
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests AddFormation
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests UpdateFormation
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
|
|
#region Tests DeleteFormationById
|
|
|
|
// Arrange
|
|
|
|
// Act
|
|
|
|
// Assert
|
|
|
|
#endregion
|
|
}
|
|
} |