forked from equinor/flotilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignalRServiceMock.cs
More file actions
67 lines (58 loc) · 1.9 KB
/
Copy pathSignalRServiceMock.cs
File metadata and controls
67 lines (58 loc) · 1.9 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
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Database.Models;
using Api.Services;
namespace Api.Test.Mocks
{
public class MockSignalRService : ISignalRService
{
// Messages are added from MQTT background threads while tests poll this collection,
// so access is locked and readers get a snapshot to enumerate safely.
private readonly object _lock = new();
private readonly List<object> _latestMessages = [];
public IReadOnlyList<object> LatestMessages
{
get
{
lock (_lock)
return _latestMessages.ToList();
}
}
private void AddMessage(string label, object? messageObject)
{
lock (_lock)
_latestMessages.Add(new { Label = label, Message = messageObject });
}
public async Task SendMessageAsync<T>(
string label,
Installation? installation,
T messageObject
)
{
AddMessage(label, messageObject);
await Task.CompletedTask;
}
public async Task SendMessageAsync<T>(
string label,
string? installationCode,
T messageObject
)
{
AddMessage(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
) { }
}
}