forked from EcovadisCode/Ev.ServiceBus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFakeClientFactory.cs
More file actions
73 lines (59 loc) · 2.31 KB
/
FakeClientFactory.cs
File metadata and controls
73 lines (59 loc) · 2.31 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
using System.Collections.Generic;
using System.Linq;
using Azure.Messaging.ServiceBus;
using Ev.ServiceBus.Abstractions.Configuration;
namespace Ev.ServiceBus.TestHelpers;
public class FakeClientFactory : IClientFactory
{
private readonly List<ServiceBusClientMock> _registeredClients;
public FakeClientFactory()
{
_registeredClients = new List<ServiceBusClientMock>();
}
public ServiceBusClientMock GetAssociatedMock(string endpoint)
{
return _registeredClients.FirstOrDefault(o => o.EndPoint == endpoint);
}
public ServiceBusClientMock[] GetAllRegisteredClients()
{
return _registeredClients.ToArray();
}
public ServiceBusClient Create(ConnectionSettings connectionSettings)
{
var client = new ServiceBusClientMock(connectionSettings);
_registeredClients.Add(client);
return client.Mock.Object;
}
public SenderMock GetSenderMock(string resourceId)
{
return _registeredClients.Select(o => o.GetSenderMock(resourceId)).FirstOrDefault(o => o != null);
}
public ProcessorMock GetProcessorMock(string queueName)
{
return _registeredClients.Select(o => o.GetProcessorMock(queueName)).FirstOrDefault(o => o != null);
}
public ProcessorMock GetProcessorMock(string topicName, string subscriptionName)
{
return _registeredClients.Select(o => o.GetProcessorMock(topicName, subscriptionName)).FirstOrDefault(o => o != null);
}
public SessionProcessorMock GetSessionProcessorMock(string queueName)
{
return _registeredClients.Select(o => o.GetSessionProcessorMock(queueName)).FirstOrDefault(o => o != null);
}
public SessionProcessorMock GetSessionProcessorMock(string topicName, string subscriptionName)
{
return _registeredClients.Select(o => o.GetSessionProcessorMock(topicName, subscriptionName)).FirstOrDefault(o => o != null);
}
public SenderMock[] GetAllSenderMocks()
{
return _registeredClients.SelectMany(o => o.Senders).ToArray();
}
public ProcessorMock[] GetAllProcessorMocks()
{
return _registeredClients.SelectMany(o => o.Processors).ToArray();
}
public SessionProcessorMock[] GetAllSessionProcessorMocks()
{
return _registeredClients.SelectMany(o => o.SessionProcessors).ToArray();
}
}