Files
Omika/tests/Omika.Tests/Mapping/BatikRendezVousMapperTests.cs
2026-10-23 18:46:50 +02:00

90 lines
3.2 KiB
C#

using Omika.Core.Compatibility;
using Omika.Core.Domain.Entities.Planning;
using BatikModels = Omika.Data.HfSql.Models.Batik;
using BatikMappers = Omika.Data.Mapping.Batik;
namespace Omika.Tests.Mapping;
/// <summary>
/// Tests unitaires du mapping Batik des valeurs de référentiel d'annulation d'un
/// rendez-vous. Aucune base réelle : uniquement des objets en mémoire.
///
/// En Batik, l'origine et le motif d'annulation sont stockés sous forme
/// d'identifiants numériques (<c>PL_IDOrigineAnnul</c> / <c>PL_IDMotifAnnul</c> →
/// <c>PA_PKID</c>). Ils doivent être résolus dans le référentiel ParametreMetier,
/// sans quoi la fiche du rendez-vous n'affiche aucun libellé.
/// </summary>
public class BatikRendezVousMapperTests
{
[Fact]
public void Map_AnnulationAvecReferentiel_LibellesOrigineEtMotifResolusParPkId()
{
var row = new BatikModels.PlanningRDVRow
{
PLPKID = 42,
PLDateDebut = new DateTime(2026, 8, 19, 9, 0, 0),
PLDateFin = new DateTime(2026, 8, 19, 10, 0, 0),
PLIDOrigineAnnul = 2000UL,
PLIDMotifAnnul = 3000UL
};
var references = new Dictionary<long, BatikModels.ParametreMetierRow>
{
[2000L] = new BatikModels.ParametreMetierRow
{
PAPKID = 2000L,
PACode = "34",
PALibelle = "Externe : Client"
},
[3000L] = new BatikModels.ParametreMetierRow
{
PAPKID = 3000L,
PACode = "35",
PALibelle = "Absent"
}
};
CanonicalMappingResult<RendezVous> mapped = BatikMappers.BatikRendezVousMapper.Map(row, references);
Assert.NotNull(mapped.Value.Annulation);
Assert.Equal(2000L, mapped.Value.Annulation!.Origine!.LegacyId);
Assert.Equal("Externe : Client", mapped.Value.Annulation.Origine!.Label);
Assert.Equal(3000L, mapped.Value.Annulation.Motif!.LegacyId);
Assert.Equal("Absent", mapped.Value.Annulation.Motif!.Label);
}
[Fact]
public void Map_AnnulationSansReferentiel_ConserveLIdentifiantSansInventerDeLibelle()
{
var row = new BatikModels.PlanningRDVRow
{
PLPKID = 43,
PLDateDebut = new DateTime(2026, 8, 19, 9, 0, 0),
PLDateFin = new DateTime(2026, 8, 19, 10, 0, 0),
PLIDMotifAnnul = 3000UL
};
CanonicalMappingResult<RendezVous> mapped = BatikMappers.BatikRendezVousMapper.Map(row, null);
Assert.NotNull(mapped.Value.Annulation);
Assert.Equal(3000L, mapped.Value.Annulation!.Motif!.LegacyId);
Assert.True(string.IsNullOrEmpty(mapped.Value.Annulation.Motif!.Label));
Assert.Null(mapped.Value.Annulation.Origine);
}
[Fact]
public void Map_SansAnnulation_AucuneAnnulation()
{
var row = new BatikModels.PlanningRDVRow
{
PLPKID = 44,
PLDateDebut = new DateTime(2026, 8, 19, 9, 0, 0),
PLDateFin = new DateTime(2026, 8, 19, 10, 0, 0)
};
CanonicalMappingResult<RendezVous> mapped = BatikMappers.BatikRendezVousMapper.Map(row, null);
Assert.Null(mapped.Value.Annulation);
}
}