Skip to content

Commit acb1f1a

Browse files
committed
Fix null reference issues and spelling.
1 parent eecf892 commit acb1f1a

22 files changed

+299
-288
lines changed

AntPlus.UnitTests/AntDeviceTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace SmallEarthTech.AntPlus.UnitTests
99
[TestClass]
1010
public class AntDeviceTests
1111
{
12-
private MockRepository? mockRepository;
12+
private MockRepository mockRepository;
1313

14-
private Mock<IAntChannel>? mockAntChannel;
15-
private Mock<ILogger<Tracker>>? mockLogger;
14+
private Mock<IAntChannel> mockAntChannel;
15+
private Mock<ILogger<Tracker>> mockLogger;
1616

1717
[TestInitialize]
1818
public void TestInitialize()
@@ -32,7 +32,7 @@ public void Ctor_ChannelID_VerifyDeviceNumber(uint channelId, uint expectedDevic
3232
ChannelId cid = new((uint)channelId);
3333

3434
// Act
35-
Mock<AntDevice> antDevice = new(cid, mockAntChannel?.Object, mockLogger?.Object, 500);
35+
Mock<AntDevice> antDevice = new(cid, mockAntChannel.Object, mockLogger.Object, 500);
3636

3737
// Assert
3838
Assert.AreEqual((uint)expectedDeviceNumber, antDevice.Object.ChannelId.DeviceNumber);
@@ -47,7 +47,7 @@ public void Ctor_ChannelID_VerifyDeviceType(uint channelId, byte expectedDeviceT
4747
ChannelId cid = new((uint)channelId);
4848

4949
// Act
50-
Mock<AntDevice> antDevice = new(cid, mockAntChannel?.Object, mockLogger?.Object, 500);
50+
Mock<AntDevice> antDevice = new(cid, mockAntChannel.Object, mockLogger.Object, 500);
5151

5252
// Assert
5353
Assert.AreEqual(expectedDeviceType, antDevice.Object.ChannelId.DeviceType);
@@ -62,7 +62,7 @@ public void Ctor_ChannelID_VerifyPairingBit(uint channelId, bool expectedResult)
6262
ChannelId cid = new((uint)channelId);
6363

6464
// Act
65-
Mock<AntDevice> antDevice = new(cid, mockAntChannel?.Object, mockLogger?.Object, 500);
65+
Mock<AntDevice> antDevice = new(cid, mockAntChannel.Object, mockLogger.Object, 500);
6666

6767
// Assert
6868
Assert.AreEqual(expectedResult, antDevice.Object.ChannelId.IsPairingBitSet);
@@ -77,7 +77,7 @@ public void Ctor_ChannelID_VerifyAreGlobalPageUsed(uint channelId, bool expected
7777
ChannelId cid = new((uint)channelId);
7878

7979
// Act
80-
Mock<AntDevice> antDevice = new(cid, mockAntChannel?.Object, mockLogger?.Object, 500);
80+
Mock<AntDevice> antDevice = new(cid, mockAntChannel.Object, mockLogger.Object, 500);
8181

8282
// Assert
8383
Assert.AreEqual(expectedResult, antDevice.Object.ChannelId.AreGlobalDataPagesUsed);
@@ -98,7 +98,7 @@ public void Ctor_ChannelID_VerifyTransmissionType(uint channelId, ChannelSharing
9898
ChannelId cid = new((uint)channelId);
9999

100100
// Act
101-
Mock<AntDevice> antDevice = new(cid, mockAntChannel?.Object, mockLogger?.Object, 500);
101+
Mock<AntDevice> antDevice = new(cid, mockAntChannel.Object, mockLogger.Object, 500);
102102

103103
// Assert
104104
Assert.AreEqual(expectedTransmissionType, antDevice.Object.ChannelId.TransmissionType);
@@ -110,7 +110,7 @@ public void Timeout_Offline_ExpectedEventAndStatus()
110110
// Arrange
111111
bool offline = false;
112112
ChannelId cid = new(0);
113-
Mock<AntDevice> antDevice = new(cid, mockAntChannel?.Object, mockLogger?.Object, 50);
113+
Mock<AntDevice> antDevice = new(cid, mockAntChannel.Object, mockLogger.Object, 50);
114114
antDevice.Object.DeviceWentOffline += (sender, e) => { offline = antDevice.Object.Offline; };
115115

116116
// Act

AntPlus.UnitTests/AntPlus.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
5-
<Nullable>enable</Nullable>
5+
<Nullable>disable</Nullable>
66

77
<IsPackable>false</IsPackable>
88
</PropertyGroup>

AntPlus.UnitTests/DeviceProfiles/AssetTracker/AssetTrackerTests.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ namespace AntPlus.UnitTests.DeviceProfiles.AssetTracker
99
[TestClass]
1010
public class AssetTrackerTests
1111
{
12-
private MockRepository? mockRepository;
12+
private MockRepository mockRepository;
1313

1414
private readonly ChannelId mockChannelId = new(0);
15-
private Mock<IAntChannel>? mockAntChannel;
16-
private Mock<ILogger<Tracker>>? mockLogger;
15+
private Mock<IAntChannel> mockAntChannel;
16+
private Mock<ILogger<Tracker>> mockLogger;
1717

1818
[TestInitialize]
1919
public void TestInitialize()
@@ -28,26 +28,26 @@ private Tracker CreateAssetTracker()
2828
{
2929
return new Tracker(
3030
mockChannelId,
31-
mockAntChannel?.Object,
32-
mockLogger?.Object);
31+
mockAntChannel.Object,
32+
mockLogger.Object);
3333
}
3434

3535
[TestMethod]
3636
public void Parse_OutOfOrderDataPages_ExpectedAssetProperties()
3737
{
3838
// Arrange
39-
mockAntChannel?.Setup(ac =>
39+
mockAntChannel.Setup(ac =>
4040
ac.SendExtAcknowledgedData(mockChannelId, It.IsAny<byte[]>(), It.IsAny<uint>()).Result).
4141
Returns(MessagingReturnCode.Pass);
42-
List<byte[]>? dataPages = new() {
42+
List<byte[]> dataPages = new() {
4343
new byte[] { 1, 0xE1, 20, 0, 128, 0, 0x00, 0x00 },
4444
new byte[] { 2, 0xE1, 0x00, 0x20, 0xDE, 0xDD, 0xDD, 0xBD },
4545
new byte[] { 16, 0xE1, 128, (byte)'C', (byte)'a', (byte)'r', (byte)'l', (byte)'o' },
4646
new byte[] { 17, 0xE1, 0, (byte)'s', (byte)' ', (byte)'C', (byte)'a', (byte)'t' }
4747
};
4848

4949
// Act
50-
for (int? i = 0; i < 32; i++)
50+
for (int i = 0; i < 32; i++)
5151
{
5252
var tracker = CreateAssetTracker();
5353

@@ -69,7 +69,7 @@ public void Parse_OutOfOrderDataPages_ExpectedAssetProperties()
6969
Assert.AreEqual(128, tracker.Assets[0].Color);
7070
Assert.AreEqual("Carlos Cat", tracker.Assets[0].Name);
7171
Assert.AreEqual(Asset.AssetType.AssetTracker, tracker.Assets[0].Type);
72-
mockRepository?.VerifyAll();
72+
mockRepository.VerifyAll();
7373
}
7474
}
7575

@@ -83,10 +83,10 @@ public void Parse_OutOfOrderDataPages_ExpectedAssetProperties()
8383
public void Parse_AssetSituation_ExpectedSituation(int situation, Asset.AssetSituation expSituation)
8484
{
8585
// Arrange
86-
mockAntChannel?.Setup(ac =>
86+
mockAntChannel.Setup(ac =>
8787
ac.SendExtAcknowledgedData(mockChannelId, It.IsAny<byte[]>(), It.IsAny<uint>()).Result).
8888
Returns(MessagingReturnCode.Pass);
89-
byte[]? dataPage = new byte[8];
89+
byte[] dataPage = new byte[8];
9090
dataPage[0] = 1;
9191
dataPage[5] = (byte)situation;
9292
var tracker = CreateAssetTracker();
@@ -107,10 +107,10 @@ public void Parse_AssetSituation_ExpectedSituation(int situation, Asset.AssetSit
107107
public void Parse_AssetStatus_ExpectedStatus(int status, Asset.AssetStatus expStatus)
108108
{
109109
// Arrange
110-
mockAntChannel?.Setup(ac =>
110+
mockAntChannel.Setup(ac =>
111111
ac.SendExtAcknowledgedData(mockChannelId, It.IsAny<byte[]>(), It.IsAny<uint>()).Result).
112112
Returns(MessagingReturnCode.Pass);
113-
byte[]? dataPage = new byte[8];
113+
byte[] dataPage = new byte[8];
114114
dataPage[0] = 1;
115115
dataPage[5] = (byte)status;
116116
var tracker = CreateAssetTracker();
@@ -126,10 +126,10 @@ public void Parse_AssetStatus_ExpectedStatus(int status, Asset.AssetStatus expSt
126126
public void Parse_NoAssets_ExpectedAssetCountIsZero()
127127
{
128128
// Arrange
129-
mockAntChannel?.Setup(ac =>
129+
mockAntChannel.Setup(ac =>
130130
ac.SendExtAcknowledgedData(mockChannelId, It.IsAny<byte[]>(), It.IsAny<uint>()).Result).
131131
Returns(MessagingReturnCode.Pass);
132-
byte[]? dataPage = new byte[8];
132+
byte[] dataPage = new byte[8];
133133
dataPage[0] = 1;
134134
var tracker = CreateAssetTracker();
135135
tracker.Parse(dataPage);
@@ -146,10 +146,10 @@ public void Parse_NoAssets_ExpectedAssetCountIsZero()
146146
public void Parse_Disconnected_IsDisconnected()
147147
{
148148
// Arrange
149-
mockAntChannel?.Setup(ac =>
149+
mockAntChannel.Setup(ac =>
150150
ac.SendExtAcknowledgedData(mockChannelId, It.IsAny<byte[]>(), It.IsAny<uint>()).Result).
151151
Returns(MessagingReturnCode.Pass);
152-
byte[]? dataPage = new byte[8];
152+
byte[] dataPage = new byte[8];
153153
dataPage[0] = 1;
154154
var tracker = CreateAssetTracker();
155155
tracker.Parse(dataPage);

AntPlus.UnitTests/DeviceProfiles/BicyclePower/BicyclePowerTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ namespace AntPlus.UnitTests.DeviceProfiles.BicyclePower
88
[TestClass]
99
public class BicyclePowerTests
1010
{
11-
private MockRepository? mockRepository;
11+
private MockRepository mockRepository;
1212

1313
private readonly ChannelId mockChannelId = new(0);
14-
private Mock<IAntChannel>? mockAntChannel;
15-
private Mock<ILogger<Bicycle>>? mockLogger;
14+
private Mock<IAntChannel> mockAntChannel;
15+
private Mock<ILogger<Bicycle>> mockLogger;
1616

1717
[TestInitialize]
1818
public void TestInitialize()
@@ -27,8 +27,8 @@ private Bicycle CreateBicyclePower()
2727
{
2828
return new Bicycle(
2929
mockChannelId,
30-
mockAntChannel?.Object,
31-
mockLogger?.Object);
30+
mockAntChannel.Object,
31+
mockLogger.Object);
3232
}
3333

3434
[TestMethod]

AntPlus.UnitTests/DeviceProfiles/BicyclePower/CalibrationTests.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ namespace AntPlus.UnitTests.DeviceProfiles.BicyclePower
1212
[TestClass]
1313
public class CalibrationTests
1414
{
15-
private MockRepository? mockRepository;
15+
private MockRepository mockRepository;
1616

17-
private Bicycle? mockBicycle;
17+
private Bicycle mockBicycle;
1818
private readonly ChannelId mockChannelId = new(0);
19-
private Mock<IAntChannel>? mockAntChannel;
20-
private Mock<ILogger<Bicycle>>? mockLogger;
19+
private Mock<IAntChannel> mockAntChannel;
20+
private Mock<ILogger<Bicycle>> mockLogger;
2121

2222
[TestInitialize]
2323
public void TestInitialize()
@@ -32,8 +32,8 @@ private Bicycle CreateBicyclePower()
3232
{
3333
return new Bicycle(
3434
mockChannelId,
35-
mockAntChannel?.Object,
36-
mockLogger?.Object);
35+
mockAntChannel.Object,
36+
mockLogger.Object);
3737
}
3838

3939
private Calibration CreateCalibration()
@@ -54,7 +54,7 @@ public void Parse_AutoZeroSupport_ExpectedAutoZeroSupport(int config, bool suppo
5454
byte[] dataPage = new byte[8] { 0x01, 0x12, (byte)config, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5555

5656
// Act
57-
mockBicycle?.Parse(
57+
mockBicycle.Parse(
5858
dataPage);
5959

6060
// Assert
@@ -75,7 +75,7 @@ public void Parse_GeneralCalibrationResponse_ExpectedResponse(byte[] dataPage, C
7575
var calibration = CreateCalibration();
7676

7777
// Act
78-
mockBicycle?.Parse(
78+
mockBicycle.Parse(
7979
dataPage);
8080

8181
// Assert
@@ -94,7 +94,7 @@ public void Parse_CustomCalibration_ExpectedCustomParameters(int calID)
9494
byte[] dataPage = new byte[8] { 1, (byte)calID, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
9595

9696
// Act
97-
mockBicycle?.Parse(
97+
mockBicycle.Parse(
9898
dataPage);
9999

100100
// Assert
@@ -114,7 +114,7 @@ public void Parse_MeasurementOutputData_ExpectedDataType(int val, MeasurementOut
114114
byte[] dataPage = new byte[8] { 3, 0x00, (byte)val, 0x00, 0x00, 0x00, 0x00, 0x00 };
115115

116116
// Act
117-
mockBicycle?.Parse(
117+
mockBicycle.Parse(
118118
dataPage);
119119

120120
// Assert
@@ -126,21 +126,21 @@ public void Parse_MeasurementOutputData_ExpectedDataType(int val, MeasurementOut
126126
[DataRow(sbyte.MaxValue, short.MaxValue)]
127127
[DataRow(sbyte.MinValue, short.MinValue)]
128128
[DataRow(sbyte.MaxValue, short.MinValue)]
129-
public void Parse_MeasurementOutputData_ExpectedScaledMeasurement(int scale, int meas)
129+
public void Parse_MeasurementOutputData_ExpectedScaledMeasurement(int scale, int measurement)
130130
{
131131
// Arrange
132132
var calibration = CreateCalibration();
133133
byte[] dataPage = new byte[8] { 3, 0x00, 0x00, (byte)scale, 0x00, 0x00, 0x00, 0x00 };
134-
dataPage[6] = BitConverter.GetBytes((short)meas)[0];
135-
dataPage[7] = BitConverter.GetBytes((short)meas)[1];
136-
double expMeas = meas * Math.Pow(2, scale);
134+
dataPage[6] = BitConverter.GetBytes((short)measurement)[0];
135+
dataPage[7] = BitConverter.GetBytes((short)measurement)[1];
136+
double expMeasurement = measurement * Math.Pow(2, scale);
137137

138138
// Act
139-
mockBicycle?.Parse(
139+
mockBicycle.Parse(
140140
dataPage);
141141

142142
// Assert
143-
Assert.AreEqual(expMeas, calibration.Measurements[0].Measurement);
143+
Assert.AreEqual(expMeasurement, calibration.Measurements[0].Measurement);
144144
}
145145

146146
[TestMethod]
@@ -156,7 +156,7 @@ public void Parse_MeasurementOutputData_ExpectedTimestamp(int timeStamp, double
156156
dataPage[5] = BitConverter.GetBytes((ushort)timeStamp)[1];
157157

158158
// Act
159-
mockBicycle?.Parse(
159+
mockBicycle.Parse(
160160
dataPage);
161161

162162
// Assert
@@ -168,7 +168,7 @@ public async Task RequestManualCalibration_Request_ExpectedMessage()
168168
{
169169
// Arrange
170170
var calibration = CreateCalibration();
171-
mockAntChannel?.Setup(ac => ac.SendExtAcknowledgedData(mockChannelId, new byte[] { 0x01, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
171+
mockAntChannel.Setup(ac => ac.SendExtAcknowledgedData(mockChannelId, new byte[] { 0x01, 0xAA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
172172
It.IsAny<uint>()).Result)
173173
.Returns(MessagingReturnCode.Pass);
174174

@@ -178,7 +178,7 @@ public async Task RequestManualCalibration_Request_ExpectedMessage()
178178
// Assert
179179
Assert.AreEqual(MessagingReturnCode.Pass, result);
180180
Assert.AreEqual(CalibrationResponse.InProgress, calibration.CalibrationStatus);
181-
mockRepository?.VerifyAll();
181+
mockRepository.VerifyAll();
182182
}
183183

184184
[TestMethod]
@@ -189,7 +189,7 @@ public async Task SetAutoZeroConfiguration_StateUnderTest_ExpectedBehavior(AutoZ
189189
{
190190
// Arrange
191191
var calibration = CreateCalibration();
192-
mockAntChannel?.Setup(ac => ac.SendExtAcknowledgedData(mockChannelId, new byte[] { 0x01, 0xAB, (byte)autoZero, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
192+
mockAntChannel.Setup(ac => ac.SendExtAcknowledgedData(mockChannelId, new byte[] { 0x01, 0xAB, (byte)autoZero, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
193193
It.IsAny<uint>()).Result)
194194
.Returns(MessagingReturnCode.Pass);
195195

@@ -200,15 +200,15 @@ public async Task SetAutoZeroConfiguration_StateUnderTest_ExpectedBehavior(AutoZ
200200
// Assert
201201
Assert.AreEqual(MessagingReturnCode.Pass, result);
202202
Assert.AreEqual(CalibrationResponse.Unknown, calibration.CalibrationStatus);
203-
mockRepository?.VerifyAll();
203+
mockRepository.VerifyAll();
204204
}
205205

206206
[TestMethod]
207207
public async Task RequestCustomParameters_Request_ExpectedMessage()
208208
{
209209
// Arrange
210210
var calibration = CreateCalibration();
211-
mockAntChannel?.Setup(ac => ac.SendExtAcknowledgedData(mockChannelId, new byte[] { 0x01, 0xBA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
211+
mockAntChannel.Setup(ac => ac.SendExtAcknowledgedData(mockChannelId, new byte[] { 0x01, 0xBA, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
212212
It.IsAny<uint>()).Result)
213213
.Returns(MessagingReturnCode.Pass);
214214

@@ -218,7 +218,7 @@ public async Task RequestCustomParameters_Request_ExpectedMessage()
218218
// Assert
219219
Assert.AreEqual(MessagingReturnCode.Pass, result);
220220
Assert.AreEqual(CalibrationResponse.InProgress, calibration.CalibrationStatus);
221-
mockRepository?.VerifyAll();
221+
mockRepository.VerifyAll();
222222
}
223223

224224
[TestMethod]
@@ -227,7 +227,7 @@ public async Task SetCustomParameters_Parameters_ExpectedMessage()
227227
// Arrange
228228
var calibration = CreateCalibration();
229229
byte[] customParameters = new byte[] { 0x01, 0xBC, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
230-
mockAntChannel?.Setup(ac => ac.SendExtAcknowledgedData(mockChannelId, customParameters,
230+
mockAntChannel.Setup(ac => ac.SendExtAcknowledgedData(mockChannelId, customParameters,
231231
It.IsAny<uint>()).Result)
232232
.Returns(MessagingReturnCode.Pass);
233233

@@ -238,7 +238,7 @@ public async Task SetCustomParameters_Parameters_ExpectedMessage()
238238
// Assert
239239
Assert.AreEqual(MessagingReturnCode.Pass, result);
240240
Assert.AreEqual(CalibrationResponse.InProgress, calibration.CalibrationStatus);
241-
mockRepository?.VerifyAll();
241+
mockRepository.VerifyAll();
242242
}
243243
}
244244
}

0 commit comments

Comments
 (0)