From dc3ff3c07b28e0c61ec38699467f725871090556 Mon Sep 17 00:00:00 2001 From: Freddy <100769900+FreddyFox892@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:54:56 +0100 Subject: [PATCH] Make `ZeitabhaengigeBeziehung.GueltigBis` Optional (#610) * Make Enddate Optional * Extend Test * add * , * Add test * cscharping * Update BO4ETestProject/TestLinkExtensions.cs * Update BO4E/Marktkommunikation/ZeitabhaengigeBeziehung.cs --------- Co-authored-by: konstantin --- .../ZeitabhaengigeBeziehung.cs | 10 +++- BO4ETestProject/TestLinkExtensions.cs | 51 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/BO4E/Marktkommunikation/ZeitabhaengigeBeziehung.cs b/BO4E/Marktkommunikation/ZeitabhaengigeBeziehung.cs index 85d8926e..e601d7f5 100644 --- a/BO4E/Marktkommunikation/ZeitabhaengigeBeziehung.cs +++ b/BO4E/Marktkommunikation/ZeitabhaengigeBeziehung.cs @@ -21,12 +21,18 @@ public class ZeitabhaengigeBeziehung public DateTimeOffset GueltigVon { get; set; } /// - /// exklusives Ende + /// Offene Zeitscheiben werden mit GueltigBis = null modelliert, _nicht_ mit DateTimeOffset.MaxValue. + /// The maximum end date is NULL, this means DateTimeOffset.MaxValue is converted to null by the setter. /// [JsonPropertyName("gueltigBis")] [JsonPropertyOrder(2)] [Newtonsoft.Json.JsonProperty(PropertyName = "gueltigBis", Order = 2)] - public DateTimeOffset GueltigBis { get; set; } + public DateTimeOffset? GueltigBis + { + get => _gueltigBis; + set => _gueltigBis = (value == DateTimeOffset.MaxValue) ? null : value; + } + private DateTimeOffset? _gueltigBis; /// /// e.g. diff --git a/BO4ETestProject/TestLinkExtensions.cs b/BO4ETestProject/TestLinkExtensions.cs index 7b340034..535a2b04 100644 --- a/BO4ETestProject/TestLinkExtensions.cs +++ b/BO4ETestProject/TestLinkExtensions.cs @@ -124,4 +124,55 @@ public void Test_Zeitabhaengig_To_Links() actual.Should().ContainKey("x").WhoseValue.Should().HaveCount(2); actual.Should().ContainKey("foo").WhoseValue.Should().HaveCount(2); } + + [TestMethod] + public void Test_Zeitabhaengig_To_Links_with_Null_Until() + { + var bc = new BOneyComb + { + ZeitabhaengigeLinks = new() + { + new ZeitabhaengigeBeziehung + { + ParentId = "foo", + ChildId = "bar", + GueltigVon = DateTimeOffset.MinValue, + }, + new ZeitabhaengigeBeziehung + { + ParentId = "foo", + ChildId = "baz", + GueltigVon = DateTimeOffset.MinValue, + }, + new ZeitabhaengigeBeziehung + { + ParentId = "x", + ChildId = "y", + GueltigVon = DateTimeOffset.MinValue, + }, + new ZeitabhaengigeBeziehung + { + ParentId = "x", + ChildId = "z", + GueltigVon = DateTimeOffset.MinValue, + }, + }, + }; + var actual = bc.ZeitabhaengigeLinks.ToTimeIndependentLinks(); + actual.Should().ContainKey("x").WhoseValue.Should().HaveCount(2); + actual.Should().ContainKey("foo").WhoseValue.Should().HaveCount(2); + } + + [TestMethod] + public void Test_inifinteTime_is_null() + { + ZeitabhaengigeBeziehung timeMax = new ZeitabhaengigeBeziehung() + { + ParentId = "x", + ChildId = "y", + GueltigVon = DateTimeOffset.MinValue, + GueltigBis = DateTimeOffset.MaxValue, + }; + timeMax.GueltigBis.Should().BeNull(because: "the setter converts MaxValue to null"); + } }