Add legal entity

This commit is contained in:
femsci 2023-11-17 23:37:35 +01:00
parent 7b322ef7fb
commit b9c218111a
Signed by: femsci
GPG key ID: 08F7911F0E650C67
5 changed files with 61 additions and 5 deletions

View file

@ -0,0 +1,7 @@
namespace Nyanlabs.Umogen.Core.Models;
public interface IEntity : INLSerializable
{
public string GetName();
public string? IdCode();
}

View file

@ -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()}" : "")}";
}
}

View file

@ -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")}";

View file

@ -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; }

View file

@ -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);
}
}