Add ActiveDevice + DeviceRegistry + HubEnvelopes + IDeviceClient/Channel implementations

This commit is contained in:
2026-06-11 21:51:25 +00:00
parent 78373b0912
commit 4dc48bd9fd
6 changed files with 217 additions and 2 deletions
+16 -2
View File
@@ -1,14 +1,28 @@
using System.Collections.Concurrent;
using System.Text.Json;
using backend.DeviceHub;
using backend.Tools;
namespace backend.tests;
// Slim version for Tasks 9-15. Task 16 reopens this file to add IDeviceClient + envelope sending.
public class FakeDeviceChannel : IDeviceChannel
public class FakeDeviceChannel : IDeviceChannel, IDeviceClient
{
public List<HubEnvelope> SentEnvelopes { get; } = new();
public List<byte[]> SentBinary { get; } = new();
public ConcurrentQueue<JsonElement> PiToolReplies { get; } = new();
public Task SendEnvelopeAsync<T>(T envelope, CancellationToken ct) where T : HubEnvelope
{
SentEnvelopes.Add(envelope);
return Task.CompletedTask;
}
public Task SendBinaryAsync(ReadOnlyMemory<byte> bytes, CancellationToken ct)
{
SentBinary.Add(bytes.ToArray());
return Task.CompletedTask;
}
public Task<JsonElement> CallPiToolAsync(string name, JsonElement args, CancellationToken ct)
{
if (PiToolReplies.TryDequeue(out var reply))