-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathSignalRServiceMock.cs
More file actions
74 lines (65 loc) · 2.17 KB
/
Copy pathSignalRServiceMock.cs
File metadata and controls
74 lines (65 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Api.Database.Models;
using Api.Services;
namespace Api.Test.Mocks
{
public class MockSignalRService : ISignalRService
{
// Messages arrive on background threads -- the MQTT event handler raises them
// while a test is polling this collection from another thread. An unguarded
// List throws "Collection was modified; enumeration operation may not execute"
// in the middle of a foreach, so writes take a lock and reads hand back a
// snapshot that the caller can safely enumerate.
private readonly List<object> _latestMessages = [];
private readonly Lock _lock = new();
public IReadOnlyList<object> LatestMessages
{
get
{
lock (_lock)
{
return [.. _latestMessages];
}
}
}
private void Record(string label, object messageObject)
{
lock (_lock)
{
_latestMessages.Add(new { Label = label, Message = messageObject });
}
}
public async Task SendMessageAsync<T>(
string label,
Installation? installation,
T messageObject
)
{
Record(label, messageObject!);
await Task.CompletedTask;
}
public async Task SendMessageAsync<T>(
string label,
string? installationCode,
T messageObject
)
{
Record(label, messageObject!);
await Task.CompletedTask;
}
public async Task SendMessageAsync(string label, string? installationCode, string message)
{
await Task.CompletedTask;
}
public void ReportDockFailureToSignalR(Robot robot, string message) { }
public void ReportGeneralFailToSignalR(Robot robot, string title, string message) { }
public void ReportAutoScheduleToSignalR(
string type,
string missionDefinitionId,
string message,
string installationCode
) { }
}
}