- GeradoresService: cada tipo passa a ser um IGenerator (NIF, NIPC, NISS, CC, passaporte, IBAN, NIB, cartões, referência MB, pessoa, telefone, código postal, email, matrícula, EAN, UUID) registado em GeneratorRegistry; remove DAL/EF - GeradoresWS: minimal APIs em /api/v1 com OpenAPI + Scalar e health check - UnitTest: testes de ida e volta, valores conhecidos, detecção e API - geradoresfe: UI construída a partir dos metadados da API, validador livre, exportação CSV/JSON/TXT, nginx com API_UPSTREAM configurável - Docker, docker-compose e Jenkinsfile actualizados Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
3.3 KiB
C#
70 lines
3.3 KiB
C#
using GeradoresService.Core;
|
||
using GeradoresService.Data;
|
||
using GeradoresService.Generators.Financeiro;
|
||
using GeradoresService.Generators.Identificacao;
|
||
|
||
namespace GeradoresService.Generators.Contactos;
|
||
|
||
/// <summary>Pessoa fictícia completa, com todos os identificadores válidos.</summary>
|
||
public sealed class PessoaGenerator : GeneratorBase
|
||
{
|
||
public override string Id => "pessoa";
|
||
public override string Name => "Pessoa fictícia";
|
||
public override string Category => Categories.Contactos;
|
||
public override string Description => "Nome, data de nascimento, NIF, NISS, CC, contactos, morada e IBAN — tudo consistente e válido.";
|
||
public override bool CanValidate => false;
|
||
|
||
public override IReadOnlyList<GeneratorOption> Options =>
|
||
[
|
||
Option("genero", "Género", "qualquer", ("qualquer", "Qualquer"), ("f", "Feminino"), ("m", "Masculino")),
|
||
Option("idade", "Idade", "adulto", ("adulto", "Adulto (18–80)"), ("menor", "Menor (0–17)"), ("qualquer", "Qualquer (0–90)")),
|
||
];
|
||
|
||
public override ValidationResult Validate(string value) =>
|
||
ValidationResult.WrongFormat("Este gerador não tem validação.");
|
||
|
||
public override GeneratedItem Generate(GeneratorContext context)
|
||
{
|
||
var genero = context.Option(Options[0]);
|
||
if (genero == "qualquer")
|
||
genero = context.Random.Next(2) == 0 ? "f" : "m";
|
||
|
||
var names = genero == "f" ? PtData.FemaleNames : PtData.MaleNames;
|
||
var first = context.Pick(names);
|
||
var middle = context.Random.Next(3) == 0 ? " " + context.Pick(names.Where(n => n != first).ToArray()) : "";
|
||
var surname1 = context.Pick(PtData.Surnames);
|
||
var surname2 = context.Pick(PtData.Surnames.Where(s => s != surname1).ToArray());
|
||
var fullName = $"{first}{middle} {surname1} {surname2}";
|
||
|
||
var (minAge, maxAge) = context.Option(Options[1]) switch
|
||
{
|
||
"menor" => (0, 17),
|
||
"qualquer" => (0, 90),
|
||
_ => (18, 80),
|
||
};
|
||
var today = DateOnly.FromDateTime(DateTime.UtcNow);
|
||
var birth = today.AddYears(-maxAge - 1).AddDays(1 + context.Random.Next((maxAge - minAge + 1) * 365));
|
||
|
||
var (cp, locality, _) = CodigoPostalGenerator.Random(context);
|
||
var street = $"{context.Pick(PtData.StreetTypes)} {context.Pick(PtData.StreetNames)}, {1 + context.Random.Next(300)}";
|
||
var nibContext = new GeneratorContext(context.Random, new Dictionary<string, string?>());
|
||
|
||
var fields = new Dictionary<string, string>
|
||
{
|
||
["Nome"] = fullName,
|
||
["Género"] = genero == "f" ? "Feminino" : "Masculino",
|
||
["Data de nascimento"] = birth.ToString("yyyy-MM-dd"),
|
||
["NIF"] = NifGenerator.Build(context.Pick(["1", "2", "3"]), context),
|
||
["NISS"] = new NissGenerator().Generate(nibContext).Value,
|
||
["Cartão de Cidadão"] = new CartaoCidadaoGenerator().Generate(nibContext).Value,
|
||
["Telemóvel"] = new TelefoneGenerator().Generate(nibContext).Value,
|
||
["Email"] = EmailGenerator.Build(first, surname2, context),
|
||
["Morada"] = street,
|
||
["Código postal"] = cp,
|
||
["Localidade"] = locality,
|
||
["IBAN"] = new IbanGenerator().Generate(nibContext).Value,
|
||
};
|
||
return new GeneratedItem(fullName, fields);
|
||
}
|
||
}
|