📄
tests/StorageHeaderTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using Shouldly; namespace SharpDlt.Tests; public class StorageHeaderTests { [Fact] public void Parse_ReadsAllFields() { var data = TestDlt.StorageHeader(seconds: 1_600_000_000, microseconds: 123_456, ecuId: "ECU"); var header = StorageHeader.Parse(data); header.Seconds.ShouldBe(1_600_000_000u); header.Microseconds.ShouldBe(123_456); header.EcuId.ShouldBe("ECU"); } [Fact] public void Parse_StripsNulPaddingOfEcuId() { var data = TestDlt.StorageHeader(ecuId: "AB"); StorageHeader.Parse(data).EcuId.ShouldBe("AB"); } [Fact] public void Parse_IgnoresTrailingData() { var data = TestDlt.StorageHeader().Concat<byte>([1, 2, 3]).ToArray(); StorageHeader.Parse(data).EcuId.ShouldBe("ECU1"); } [Fact] public void Timestamp_CombinesSecondsAndMicroseconds() { var header = new StorageHeader(1_600_000_000, 500_000, "ECU1"); header.Timestamp.ShouldBe(DateTimeOffset.FromUnixTimeSeconds(1_600_000_000).AddMilliseconds(500)); } [Fact] public void Parse_TooShortData_Throws() { var data = TestDlt.StorageHeader()[..15]; Should.Throw<DltParseException>(() => StorageHeader.Parse(data)); } [Fact] public void Parse_WithoutDltPattern_Throws() { var data = TestDlt.StorageHeader(); data[0] = (byte)'X'; Should.Throw<DltParseException>(() => StorageHeader.Parse(data)); } [Fact] public void Equality_IsByValue() { new StorageHeader(1, 2, "ECU1").ShouldBe(new StorageHeader(1, 2, "ECU1")); new StorageHeader(1, 2, "ECU1").ShouldNotBe(new StorageHeader(1, 3, "ECU1")); } }