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
4 changes: 2 additions & 2 deletions src/Daqifi.Core.Tests/Channel/AnalogChannelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void SetActiveSample_RaisesSampleReceivedEvent()
}

[Fact]
public void SetActiveSample_IsThreadSafe()
public async Task SetActiveSample_IsThreadSafe()
{
// Arrange
var channel = new AnalogChannel(0);
Expand All @@ -153,7 +153,7 @@ public void SetActiveSample_IsThreadSafe()
tasks.Add(Task.Run(() => channel.SetActiveSample(value, DateTime.UtcNow)));
}

Task.WaitAll(tasks.ToArray());
await Task.WhenAll(tasks.ToArray());

// Assert
Assert.NotNull(channel.ActiveSample);
Expand Down
4 changes: 2 additions & 2 deletions src/Daqifi.Core.Tests/Channel/DigitalChannelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void SetActiveSample_RaisesSampleReceivedEvent()
}

[Fact]
public void SetActiveSample_IsThreadSafe()
public async Task SetActiveSample_IsThreadSafe()
{
// Arrange
var channel = new DigitalChannel(0);
Expand All @@ -133,7 +133,7 @@ public void SetActiveSample_IsThreadSafe()
tasks.Add(Task.Run(() => channel.SetActiveSample(value, DateTime.UtcNow)));
}

Task.WaitAll(tasks.ToArray());
await Task.WhenAll(tasks.ToArray());

// Assert
Assert.NotNull(channel.ActiveSample);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace Daqifi.Core.Tests.Communication.Transport;

Expand Down Expand Up @@ -188,11 +189,11 @@ await Assert.ThrowsAsync<InvalidOperationException>(
}

[Fact]
public void Dispose_ShouldCloseTransport()
public async Task Dispose_ShouldCloseTransport()
{
// Arrange
var transport = new UdpTransport(0);
transport.OpenAsync().Wait();
await transport.OpenAsync();

// Act
transport.Dispose();
Expand All @@ -202,15 +203,15 @@ public void Dispose_ShouldCloseTransport()
}

[Fact]
public void ConnectionInfo_ShouldReflectStatus()
public async Task ConnectionInfo_ShouldReflectStatus()
{
// Arrange - use dynamic port to avoid conflicts in parallel test runs
using var transport = new UdpTransport(0);

// Act & Assert
Assert.Contains("Closed", transport.ConnectionInfo);

transport.OpenAsync().Wait();
await transport.OpenAsync();
Assert.Contains("Open", transport.ConnectionInfo);
}
}
2 changes: 1 addition & 1 deletion src/Daqifi.Core.Tests/Device/DeviceTypeDetectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void DetectFromPartNumber_ValidPartNumber_ReturnsCorrectType(string partN
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void DetectFromPartNumber_EmptyOrNull_ReturnsUnknown(string partNumber)
public void DetectFromPartNumber_EmptyOrNull_ReturnsUnknown(string? partNumber)
{
// Act
var result = DeviceTypeDetector.DetectFromPartNumber(partNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public void CanHandle_WithNonProtobufMessage_ReturnsFalse()
}

[Fact]
public async void HandleAsync_WithStatusMessage_CallsStatusHandler()
public async Task HandleAsync_WithStatusMessage_CallsStatusHandler()
{
// Arrange
var statusHandlerCalled = false;
DaqifiOutMessage receivedMessage = null;
DaqifiOutMessage? receivedMessage = null;

var handler = new ProtobufProtocolHandler(
statusMessageHandler: msg =>
Expand All @@ -69,11 +69,11 @@ public async void HandleAsync_WithStatusMessage_CallsStatusHandler()
}

[Fact]
public async void HandleAsync_WithStreamMessage_CallsStreamHandler()
public async Task HandleAsync_WithStreamMessage_CallsStreamHandler()
{
// Arrange
var streamHandlerCalled = false;
DaqifiOutMessage receivedMessage = null;
DaqifiOutMessage? receivedMessage = null;

var handler = new ProtobufProtocolHandler(
streamMessageHandler: msg =>
Expand Down Expand Up @@ -102,7 +102,7 @@ public async void HandleAsync_WithStreamMessage_CallsStreamHandler()
}

[Fact]
public async void HandleAsync_WithNonProtobufMessage_DoesNotCallHandlers()
public async Task HandleAsync_WithNonProtobufMessage_DoesNotCallHandlers()
{
// Arrange
var statusHandlerCalled = false;
Expand All @@ -127,7 +127,7 @@ public async Task HandleAsync_WithFloatStreamMessage_CallsStreamHandler()
{
// Arrange - USB firmware sends pre-scaled float values (AnalogInDataFloat)
var streamHandlerCalled = false;
DaqifiOutMessage receivedMessage = null;
DaqifiOutMessage? receivedMessage = null;

var handler = new ProtobufProtocolHandler(
streamMessageHandler: msg =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public async Task ParseAsync_PerChannelTimestamps_PopulatedFromFirmwareFormat()
Assert.Single(samples);
Assert.NotNull(samples[0].AnalogTimestamps);
Assert.Equal(2, samples[0].AnalogTimestamps!.Count);
Assert.Equal(1000u, samples[0].AnalogTimestamps[0]);
Assert.Equal(1001u, samples[0].AnalogTimestamps[1]);
Assert.Equal(1000u, samples[0].AnalogTimestamps![0]);
Assert.Equal(1001u, samples[0].AnalogTimestamps![1]);
}

[Fact]
Expand All @@ -201,9 +201,9 @@ public async Task ParseAsync_SharedTimestampPerRow_PerChannelTimestampsAllEqual(
Assert.NotNull(samples[0].AnalogTimestamps);
Assert.Equal(3, samples[0].AnalogTimestamps!.Count);
// All channels share the same timestamp in shared-ts mode
Assert.Equal(1746522255u, samples[0].AnalogTimestamps[0]);
Assert.Equal(1746522255u, samples[0].AnalogTimestamps[1]);
Assert.Equal(1746522255u, samples[0].AnalogTimestamps[2]);
Assert.Equal(1746522255u, samples[0].AnalogTimestamps![0]);
Assert.Equal(1746522255u, samples[0].AnalogTimestamps![1]);
Assert.Equal(1746522255u, samples[0].AnalogTimestamps![2]);
}

// -------------------------------------------------------------------------
Expand Down Expand Up @@ -443,7 +443,7 @@ public async Task ParseAsync_ProgressReporting_CallsCallback()
"TestDevice", "SN001", 100u, rows);

var progressCalls = 0;
var lastProgress = default(global::Daqifi.Core.Device.SdCard.SdCardParseProgress);
global::Daqifi.Core.Device.SdCard.SdCardParseProgress? lastProgress = null;
var parser = new global::Daqifi.Core.Device.SdCard.SdCardCsvFileParser();
var options = new global::Daqifi.Core.Device.SdCard.SdCardParseOptions
{
Expand All @@ -459,7 +459,8 @@ public async Task ParseAsync_ProgressReporting_CallsCallback()

Assert.Equal(250, samples.Count);
Assert.True(progressCalls >= 2, $"Expected ≥2 progress callbacks, got {progressCalls}");
Assert.Equal(250, lastProgress.MessagesRead);
Assert.NotNull(lastProgress);
Assert.Equal(250, lastProgress!.MessagesRead);
Assert.True(lastProgress.BytesRead > 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public async Task ParseAsync_ProgressReporting_CallsCallback()
);

var progressCalls = 0;
var lastProgress = default(global::Daqifi.Core.Device.SdCard.SdCardParseProgress);
global::Daqifi.Core.Device.SdCard.SdCardParseProgress? lastProgress = null;
var parser = new global::Daqifi.Core.Device.SdCard.SdCardJsonFileParser();
var options = new global::Daqifi.Core.Device.SdCard.SdCardParseOptions
{
Expand All @@ -273,7 +273,8 @@ public async Task ParseAsync_ProgressReporting_CallsCallback()
// Assert
Assert.Equal(250, samples.Count);
Assert.True(progressCalls >= 2); // At least 2 progress updates (100-line batches + final)
Assert.Equal(250, lastProgress.MessagesRead);
Assert.NotNull(lastProgress);
Assert.Equal(250, lastProgress!.MessagesRead);
}

[Fact]
Expand Down
10 changes: 5 additions & 5 deletions src/Daqifi.Core.Tests/Device/TimestampProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void ResetAll_ClearsAllDeviceStates()
#region Thread Safety Tests

[Fact]
public void ProcessTimestamp_IsThreadSafe()
public async Task ProcessTimestamp_IsThreadSafe()
{
// Arrange
var processor = new TimestampProcessor();
Expand All @@ -348,15 +348,15 @@ public void ProcessTimestamp_IsThreadSafe()
}));
}

Task.WaitAll(tasks.ToArray());
await Task.WhenAll(tasks.ToArray());

// Assert - All tasks completed without exception
Assert.Equal(100, results.Count);
Assert.Single(results.Where(r => r.IsFirstMessage)); // Only one first message
Assert.Single(results, r => r.IsFirstMessage); // Only one first message
}

[Fact]
public void ProcessTimestamp_MultipleDevicesInParallel_IsThreadSafe()
public async Task ProcessTimestamp_MultipleDevicesInParallel_IsThreadSafe()
{
// Arrange
var processor = new TimestampProcessor();
Expand Down Expand Up @@ -384,7 +384,7 @@ public void ProcessTimestamp_MultipleDevicesInParallel_IsThreadSafe()
}
}

Task.WaitAll(tasks.ToArray());
await Task.WhenAll(tasks.ToArray());

// Assert - All devices have 10 results
Assert.Equal(10, results.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void ClearBuffer()
var tempBuffer = new byte[_buffer.Length];
while (networkStream.DataAvailable)
{
_stream.Read(tempBuffer, 0, tempBuffer.Length);
_ = _stream.Read(tempBuffer, 0, tempBuffer.Length);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Daqifi.Core/Device/DeviceTypeDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class DeviceTypeDetector
/// </summary>
/// <param name="partNumber">The device part number (e.g., "Nq1", "Nq2", "Nq3").</param>
/// <returns>The detected DeviceType, or DeviceType.Unknown if not recognized.</returns>
public static DeviceType DetectFromPartNumber(string partNumber)
public static DeviceType DetectFromPartNumber(string? partNumber)
{
if (string.IsNullOrWhiteSpace(partNumber))
{
Expand Down