Skip to content

Commit

Permalink
Make ZeitabhaengigeBeziehung.GueltigBis Optional (#610)
Browse files Browse the repository at this point in the history
* Make Enddate Optional

* Extend Test

* add

* ,

* Add test

* cscharping

* Update BO4ETestProject/TestLinkExtensions.cs

* Update BO4E/Marktkommunikation/ZeitabhaengigeBeziehung.cs

---------

Co-authored-by: konstantin <[email protected]>
  • Loading branch information
FreddyFox892 and hf-kklein authored Nov 25, 2024
1 parent 2910114 commit dc3ff3c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
10 changes: 8 additions & 2 deletions BO4E/Marktkommunikation/ZeitabhaengigeBeziehung.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ public class ZeitabhaengigeBeziehung
public DateTimeOffset GueltigVon { get; set; }

/// <summary>
/// exklusives Ende
/// Offene Zeitscheiben werden mit <code>GueltigBis = null</code> modelliert, _nicht_ mit <code>DateTimeOffset.MaxValue</code>.
/// The maximum end date is NULL, this means DateTimeOffset.MaxValue is converted to null by the setter.
/// </summary>
[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;

/// <summary>
/// e.g.
Expand Down
51 changes: 51 additions & 0 deletions BO4ETestProject/TestLinkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit dc3ff3c

Please sign in to comment.