using EPAServeur.Context; using EPAServeur.IServices; using EPAServeur.Services; using IO.Swagger.ApiCollaborateur; using IO.Swagger.Controllers; using IO.Swagger.DTO; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging.Abstractions; using NUnit.Framework; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; namespace EPAServeur.Tests.Controllers { [TestFixture] public class ReferentEPApiTests { #region Variables private EpContext context; private ICollaborateurApi collaborateurApi; private IReferentEPService referentEPService; private Guid? referent, collaborateur; #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; context = new EpContext(optionBuider); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.SaveChanges(); foreach (var entity in context.ChangeTracker.Entries()) { entity.State = EntityState.Detached; } collaborateurApi = new CollaborateurApi(); referentEPService = new ReferentEPService(context, collaborateurApi); referent = new Guid("ecf528c3-e509-402f-87bb-c8821467e350"); collaborateur = new Guid("006226f6-51b2-4a02-a302-7447f7fccc04"); } #endregion #region Tests [Test] public void UpdateReferentCollaborateur() { ReferentsEPApiController referentsEPApi = new ReferentsEPApiController(referentEPService, new NullLogger()); ReferentEPDTO referentEPDTO = new ReferentEPDTO() { IdReferent = referent, IdsCollaborateur = new List() }; referentEPDTO.IdsCollaborateur.Add(collaborateur); Task task = referentsEPApi.UpdateReferentCollaborateur(referentEPDTO, collaborateur); OkObjectResult result = task.Result as OkObjectResult; Assert.AreEqual(200, result.StatusCode); Assert.IsInstanceOf(result.Value); } #endregion } }