public void ShouldNotTriggerReceiveCallbackIfNotAddedFirst() { var mockRepo = new Mock <IConnectedClientRepository <HubConnectedClient> >(); var hub = new SignalRMessageHubService(mockRepo.Object); var mockRequest = new Mock <IRequest>(); hub.Context = new HubCallerContext(mockRequest.Object, "123"); var mockClients = new Mock <IHubCallerConnectionContext <dynamic> >(); hub.Clients = mockClients.Object; var receiver = new Mock <IMessageHubServiceReceiver>(); hub.Send(Guid.NewGuid(), Message.Create().WithData("Test")); receiver.Verify(r => r.Receive(It.IsAny <Guid>(), It.IsAny <Message>()), Times.Never); }
public void ShouldNotTriggerReceiveCallbackFromSameHubId() { var mockRepo = new Mock <IConnectedClientRepository <HubConnectedClient> >(); var hub = new SignalRMessageHubService(mockRepo.Object); var mockRequest = new Mock <IRequest>(); hub.Context = new HubCallerContext(mockRequest.Object, "123"); var mockGroups = new Mock <IGroupManager>(); hub.Groups = mockGroups.Object; var mockClients = new Mock <IHubCallerConnectionContext <dynamic> >(); hub.Clients = mockClients.Object; var receiver = new Mock <IMessageHubServiceReceiver>(); Guid excludedGuid = Guid.NewGuid(); receiver.SetupGet(r => r.Id).Returns(excludedGuid); hub.AddReceiver(new ConnectedClientData(excludedGuid, null)); hub.Send(excludedGuid, Message.Create().WithData("Test")); receiver.Verify(r => r.Receive(excludedGuid, It.IsAny <Message>()), Times.Never); }
public void ShouldTriggerReceiveCallbackAfterSend() { bool failed = false; try { var mockRepo = new Mock <IConnectedClientRepository <HubConnectedClient> >(); var hub = new SignalRMessageHubService(mockRepo.Object); var mockClients = new Mock <IHubCallerConnectionContext <dynamic> >(); var all = new Mock <IMessageHubServiceReceiver>(); hub.Clients = mockClients.Object; all.Setup(m => m.Receive(It.IsAny <Guid>(), It.IsAny <Message>())).Verifiable(); mockClients.Setup(m => m.Group("__receivers", It.IsAny <string>())).Returns(all.Object); hub.Send(Guid.NewGuid(), Message.Create().WithData("Test")); all.VerifyAll(); } catch (MockException) { failed = true; } Assert.IsFalse(failed); }