protected override IList <string> GetSignals(string userId, string connectionId) { var signals = _hubs.SelectMany(info => { var items = new List <string> { PrefixHelper.GetHubName(info.Name), PrefixHelper.GetHubConnectionId(info.CreateQualifiedName(connectionId)), }; if (!String.IsNullOrEmpty(userId)) { items.Add(PrefixHelper.GetHubUserId(info.CreateQualifiedName(userId))); } return(items); }) .Concat(new[] { PrefixHelper.GetConnectionId(connectionId), PrefixHelper.GetAck(connectionId) }); return(signals.ToList()); }
public void TestHubUserMessage(string userName, string input, string hub, Type exceptionType = null) { var hubs = new List <string> { "hub1", "hub.hub1", "hub2.hub1.h.hub2", ".", ".." }; var parser = new SignalRMessageParser(hubs, _resolver); var message = SignalRMessageUtility.CreateMessage(PrefixHelper.GetHubUserId(hub + "." + userName), input); var excludedConnectionIds = new string[] { GenerateRandomName(), GenerateRandomName() }; message.Filter = GetFilter(excludedConnectionIds.Select(s => PrefixHelper.GetConnectionId(s)).ToList()); if (exceptionType != null) { Assert.Throws(exceptionType, () => parser.GetMessages(message).ToList()); return; } var msgs = parser.GetMessages(message).ToList(); Assert.Single(msgs); var msg = msgs[0].Message as UserDataMessage; Assert.NotNull(msg); Assert.Equal(userName, msg.UserId); Assert.Equal(input, msg.Payloads["json"].GetSingleFramePayload()); }
public void TestHubUserMessageWithMultiplePossiblities() { var hubs = new List <string> { "hub", "hub.hub1", "hub.hub1.h.hub2", ".", "......" }; var parser = new SignalRMessageParser(hubs, _resolver); var fullName = "hub.hub1.h.hub2.user1"; var message = SignalRMessageUtility.CreateMessage(PrefixHelper.GetHubUserId(fullName), null); var msgs = parser.GetMessages(message).ToList(); Assert.Equal(3, msgs.Count); var msg = msgs[0].Message as UserDataMessage; Assert.NotNull(msg); Assert.Equal("h.hub2.user1", msg.UserId); msg = msgs[1].Message as UserDataMessage; Assert.NotNull(msg); Assert.Equal("user1", msg.UserId); msg = msgs[2].Message as UserDataMessage; Assert.NotNull(msg); Assert.Equal("hub1.h.hub2.user1", msg.UserId); }