Add ActiveDevice + DeviceRegistry + HubEnvelopes + IDeviceClient/Channel implementations
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user