Skip to content

Commit 8ab0cca

Browse files
committed
17 - First telegram tests
1 parent 4ae9e12 commit 8ab0cca

File tree

3 files changed

+89
-18
lines changed

3 files changed

+89
-18
lines changed

tests/BaseTelegramTest.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
namespace RS485_Monitor.tests;
2+
using NUnit.Framework;
3+
4+
public class BaseTelegramTest
5+
{
6+
[Test]
7+
public void ParseTelegramSuccessful()
8+
{
9+
byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0xDA, 0x0A, 0x02, 0x00, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D };
10+
11+
BaseTelegram telegram = new(raw);
12+
13+
Assert.That(telegram.Type, Is.EqualTo(BaseTelegram.TelegramType.READ_RESPONSE));
14+
Assert.That(telegram.Destination, Is.EqualTo(0xDA));
15+
Assert.That(telegram.Source, Is.EqualTo(0xAA));
16+
Assert.That(telegram.Valid, Is.EqualTo(true));
17+
}
18+
19+
[Test]
20+
public void ParseTelegramRequestSuccessful()
21+
{
22+
byte[] raw = new byte[] { 0xC5, 0x5C, 0xAA, 0xDA, 0x0A, 0x02, 0x00, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D };
23+
24+
BaseTelegram telegram = new(raw);
25+
26+
Assert.That(telegram.Type, Is.EqualTo(BaseTelegram.TelegramType.READ_REQUEST));
27+
Assert.That(telegram.Destination, Is.EqualTo(0xDA));
28+
Assert.That(telegram.Source, Is.EqualTo(0xAA));
29+
Assert.That(telegram.Valid, Is.EqualTo(true));
30+
}
31+
32+
[Test]
33+
public void ParseTelegramWrongChecksum()
34+
{
35+
byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0xDA, 0x0A, 0x02, 0x10, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D };
36+
37+
BaseTelegram telegram = new(raw);
38+
39+
Assert.That(telegram.Type, Is.EqualTo(BaseTelegram.TelegramType.READ_RESPONSE));
40+
Assert.That(telegram.Destination, Is.EqualTo(0xDA));
41+
Assert.That(telegram.Source, Is.EqualTo(0xAA));
42+
Assert.That(telegram.Valid, Is.EqualTo(false));
43+
}
44+
45+
}

tests/ECUStatusTest.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace RS485_Monitor.tests;
2+
using NUnit.Framework;
3+
4+
public class ECUStatusTest
5+
{
6+
private BaseTelegram? ecuBase;
7+
8+
[SetUp]
9+
public void Setup()
10+
{
11+
byte[] raw = new byte[] { 0xB6, 0x6B, 0xAA, 0xDA, 0x0A, 0x02, 0x00, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x02, 0x01, 0x1C, 0x0D };
12+
ecuBase = new BaseTelegram(raw);
13+
}
14+
15+
[Test]
16+
public void ConvertToEcuStatusSuccess()
17+
{
18+
ECUStatus status = new(ecuBase!);
19+
}
20+
21+
[Test]
22+
public void ConvertToEcuStatusFail()
23+
{
24+
byte[] raw = new byte[] { 0xC5, 0x5C, 0xBA, 0xAA, 0x0E, 0x48, 0x00, 0x00, 0x00, 0x16, 0x19, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x40, 0x0A, 0x0D };
25+
BaseTelegram gsmTelegram = new(raw);
26+
27+
Assert.Throws<ArgumentException>(() => new ECUStatus(gsmTelegram));
28+
}
29+
30+
[Test]
31+
public void CheckContent()
32+
{
33+
ECUStatus status = new(ecuBase!);
34+
using (Assert.EnterMultipleScope())
35+
{
36+
Assert.That(status.Mode, Is.EqualTo(2));
37+
Assert.That(status.Current, Is.EqualTo(0.4).Within(0.1));
38+
Assert.That(status.Speed, Is.EqualTo(0));
39+
Assert.That(status.Temperature, Is.EqualTo(0x13));
40+
Assert.That(status.IsParking, Is.EqualTo(true));
41+
}
42+
43+
}
44+
}

tests/UnitTest1.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)