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

79 lines
2.1 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, collaborateur;
#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("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<ReferentsEPApiController>());
ReferentEPDTO referentEPDTO = new ReferentEPDTO()
{
IdReferent = referent,
IdsCollaborateur = new List<Guid?>()
};
referentEPDTO.IdsCollaborateur.Add(collaborateur);
Task<IActionResult> task = referentsEPApi.UpdateReferentCollaborateur(referentEPDTO, collaborateur);
OkObjectResult result = task.Result as OkObjectResult;
Assert.AreEqual(200, result.StatusCode);
Assert.IsInstanceOf<ReferentEPDTO>(result.Value);
}
#endregion
}
}