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.
Digitalisation_EPA_Serveur/EPAServeur.Tests/Controllers/ReferentEPApiTests.cs

97 lines
3.0 KiB

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, collaborateur1, collaborateur2, collaborateur3;
#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();
foreach (var entity in context.ChangeTracker.Entries())
{
entity.State = EntityState.Detached;
}
collaborateurApi = new CollaborateurApi();
referentEPService = new ReferentEPService(context, collaborateurApi);
referent = new Guid("aa36f34c-9041-42f5-9db3-6536fe7f1696");
collaborateur1 = new Guid("301ba7f3-095e-4912-8998-a7c942dc5f23");
collaborateur2 = new Guid("a43b6f4f-f199-4dd0-93b6-a1cb2c0a0d14");
collaborateur3 = new Guid("b5254c6c-7caa-435f-a4bb-e0cf92559832");
}
#endregion
#region Tests
[Test]
public void UpdateReferentCollaborateur()
{
ReferentsEPApiController referentsEPApi = new ReferentsEPApiController(referentEPService, new NullLogger<ReferentsEPApiController>());
ReferentEPDTO referentEPDTO = new ReferentEPDTO()
{
IdReferent = referent,
IdsCollaborateur = new List<Guid?>()
};
referentEPDTO.IdsCollaborateur.Add(collaborateur1);
Task<IActionResult> task = referentsEPApi.UpdateReferentCollaborateur(referentEPDTO, collaborateur1);
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<ReferentEPDTO>(result.Value);
}
public void UpdateCollaborateursReferent()
{
ReferentsEPApiController referentsEPApi = new ReferentsEPApiController(referentEPService, new NullLogger<ReferentsEPApiController>());
ReferentEPDTO referentEPDTO = new ReferentEPDTO()
{
IdReferent = referent,
IdsCollaborateur = new List<Guid?>()
};
referentEPDTO.IdsCollaborateur.Add(collaborateur1);
referentEPDTO.IdsCollaborateur.Add(collaborateur2);
referentEPDTO.IdsCollaborateur.Add(collaborateur3);
Task<IActionResult> task = referentsEPApi.UpdateCollaborateursReferent(referentEPDTO, referent);
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<ReferentEPDTO>(result.Value);
}
#endregion
}
}