I'm using Moq to build up a UnitTest framework for my SignalR 2.x application. I am currently mocking up my Clients by:
var mockClients = new Mock<IHubCallerConnectionContext>();
Clients = mockClients.Object;
In order to test, I need to test sending messages by Group:
Clients.Group(groupName).sendSomeMessage(message);
How do I add Group support to my mocked up Client?
Check this: https://github.com/SignalR/SignalR/blob/release/tests/Microsoft.AspNet.SignalR.Tests/Server/Hubs/HubFacts.cs
public void HubsGroupAreMockable()
{
var hub = new MyTestableHub();
var mockClients = new Mock<IHubCallerConnectionContext<dynamic>>();
var groups = new Mock<IClientContract>();
hub.Clients = mockClients.Object;
groups.Setup(m => m.send(It.IsAny<string>())).Verifiable();
mockClients.Setup(m => m.Group("test")).Returns(groups.Object);
hub.SendGroup("test", "foo");
groups.VerifyAll();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With