From efbfd193d745e3afd95aca25a8d431b60d28012f Mon Sep 17 00:00:00 2001 From: jboinembalome Date: Mon, 9 Nov 2020 14:49:42 +0100 Subject: [PATCH] Creation de la classe FormationApiTests --- .../Controllers/FormationApiTests.cs | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 EPAServeur.Tests/Controllers/FormationApiTests.cs diff --git a/EPAServeur.Tests/Controllers/FormationApiTests.cs b/EPAServeur.Tests/Controllers/FormationApiTests.cs new file mode 100644 index 0000000..9347923 --- /dev/null +++ b/EPAServeur.Tests/Controllers/FormationApiTests.cs @@ -0,0 +1,188 @@ +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 logger; + + #endregion + + #region Setup + + [SetUp] + public void Setup() + { + // Utilisation d'une base de données en mémoire + var optionBuider = new DbContextOptionsBuilder() + .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()); + + // Act + var okResult = formationsApiController.GetFormationById(1); + + // Assert + Assert.IsInstanceOf(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 + } +} \ No newline at end of file