diff --git a/src/Nyanlabs.Umogen.Core/Models/IEntity.cs b/src/Nyanlabs.Umogen.Core/Models/IEntity.cs new file mode 100644 index 0000000..0c11c94 --- /dev/null +++ b/src/Nyanlabs.Umogen.Core/Models/IEntity.cs @@ -0,0 +1,7 @@ +namespace Nyanlabs.Umogen.Core.Models; + +public interface IEntity : INLSerializable +{ + public string GetName(); + public string? IdCode(); +} diff --git a/src/Nyanlabs.Umogen.Core/Models/LegalEntity.cs b/src/Nyanlabs.Umogen.Core/Models/LegalEntity.cs new file mode 100644 index 0000000..027c4ea --- /dev/null +++ b/src/Nyanlabs.Umogen.Core/Models/LegalEntity.cs @@ -0,0 +1,24 @@ +namespace Nyanlabs.Umogen.Core.Models; + +public class LegalEntity(string Name, string? Nip = null, string? Headquarters = null, Person? Representative = null) : IEntity, INLSerializable +{ + public string Name { get; set; } = Name; + public string? Nip { get; set; } = Nip; + public string? Headquarters { get; set; } = Headquarters; + public Person? Representative { get; set; } = Representative; + + public string GetName() + { + return Name; + } + + public string? IdCode() + { + return Nip; + } + + public string NLSerialize() + { + return $"{Name}; with NIP {Nip ?? "unknown"}{(Headquarters != null ? $"; located in {Headquarters}" : "")}{(Representative != null ? $"; represented by {Representative.GetName()}" : "")}"; + } +} diff --git a/src/Nyanlabs.Umogen.Core/Models/Person.cs b/src/Nyanlabs.Umogen.Core/Models/Person.cs index 1befbe4..343d09d 100644 --- a/src/Nyanlabs.Umogen.Core/Models/Person.cs +++ b/src/Nyanlabs.Umogen.Core/Models/Person.cs @@ -1,6 +1,6 @@ namespace Nyanlabs.Umogen.Core.Models; -public record Person(string Name, string Surname, string? Id = null, string? Pesel = null, DateTime? DoB = null) : INLSerializable +public record Person(string Name, string Surname, string? Id = null, string? Pesel = null, DateTime? DoB = null) : IEntity, INLSerializable { public string Name { get; set; } = Name; public string Surname { get; set; } = Surname; @@ -8,6 +8,16 @@ public record Person(string Name, string Surname, string? Id = null, string? Pes public string? Pesel { get; set; } = Pesel; public DateTime? DoB { get; set; } = DoB; + public string GetName() + { + return $"{Name} {Surname}"; + } + + public string? IdCode() + { + return IDCode!; + } + public string NLSerialize() { return $"{Name} {Surname}; {(Pesel != null ? $"PESEL {Pesel}" : "unknown PESEL")}; {(IDCode != null ? $"ID series {IDCode}" : "unknown ID series")}; {(DoB != null ? $"born {DoB.Value:dd MMM yyyy}" : "unknown date of birth")}"; diff --git a/src/Nyanlabs.Umogen.Core/Models/UmoDocument.cs b/src/Nyanlabs.Umogen.Core/Models/UmoDocument.cs index 291b648..0ad4733 100644 --- a/src/Nyanlabs.Umogen.Core/Models/UmoDocument.cs +++ b/src/Nyanlabs.Umogen.Core/Models/UmoDocument.cs @@ -30,7 +30,7 @@ public static class UmoDoctypeBindings public class UmoDocument : INLSerializable { - public UmoDocument(UmoDoctype type, Person employer, Person employee, ValidTime? validTime = null) + public UmoDocument(UmoDoctype type, IEntity employer, Person employee, ValidTime? validTime = null) { Doctype = type; Employer = employer; @@ -39,7 +39,7 @@ public class UmoDocument : INLSerializable } public UmoDoctype Doctype { get; set; } - public Person Employer { get; set; } + public IEntity Employer { get; set; } public Person Employee { get; set; } //Null is 'unspecified time' public ValidTime? ValidTime { get; set; } diff --git a/test/Nyanlabs.Umogen.CoreTests/NLSerializationTests.cs b/test/Nyanlabs.Umogen.CoreTests/NLSerializationTests.cs index 2e60fd8..46d23f8 100644 --- a/test/Nyanlabs.Umogen.CoreTests/NLSerializationTests.cs +++ b/test/Nyanlabs.Umogen.CoreTests/NLSerializationTests.cs @@ -18,7 +18,7 @@ public class NLSerializationTests var query = doc.NLSerialize(); // Then - Assert.Equal($"Contract of Employment for {ModelEmployee.NLSerialize()} working for {ModelEmployer.NLSerialize()}; valid for unspecified time.", query); + Assert.Equal($"Umowa o Pracę for {ModelEmployee.NLSerialize()} working for {ModelEmployer.NLSerialize()}; valid for unspecified time.", query); } [Fact] @@ -31,7 +31,7 @@ public class NLSerializationTests var query = doc.NLSerialize(); // Then - Assert.Equal($"Contract of Employment for {ModelEmployee.NLSerialize()} working for {ModelEmployer.NLSerialize()}; valid from 17 Nov 2023 until 18 Nov 2023.", query); + Assert.Equal($"Umowa o Pracę for {ModelEmployee.NLSerialize()} working for {ModelEmployer.NLSerialize()}; valid from 17 Nov 2023 until 18 Nov 2023.", query); } [Fact] @@ -64,4 +64,19 @@ public class NLSerializationTests // Then Assert.Equal("Kotek Miauczyński; unknown PESEL; unknown ID series; unknown date of birth", query); } + + private LegalEntity ModelCompany => new("Nyanbyte P.S.A.", "1313131313", "Miaumiaśna 13, Miauczki", ModelEmployer); + + [Fact] + public void CompanySerializationTest() + { + // Given + LegalEntity company = ModelCompany; + + // When + var query = company.NLSerialize(); + + // Then + Assert.Equal("Nyanbyte P.S.A.; with NIP 1313131313; located in Miaumiaśna 13, Miauczki; represented by Kotek Miauczyński", query); + } }