Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PackageVersion Include="MQTTnet" Version="5.0.1.1416" />
<PackageVersion Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageVersion Include="QRCoder" Version="1.6.0" />
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="SimpleExec" Version="12.0.0" />
<PackageVersion Include="Spectre.Console" Version="0.49.1" />
<PackageVersion Include="Spectre.Console.Json" Version="0.49.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NUnit" />
<PackageReference Include="NUnit3TestAdapter" />
Expand All @@ -17,6 +16,7 @@
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Shouldly" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public async Task SendTextMessage_ShouldReceiveAck_WhenDeviceConnected(Meshtasti
return await Task.FromResult(container.MyNodeInfo.MyNodeNum != 0);
});

container.Should().NotBeNull();
container.MyNodeInfo.Should().NotBeNull();
container.MyNodeInfo.MyNodeNum.Should().NotBe(0u);
container.ShouldNotBeNull();
container.MyNodeInfo.ShouldNotBeNull();
container.MyNodeInfo.MyNodeNum.ShouldNotBe(0u);

_logger.LogInformation($"Connected to device. Node number: {container.MyNodeInfo.MyNodeNum}");

Expand Down Expand Up @@ -88,8 +88,8 @@ await connection.WriteToRadio(toRadioFactory.CreateMeshPacketMessage(textMessage
}

// Assert
ackReceived.Should().BeTrue("An ACK should be received for the sent message");
errorReason.Should().Be(Routing.Types.Error.None, "The message should be delivered without errors");
ackReceived.ShouldBeTrue("An ACK should be received for the sent message");
errorReason.ShouldBe(Routing.Types.Error.None, "The message should be delivered without errors");
}

[Test]
Expand Down Expand Up @@ -124,14 +124,14 @@ public async Task GetDeviceInfo_ShouldReturnValidNodeInfo(MeshtasticDevice devic
}

// Assert
container.Should().NotBeNull();
container!.MyNodeInfo.Should().NotBeNull();
container.MyNodeInfo.MyNodeNum.Should().NotBe(0u);
container.ShouldNotBeNull();
container!.MyNodeInfo.ShouldNotBeNull();
container.MyNodeInfo.MyNodeNum.ShouldNotBe(0u);

var deviceNode = container.GetDeviceNodeInfo();
deviceNode.Should().NotBeNull();
deviceNode!.User.Should().NotBeNull();
deviceNode.User!.LongName.Should().NotBeNullOrEmpty();
deviceNode.ShouldNotBeNull();
deviceNode!.User.ShouldNotBeNull();
deviceNode.User!.LongName.ShouldNotBeNullOrEmpty();

_logger.LogInformation($"Device Info - Node: {container.MyNodeInfo.MyNodeNum}, " +
$"Name: '{deviceNode.User.LongName}', " +
Expand Down
2 changes: 1 addition & 1 deletion Meshtastic.IntegrationTest/Usings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
global using NUnit.Framework;
global using FluentAssertions;
global using Shouldly;
global using Microsoft.Extensions.Logging;
global using Meshtastic.Connections;
global using Meshtastic.Data;
Expand Down
29 changes: 14 additions & 15 deletions Meshtastic.Test/CommandHandlers/CommandHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public async Task MetadataCommandHandler_Should_ReceiveMetadataResponse()

ReceivedWantConfigPayloads();
InformationLogsContain("Getting device metadata");
container.FromRadioMessageLog.Should()
.Contain(fromRadio => fromRadio.GetPayload<AdminMessage>() != null &&
container.FromRadioMessageLog.ShouldContain(fromRadio => fromRadio.GetPayload<AdminMessage>() != null &&
fromRadio.GetPayload<AdminMessage>()!.GetDeviceMetadataResponse != null);
}

Expand All @@ -66,7 +65,7 @@ public void GetCommandHandler_Should_RejectBadSettings()
{
var settings = new List<string>() { "butt.farts" };
var handler = new GetCommandHandler(settings, ConnectionContext, CommandContext);
handler.ParsedSettings.Should().BeNull();
handler.ParsedSettings.ShouldBeNull();
}

[Test]
Expand All @@ -78,7 +77,7 @@ public async Task SetCommandHandler_Should_SetValues()
await handler.Handle();

var container = await new InfoCommandHandler(ConnectionContext, CommandContext).Handle();
container.LocalConfig.Display.ScreenOnSecs.Should().Be(123456);
container.LocalConfig.Display.ScreenOnSecs.ShouldBe((uint)123456);
}

[Test]
Expand All @@ -87,7 +86,7 @@ public void SetCommandHandler_Should_RejectBadSettings()
{
var settings = new List<string>() { "butt.farts=2" };
var handler = new SetCommandHandler(settings, ConnectionContext, CommandContext);
handler.ParsedSettings.Should().BeNull();
handler.ParsedSettings.ShouldBeNull();
}

// [Test]
Expand All @@ -99,7 +98,7 @@ public void SetCommandHandler_Should_RejectBadSettings()
// InformationLogsContain("Sending position to device");
// InformationLogsContain("Setting Position.FixedPosition to True");
// var routingPacket = container.FromRadioMessageLog.First(fromRadio => fromRadio.GetPayload<Routing>() != null);
// routingPacket.GetPayload<Routing>()!.ErrorReason.Should().Be(Routing.Types.Error.None);
// routingPacket.GetPayload<Routing>()!.ErrorReason.ShouldBe(Routing.Types.Error.None);
// }

[Test]
Expand All @@ -111,9 +110,9 @@ public async Task ChannelCommandHandler_Should_SavePrimaryChannel()
var container = await handler.Handle();
InformationLogsContain("Writing channel");
var routingPacket = container.FromRadioMessageLog.First(fromRadio => fromRadio.GetPayload<Routing>() != null);
routingPacket.GetPayload<Routing>()!.ErrorReason.Should().Be(Routing.Types.Error.None);
routingPacket.GetPayload<Routing>()!.ErrorReason.ShouldBe(Routing.Types.Error.None);
var adminMessages = container.ToRadioMessageLog.Where(toRadio => toRadio?.Packet?.Decoded.Portnum == PortNum.AdminApp);
adminMessages.Should().Contain(adminMessage =>
adminMessages.ShouldContain(adminMessage =>
AdminMessage.Parser.ParseFrom(adminMessage.Packet.Decoded.Payload).PayloadVariantCase == AdminMessage.PayloadVariantOneofCase.SetChannel);
}

Expand All @@ -126,9 +125,9 @@ public async Task ChannelCommandHandler_Should_SavePrimaryChannelWithNoPsk()
var container = await handler.Handle();
InformationLogsContain("Writing channel");
var routingPacket = container.FromRadioMessageLog.First(fromRadio => fromRadio.GetPayload<Routing>() != null);
routingPacket.GetPayload<Routing>()!.ErrorReason.Should().Be(Routing.Types.Error.None);
routingPacket.GetPayload<Routing>()!.ErrorReason.ShouldBe(Routing.Types.Error.None);
var adminMessages = container.ToRadioMessageLog.Where(toRadio => toRadio?.Packet?.Decoded.Portnum == PortNum.AdminApp);
adminMessages.Should().Contain(adminMessage =>
adminMessages.ShouldContain(adminMessage =>
AdminMessage.Parser.ParseFrom(adminMessage.Packet.Decoded.Payload).PayloadVariantCase == AdminMessage.PayloadVariantOneofCase.SetChannel);
}

Expand All @@ -141,9 +140,9 @@ public async Task ChannelCommandHandler_Should_SavePrimaryChannelWithPsk()
var container = await handler.Handle();
InformationLogsContain("Writing channel");
var routingPacket = container.FromRadioMessageLog.First(fromRadio => fromRadio.GetPayload<Routing>() != null);
routingPacket.GetPayload<Routing>()!.ErrorReason.Should().Be(Routing.Types.Error.None);
routingPacket.GetPayload<Routing>()!.ErrorReason.ShouldBe(Routing.Types.Error.None);
var adminMessages = container.ToRadioMessageLog.Where(toRadio => toRadio?.Packet?.Decoded.Portnum == PortNum.AdminApp);
adminMessages.Should().Contain(adminMessage =>
adminMessages.ShouldContain(adminMessage =>
AdminMessage.Parser.ParseFrom(adminMessage.Packet.Decoded.Payload).PayloadVariantCase == AdminMessage.PayloadVariantOneofCase.SetChannel);
}

Expand All @@ -156,9 +155,9 @@ public async Task ChannelCommandHandler_Should_AllowEnableOfSecondary()
var container = await handler.Handle();
InformationLogsContain("Writing channel");
var routingPacket = container.FromRadioMessageLog.First(fromRadio => fromRadio.GetPayload<Routing>() != null);
routingPacket.GetPayload<Routing>()!.ErrorReason.Should().Be(Routing.Types.Error.None);
routingPacket.GetPayload<Routing>()!.ErrorReason.ShouldBe(Routing.Types.Error.None);
var adminMessages = container.ToRadioMessageLog.Where(toRadio => toRadio?.Packet?.Decoded.Portnum == PortNum.AdminApp);
adminMessages.Should().Contain(adminMessage =>
adminMessages.ShouldContain(adminMessage =>
AdminMessage.Parser.ParseFrom(adminMessage.Packet.Decoded.Payload).PayloadVariantCase == AdminMessage.PayloadVariantOneofCase.SetChannel);
}

Expand All @@ -169,6 +168,6 @@ public async Task ChannelCommandHandler_Should_ThrowExceptionForOutOfRangeIndex(
var channelSettings = new ChannelOperationSettings(ChannelOperation.Save, 10, null, null, null, null, null);
var handler = new ChannelCommandHandler(channelSettings, ConnectionContext, CommandContext);
var action = () => handler.Handle();
await action.Should().ThrowAsync<IndexOutOfRangeException>();
await action.ShouldThrowAsync<IndexOutOfRangeException>();
}
}
12 changes: 6 additions & 6 deletions Meshtastic.Test/Commands/CannedMessagesCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ public void Setup()
public async Task CannedMessagesCommand_Should_Fail_ForEmptyOrNullMessagesOnSet()
{
var result = await rootCommand.InvokeAsync("canned-messages set --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Must specify pipe delimited messages");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Must specify pipe delimited messages");
}

[Test]
public async Task CannedMessagesCommand_Should_Fail_ForPipelessMessagesOnSet()
{
var result = await rootCommand.InvokeAsync("canned-messages set hello --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Must specify pipe delimited messages");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Must specify pipe delimited messages");
}

[Test]
public async Task CannedMessagesCommand_Should_Succeed_ForValidGet()
{
var result = await rootCommand.InvokeAsync("canned-messages get --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}

[Test]
public async Task CannedMessagesCommand_Should_Succeed_ForValidSet()
{
var result = await rootCommand.InvokeAsync("canned-messages set \"I need an alpinist|Halp\" --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
14 changes: 7 additions & 7 deletions Meshtastic.Test/Commands/ChannelCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ public void Setup()
public async Task ChannelCommand_Should_Succeed_ForValidArgs()
{
var result = await rootCommand.InvokeAsync("channel save --index 0 --name \"Derp\"s --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
result.ShouldBeGreaterThan(0);
}

[Test]
public async Task ChannelCommand_Should_Fail_ForIndexOutOfRange()
{
var result = await rootCommand.InvokeAsync("channel disable --index 10 --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Channel index is out of range");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Channel index is out of range");
}

[Test]
public async Task ChannelCommand_Should_Fail_ForEnable_DisablePrimary()
{
var result = await rootCommand.InvokeAsync("channel disable --index 0 --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Cannot enable / disable PRIMARY channel");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Cannot enable / disable PRIMARY channel");
result = await rootCommand.InvokeAsync("channel enable --index 0 --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Cannot enable / disable PRIMARY channel");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Cannot enable / disable PRIMARY channel");
}
}
2 changes: 1 addition & 1 deletion Meshtastic.Test/Commands/FactoryResetCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void Setup()
public async Task FactoryReset_Should_Succeed_ForValidArgs()
{
var result = await rootCommand.InvokeAsync("factory-reset --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
result.ShouldBeGreaterThan(0);
}
}
6 changes: 3 additions & 3 deletions Meshtastic.Test/Commands/FileCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public void Setup()
public async Task FileCommand_Should_Fail_ForEmptyOrNullText()
{
var result = await rootCommand.InvokeAsync("file --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Required argument missing for command: 'file'");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Required argument missing for command: 'file'");
}

[Test]
public async Task FileCommand_Should_Succeed_ForValidText()
{
var result = await rootCommand.InvokeAsync("file 'Butt.txt' --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
18 changes: 9 additions & 9 deletions Meshtastic.Test/Commands/FixedPositionCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ public void Setup()
public async Task FixedPositionCommand_Should_Fail_ForInvalidLat()
{
var result = await rootCommand.InvokeAsync("fixed-position -91 -90.023 --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Invalid latitude");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Invalid latitude");
result = await rootCommand.InvokeAsync("fixed-position 91 -90.023 --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Invalid latitude");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Invalid latitude");
}

[Test]
public async Task FixedPositionCommand_Should_Fail_ForInvalidLon()
{
var result = await rootCommand.InvokeAsync("fixed-position 34.00 -181 --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Invalid longitude");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Invalid longitude");
result = await rootCommand.InvokeAsync("fixed-position 34.00 -181 --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Invalid longitude");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Invalid longitude");
}

[Test]
public async Task FixedPositionCommand_Should_Succeed_ForValidCoords()
{
var result = await rootCommand.InvokeAsync("fixed-position 34.00 -90 --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
6 changes: 3 additions & 3 deletions Meshtastic.Test/Commands/GetCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public void Setup()
public async Task SetCommand_Should_Fail_ForEmptyOrNullSettings()
{
var result = await rootCommand.InvokeAsync("get --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Option '--setting' is required");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Option '--setting' is required");
}

[Test]
public async Task GetCommand_Should_Succeed_ForValidSetting()
{
var result = await rootCommand.InvokeAsync("get --setting Mqtt.Address --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
2 changes: 1 addition & 1 deletion Meshtastic.Test/Commands/InfoCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void Setup()
public async Task InfoCommand_Should_Succeed_ForValidCoords()
{
var result = await rootCommand.InvokeAsync("info --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
2 changes: 1 addition & 1 deletion Meshtastic.Test/Commands/ListCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void Setup()
public async Task ListCommand_Should_Succeed_ForValidCoords()
{
var result = await rootCommand.InvokeAsync("list --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
2 changes: 1 addition & 1 deletion Meshtastic.Test/Commands/MetadataCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void Setup()
public async Task MetadataCommand_Should_Succeed_ForValidArgs()
{
var result = await rootCommand.InvokeAsync("metadata --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
2 changes: 1 addition & 1 deletion Meshtastic.Test/Commands/RebootCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void Setup()
public async Task RebootCommand_Should_Succeed_ForValidArgs()
{
var result = await rootCommand.InvokeAsync("reboot --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
2 changes: 1 addition & 1 deletion Meshtastic.Test/Commands/ResetNodeDbCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public void Setup()
public async Task ResetNodeDbCommand_Should_Succeed_ForValidArgs()
{
var result = await rootCommand.InvokeAsync("reset-nodedb --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
8 changes: 4 additions & 4 deletions Meshtastic.Test/Commands/SendInputEventCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public void Setup()
public async Task SendInputEventCommand_Should_Fail_ForMissingEventCode()
{
var result = await rootCommand.InvokeAsync("input-event --port SIMPORT", Console);
result.Should().BeGreaterThan(0);
Out.Output.Should().Contain("Required argument missing for command: 'input-event'");
result.ShouldBeGreaterThan(0);
Out.Output.ShouldContain("Required argument missing for command: 'input-event'");
}

[Test]
public async Task SendInputEventCommand_Should_Succeed_ForValidEventCode()
{
var result = await rootCommand.InvokeAsync("input-event 1 --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}

[Test]
public async Task SendInputEventCommand_Should_Succeed_WithAllOptions()
{
var result = await rootCommand.InvokeAsync("input-event 1 --kb-char 65 --touch-x 100 --touch-y 200 --port SIMPORT", Console);
result.Should().Be(0);
result.ShouldBe(0);
}
}
Loading