Skip to content
Merged
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
2 changes: 1 addition & 1 deletion AntPlus.Extensions.Hosting/Hosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PackageReleaseNotes>
<IncludeSymbols>True</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<VersionPrefix>2.0.5</VersionPrefix>
<VersionPrefix>2.0.6</VersionPrefix>
<PackageProjectUrl>https://stephenhidem.github.io/AntPlus</PackageProjectUrl>
<RepositoryUrl>https://github.com/StephenHidem/AntPlus</RepositoryUrl>
<Configurations>Debug;Release</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion AntPlus.UnitTests/AntPlus.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
49 changes: 27 additions & 22 deletions AntPlus.UnitTests/CommonDataPagesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public void ParseCommandStatusPage_PropertiesCorrect()
// Arrange
byte[] dataPage = [0x47, 0xFF, 0xFE, 0x04, 0x11, 0x22, 0x33, 0x44];
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
Assert.Equal(0xFF, _commonDataPages.CommandStatus.LastCommandReceived);
Assert.Equal(254, _commonDataPages.CommandStatus.SequenceNumber);
Assert.Equal(CommonDataPages.CommandResult.Pending, _commonDataPages.CommandStatus.Status);
Expand All @@ -40,8 +41,9 @@ public void ParseManufacturerInfoPage_PropertiesCorrect()
// Arrange
byte[] dataPage = [0x50, 0xFF, 0xFF, 0x01, 0x0F, 0x00, 0x85, 0x83];
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
Assert.Equal(0xFF, _commonDataPages.ManufacturerInfo.ComponentId);
Assert.Equal(1, _commonDataPages.ManufacturerInfo.HardwareRevision);
Assert.Equal(15, _commonDataPages.ManufacturerInfo.ManufacturerId);
Expand All @@ -54,8 +56,9 @@ public void ParseMultiComponentManufacturerInfoPage_PropertiesCorrect()
// Arrange
byte[] dataPage = [0x4E, 0xFF, 0x22, 0x01, 0x0F, 0x00, 0x85, 0x83];
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
Assert.Equal(0x22, _commonDataPages.ManufacturerInfo.ComponentId);
Assert.Equal(1, _commonDataPages.ManufacturerInfo.HardwareRevision);
Assert.Equal(15, _commonDataPages.ManufacturerInfo.ManufacturerId);
Expand All @@ -70,10 +73,11 @@ public void ParseProductInfoPage_PropertiesCorrect(byte[] dataPage, string versi
// Act
var currentCulture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = new CultureInfo("ru-RU");
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
CultureInfo.CurrentCulture = currentCulture;

// Assert
Assert.True(result);
Assert.Equal(0xFF, _commonDataPages.ProductInfo.ComponentId);
Assert.Equal(serialNumber, _commonDataPages.ProductInfo.SerialNumber);
Assert.True(_commonDataPages.ProductInfo.SoftwareRevision == Version.Parse(version));
Expand All @@ -85,8 +89,9 @@ public void ParseMultiComponentProductInfoPage_PropertiesCorrect()
// Arrange
byte[] dataPage = [0x4F, 0x22, 0xFF, 12, 5, 6, 7, 8];
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
Assert.Equal(0x22, _commonDataPages.ProductInfo.ComponentId);
Assert.Equal((uint)0x08070605, _commonDataPages.ProductInfo.SerialNumber);
Assert.True(_commonDataPages.ProductInfo.SoftwareRevision == Version.Parse("1.200"));
Expand All @@ -106,8 +111,9 @@ public void ParseBatteryStatusPage_PropertiesCorrect(byte[] dataPage,
BatteryStatus batteryStatus, double voltage, byte count, byte id, uint operatingTimeInSeconds)
{
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
Assert.Equal(batteryStatus, _commonDataPages.BatteryStatus.Status);
Assert.Equal(voltage, _commonDataPages.BatteryStatus.BatteryVoltage, 0.001);
Assert.Equal(count, _commonDataPages.BatteryStatus.NumberOfBatteries);
Expand All @@ -121,8 +127,9 @@ public void ParseTimeAndDatePage_PropertiesCorrect()
// Arrange
byte[] dataPage = [0x53, 0xFF, 0x0D, 0x1B, 0x11, 0x92, 0x06, 0x09];
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
Assert.Equal(DateTime.Parse("06/18/2009 17:27:13", DateTimeFormatInfo.InvariantInfo), _commonDataPages.TimeAndDate);
}

Expand Down Expand Up @@ -157,8 +164,9 @@ public void ParseSubfieldDataPage_PropertiesCorrect(byte[] dataPage,
double subPage1Value, double subPage2Value)
{
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
Assert.Equal(subPage1, _commonDataPages.SubfieldData.Subpage1);
Assert.Equal(subPage1Value, _commonDataPages.SubfieldData.ComputedDataField1, 0.01);
Assert.Equal(subPage2, _commonDataPages.SubfieldData.Subpage2);
Expand All @@ -171,8 +179,9 @@ public void ParseSubfieldDataPage_PropertiesCorrect(byte[] dataPage,
public void ParseSubfieldDataPage_InvalidSubPage_LogsError(byte[] dataPage)
{
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
_mockLogger.Verify(
x => x.Log(
LogLevel.Warning,
Expand All @@ -193,8 +202,9 @@ public void ParseSubfieldDataPage_InvalidSubPage_LogsError(byte[] dataPage)
public void ParseMemoryLevelPage_PropertiesCorrect(byte[] dataPage, CommonDataPages.MemorySizeUnit sizeUnit)
{
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
Assert.Equal(55.0, _commonDataPages.MemoryLevel.PercentUsed, 0.5);
Assert.Equal(3276.8, _commonDataPages.MemoryLevel.TotalSize, 0.1);
Assert.Equal(sizeUnit, _commonDataPages.MemoryLevel.TotalSizeUnit);
Expand All @@ -206,8 +216,9 @@ public void ParsePairedDevicesPage_LogsWarning()
// Arrange
byte[] dataPage = [0x56, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
_mockLogger.Verify(
x => x.Log(
LogLevel.Warning,
Expand All @@ -224,30 +235,24 @@ public void ParsePairedDevicesPage_LogsWarning()
public void ParseErrorDescriptionPage_PropertiesCorrect(byte[] dataPage, CommonDataPages.ErrorLevel errorLevel)
{
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
Assert.True(result);
Assert.Equal(errorLevel, _commonDataPages.ErrorDescription.ErrorLevel);
Assert.Equal(0xF, _commonDataPages.ErrorDescription.SystemComponentIndex);
Assert.Equal(0xFF, _commonDataPages.ErrorDescription.ProfileSpecificErrorCode);
Assert.Equal<uint>(0x11223344, _commonDataPages.ErrorDescription.ManufacturerSpecificErrorCode);
}

[Fact]
public void ParseUnknownDataPage_LogsWarning()
public void ParseUnknownDataPage_ReturnsFalse()
{
// Arrange
byte[] dataPage = [0x58, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
// Act
_commonDataPages.ParseCommonDataPage(dataPage);
bool result = _commonDataPages.ParseCommonDataPage(dataPage);
// Assert
_mockLogger.Verify(
x => x.Log(
LogLevel.Warning,
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Unknown data page")),
null,
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
Assert.False(result);
}

[Fact]
Expand Down
26 changes: 26 additions & 0 deletions AntPlus.UnitTests/DeviceProfiles/AssetTracker/AssetTrackerTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Microsoft.Extensions.Logging;
using Moq;
using SmallEarthTech.AntPlus.DeviceProfiles.AssetTracker;
using SmallEarthTech.AntPlus.DeviceProfiles.BicyclePower;
using SmallEarthTech.AntRadioInterface;
using System;
using System.Collections.Generic;
using Xunit;

Expand All @@ -17,6 +19,7 @@ public AssetTrackerTests()
{
_mockAntChannel = new Mock<IAntChannel> { CallBase = true };
_mockLogger = new Mock<ILogger<Tracker>>();
_mockLogger.Setup(l => l.IsEnabled(It.IsAny<LogLevel>())).Returns(true);
_tracker = new Tracker(new ChannelId(0), _mockAntChannel.Object, _mockLogger.Object, It.IsAny<int>());
}

Expand Down Expand Up @@ -162,5 +165,28 @@ public void Parse_Disconnected_IsDisconnected()
// Assert
Assert.True(_tracker.Disconnected);
}

[Fact]
public void Parse_UnknownDataPage_RaisedUnknownDataPageEvent()
{
// Arrange
byte[] dataPage = [0xFF, 0, 0, 0, 0, 0, 0, 0];
byte[] receivedData = null;
_tracker.UnknownDataPageReceived += (s, d) => receivedData = d;

// Act
_tracker.Parse(dataPage);

// Assert
Assert.Equal(dataPage, receivedData);
_mockLogger.Verify(
x => x.Log(
LogLevel.Warning,
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Unknown data page")),
null,
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ public void ParseMainDataPage_ExpectedValues()
Assert.Equal(0.628, _crankTorqueFrequencySensor.Power, 0.0005);
}

[Fact]
public void ParseUnknownDataPage_CallsOnUnknownDataPageReceived()
{
// Arrange
byte[] dataPage = [0xFF, 0, 0, 0, 0, 0, 0, 0];
byte[] receivedData = null;
_crankTorqueFrequencySensor.UnknownDataPageReceived += (s, d) => receivedData = d;

// Act
_crankTorqueFrequencySensor.Parse(dataPage);

// Assert
Assert.Equal(dataPage, receivedData);
_mockLogger.Verify(
x => x.Log(
LogLevel.Warning,
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Unknown data page")),
null,
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
}

[Fact]
public async Task SaveSlopeToFlash_MessageFormatCorrect()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using SmallEarthTech.AntPlus.DeviceProfiles.AssetTracker;
using SmallEarthTech.AntPlus.DeviceProfiles.BicyclePower;
using SmallEarthTech.AntRadioInterface;
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using SmallEarthTech.AntPlus.DeviceProfiles.AssetTracker;
using SmallEarthTech.AntPlus.DeviceProfiles.BicyclePower;
using SmallEarthTech.AntRadioInterface;
using Xunit;
Expand Down Expand Up @@ -73,5 +74,20 @@ public void Parse_AveragePower_ExpectedAvgPower()
// Assert
Assert.Equal(8721, _standardPowerSensor.AveragePower);
}

[Fact]
public void Parse_UnknownDataPage_RaisedUnknownDataPageEvent()
{
// Arrange
byte[] dataPage = [0xFF, 0, 0, 0, 0, 0, 0, 0];
byte[] receivedData = null;
_standardPowerSensor.UnknownDataPageReceived += (s, d) => receivedData = d;

// Act
_standardPowerSensor.Parse(dataPage);

// Assert
Assert.Equal(dataPage, receivedData);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using Moq;
using SmallEarthTech.AntPlus.DeviceProfiles.BicyclePower;
using SmallEarthTech.AntPlus.DeviceProfiles.BikeSpeedAndCadence;
using SmallEarthTech.AntRadioInterface;
using Xunit;
Expand Down Expand Up @@ -30,5 +31,20 @@ public void Parse_Cadence_ExpectedCadence()
// Assert
Assert.Equal(120, _sensor.InstantaneousCadence);
}

[Fact]
public void Parse_UnknownDataPage_RaisedUnknownDataPageEvent()
{
// Arrange
byte[] dataPage = [0xFF, 0, 0, 0, 0, 0, 0, 0];
byte[] receivedData = null;
_sensor.UnknownDataPageReceived += (s, d) => receivedData = d;

// Act
_sensor.Parse(dataPage);

// Assert
Assert.Equal(dataPage, receivedData);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using Moq;
using SmallEarthTech.AntPlus.DeviceProfiles.BicyclePower;
using SmallEarthTech.AntPlus.DeviceProfiles.BikeSpeedAndCadence;
using SmallEarthTech.AntRadioInterface;
using Xunit;
Expand Down Expand Up @@ -31,5 +32,20 @@ public void Parse_SpeedAndDistance_ExpectedSpeedAndDistance()
Assert.Equal(11, _sensor.InstantaneousSpeed);
Assert.Equal(11, _sensor.AccumulatedDistance);
}

[Fact]
public void Parse_UnknownDataPage_RaisedUnknownDataPageEvent()
{
// Arrange
byte[] dataPage = [0xFF, 0, 0, 0, 0, 0, 0, 0];
byte[] receivedData = null;
_sensor.UnknownDataPageReceived += (s, d) => receivedData = d;

// Act
_sensor.Parse(dataPage);

// Assert
Assert.Equal(dataPage, receivedData);
}
}
}
16 changes: 16 additions & 0 deletions AntPlus.UnitTests/DeviceProfiles/FitnessEquipment/ClimberTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging;
using Moq;
using SmallEarthTech.AntPlus.DeviceProfiles.BicyclePower;
using SmallEarthTech.AntPlus.DeviceProfiles.FitnessEquipment;
using SmallEarthTech.AntRadioInterface;
using Xunit;
Expand Down Expand Up @@ -58,5 +59,20 @@ public void Parse_StrideCyclesRollover_MatchesExpectedValue()
// Assert
Assert.Equal(20, _climber.StrideCycles);
}

[Fact]
public void Parse_UnknownDataPage_RaisedUnknownDataPageEvent()
{
// Arrange
byte[] dataPage = [0xFF, 0, 0, 0, 0, 0, 0, 0];
byte[] receivedData = null;
_climber.UnknownDataPageReceived += (s, d) => receivedData = d;

// Act
_climber.Parse(dataPage);

// Assert
Assert.Equal(dataPage, receivedData);
}
}
}
Loading