using System.Reflection; using Omika.Data.HfSql.Metadata; namespace Omika.Tests; /// /// Tests de cohérence des modèles physiques HFSQL générés à partir du /// dictionnaire de compatibilité Batik / Omika (docs/schema-compatibilite-batik-omika.json). /// /// Ces tests valident que les classes générées portent bien leurs attributs /// de mapping : nom de table, nom de fichier disque, clé primaire, rubriques /// HFSQL physiques et marquage des rubriques « zombie ». /// public class HfSqlModelTests { [Theory] [InlineData("Omika.Data.HfSql.Models.Omika.DocumentRow")] [InlineData("Omika.Data.HfSql.Models.Omika.InterventionRow")] [InlineData("Omika.Data.HfSql.Models.Omika.RDVPlanningRow")] [InlineData("Omika.Data.HfSql.Models.Batik.DocumentRow")] [InlineData("Omika.Data.HfSql.Models.Batik.InterventionRow")] public void Model_HasHfSqlTableAttribute(string typeName) { Type? type = Type.GetType(typeName + ", Omika.Data"); Assert.NotNull(type); HfSqlTableAttribute? attr = type!.GetCustomAttribute(); Assert.NotNull(attr); Assert.False(string.IsNullOrWhiteSpace(attr!.TableName)); } [Fact] public void OmikaDocumentRow_HasExpectedMapping() { Type type = typeof(Omika.Data.HfSql.Models.Omika.DocumentRow); HfSqlTableAttribute? table = type.GetCustomAttribute(); Assert.NotNull(table); Assert.Equal("Document", table!.TableName); Assert.Equal("Document.fic", table.DiskName); Assert.Contains("ProtectionStd", table.Groups); Assert.Contains("Omika", table.SchemaVersions); PropertyInfo pk = type.GetProperty(nameof(Omika.Data.HfSql.Models.Omika.DocumentRow.DCPKID)) ?? throw new InvalidOperationException("Propriété DCPKID introuvable."); Assert.NotNull(pk.GetCustomAttribute()); PropertyInfo zombie = type.GetProperty(nameof(Omika.Data.HfSql.Models.Omika.DocumentRow.DCCategorie)) ?? throw new InvalidOperationException("Propriété DCCategorie introuvable."); HfSqlColumnAttribute? column = zombie.GetCustomAttribute(); Assert.NotNull(column); Assert.Equal("DC_Categorie", column!.ColumnName); Assert.True(column.IsZombie); Assert.NotNull(zombie.GetCustomAttribute()); } [Fact] public void OmikaDocumentRow_HasOmikaOnlyColumns() { Type type = typeof(Omika.Data.HfSql.Models.Omika.DocumentRow); PropertyInfo cleCategorie = type.GetProperty(nameof(Omika.Data.HfSql.Models.Omika.DocumentRow.DCCleCategorie)) ?? throw new InvalidOperationException("Propriété DCCleCategorie introuvable."); HfSqlColumnAttribute? column = cleCategorie.GetCustomAttribute(); Assert.NotNull(column); Assert.True(column!.IsOmikaOnly); } [Fact] public void BatikInterventionCollaborateur_ExistsOnlyInBatik() { // La table Intervention_Collaborateur n'existe que dans l'ancienne base. Type? batik = Type.GetType("Omika.Data.HfSql.Models.Batik.InterventionCollaborateurRow, Omika.Data"); Type? omika = Type.GetType("Omika.Data.HfSql.Models.Omika.InterventionCollaborateurRow, Omika.Data"); Assert.NotNull(batik); Assert.Null(omika); HfSqlTableAttribute? attr = batik!.GetCustomAttribute(); Assert.NotNull(attr); Assert.Equal(["Batik"], attr!.SchemaVersions); } [Fact] public void OmikaOnlyTables_HaveNoBatikCounterpart() { string[] omikaOnly = ["DocAide", "CategorieAcces", "ElementModifie", "ElementSupprime", "Etats", "ModeleRapport", "RDVCollaborateur", "RDVContact", "RDVPlanning", "Role", "RubriquesDocument"]; foreach (string table in omikaOnly) { string typeName = "Omika.Data.HfSql.Models.Omika." + table + "Row, Omika.Data"; Type? omikaType = Type.GetType(typeName); Assert.NotNull(omikaType); } } }