TU générique sur Controller

pull/4/head
Alexandre Ruiz 3 years ago
parent f29bb823b5
commit 16059ff5d0
  1. 64
      Collaborateur_Epa_Back/espacecollab.backend.api.tests/BaseControllerTest.cs
  2. 24
      Collaborateur_Epa_Back/espacecollab.backend.api.tests/CollaborateursControllerTest.cs
  3. 28
      Collaborateur_Epa_Back/espacecollab.backend.api.tests/espacecollab.backend.api.tests.csproj

@ -0,0 +1,64 @@
using System.Collections.Generic;
using espacecollab.backend.api.Controllers;
using espacecollab.backend.appservices.dtos.Interfaces;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Xunit;
namespace espacecollab.backend.api.tests;
public abstract class BaseControllerTest<T, TO> where T : IBaseController<TO>
where TO : class, IGenericIdApiDto
{
protected T Controller { get; set; }
protected TO NewApiDo { get; set; }
protected TO UpdateApiDo { get; set; }
[Fact]
public void GetAllTest()
{
ActionResult<IEnumerable<TO>> actionResult = Controller.GetAll();
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject;
result.Value.Should().BeOfType<List<TO>>();
}
[Fact]
public void GetByIdTest()
{
uint id = 1;
ActionResult<TO> actionResult = Controller.GetById(id);
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject;
result.Value.Should().BeOfType<TO>();
}
[Fact]
public void AddTest()
{
ActionResult<TO> actionResult = Controller.Add(NewApiDo);
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject;
result.Value.Should().BeOfType<TO>().Subject.Id.Should().NotBe(0);
}
[Fact]
public void DeleteTest()
{
uint id = 1;
ActionResult<TO> actionResult = Controller.Delete(id);
actionResult.Result.Should().BeOfType<OkResult>();
}
[Fact]
public void UpdateTest()
{
ActionResult<TO> actionResult = Controller.Update(UpdateApiDo.Id, UpdateApiDo);
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject;
result.Value.Should().BeOfType<TO>().Subject.Id.Should().Be(UpdateApiDo.Id);
}
}

@ -0,0 +1,24 @@
using espacecollab.backend.api.Controllers;
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Values;
using espacecollab.backend.infrastructure.fake;
using System;
namespace espacecollab.backend.api.tests;
public class CollaborateursControllerTest : BaseControllerTest<CollaborateursController, CollaborateurApiDto>
{
public CollaborateursControllerTest()
{
Controller = new CollaborateursController(new CollaborateursService(new FakeCollaborateurRepository()));
NewApiDo = new CollaborateurApiDto(0, "Dupont", "Jean", new DateTime(1980, 12, 10),
EnumGenreApi.MASCULIN, EnumStatutApi.NONCADRE, 0, "1 rue du Louvre, 63000, Clermont-Ferrand", "0660258644",
"jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), 2, 1);
UpdateApiDo = new CollaborateurApiDto(1, "Dupont 2", "Jean", new DateTime(1980, 12, 10),
EnumGenreApi.MASCULIN, EnumStatutApi.NONCADRE, 0, "1 rue du Louvre, 63000, Clermont-Ferrand", "0660258644",
"jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), 2, 1);
}
}

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\espacecollab.backend.api\espacecollab.backend.api.csproj" />
</ItemGroup>
</Project>
Loading…
Cancel
Save