Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add Group support to a mocked Client in a SignalR 2.x unit testing framework?

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?

like image 737
JohnB Avatar asked Nov 01 '22 00:11

JohnB


1 Answers

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();
        }
like image 93
LastTribunal Avatar answered Nov 11 '22 01:11

LastTribunal