public void GetSubscriptionsReturnsListOfSubscriptions() { var connection = new Mock <SignalR.Client.IConnection>(); var hubProxy = new HubProxy(connection.Object, "foo"); hubProxy.On <int>("foo", i => { }); hubProxy.On("baz", () => { }); var subscriptions = hubProxy.GetSubscriptions().ToList(); Assert.Equal(2, subscriptions.Count); Assert.Equal("foo", subscriptions[0]); Assert.Equal("baz", subscriptions[1]); }
private async void InicializarHubs() { Connection = new HubConnection(ServerURI); Connection.Closed += Connection_Closed; //stockTickerHub.On( escrita sem passagem nunhuma de parametros HubProxy = Connection.CreateHubProxy("MyHub"); //Handle incoming event from server: use Invoke to write to console from SignalR's thread HubProxy.On("LimparCores", () => this.Invoke((Action)(() => { ResetCores(); } )) ); try { await Connection.Start(); } catch (HttpRequestException except) { MessageBox.Show($" Sem conecção {except.Message} "); // StatusText.Text = "Unable to connect to server: Start server before connecting clients."; //No connection: Don't enable Send button or show chat UI return; } }
public async void Connect(string userName) { UserName = userName; Connection = new HubConnection(ServerUri); Connection.Closed += Connection_Closed; Connection.StateChanged += Connection_StateChanged; HubProxy = Connection.CreateHubProxy(CHAT_HUB); //Handle incoming event from server: use Invoke to write to console from SignalR's thread HubProxy.On <string, string, string, string, string>(GET_FROM_USER, (roomId, clientId, fromName, messageText, dt) => _mainWindow.Dispatcher.Invoke(() => AddMessageToRoom(roomId, clientId, fromName, messageText, dt, false)) ); HubProxy.On <bool, string, string, string, string, bool>(GET_MESSAGE, (isPublic, roomId, fromName, messageText, dt, isAdmin) => _mainWindow.Dispatcher.Invoke(() => AddMessageToRoom(roomId, "", fromName, messageText, dt, isAdmin)) ); try { await Connection.Start(); } catch (HttpRequestException) { ConnectionFailed(); } }
/// <summary> /// Creates and connects the hub connection and hub proxy. This method /// is called asynchronously from SignInButton_Click. /// </summary> private async void ConnectAsync() { Connection = new HubConnection(ServerURI); HubProxy = Connection.CreateHubProxy("BioMatcherHub"); try { await Connection.Start(); } catch (HttpRequestException ex) { throw ex; //StatusText.Text = "Unable to connect to server: Start server before connecting clients."; //No connection: Don't enable Send button or show chat UI //return; } HubProxy.On <MatchResult>("IdentifyComplete", (result) => { var handler = OnMatchComplete; if (handler != null) { handler(this, result); } }); }
private void SubscribeEventFromServer() { //HubProxy.On<CustomerInfo, List<CustomerInfo>, List<GroupInfo>, List<MessageInfo>, List<CustomerInfo>> // (ClientEventNames.OnGetInventory, (customer, friendList, groupList, offlineMessageList, requestList) => // OnGetInventory(customer, friendList, groupList, offlineMessageList, requestList)); //HubProxy.On<CustomerInfo>(ClientEventNames.OnGetCustomerInfo, (customer) => OnGetCustomerInfo(customer)); HubProxy.On <List <CustomerInfo> >(ClientEventNames.OnGetFriendList, (friendList) => OnGetFriendList(friendList)); HubProxy.On <List <GroupInfo> >(ClientEventNames.OnGetGroupList, (groupList) => OnGetGroupList(groupList)); HubProxy.On <List <MessageInfo> >(ClientEventNames.OnGetOfflineMessage, (offlineMessageList) => OnGetOfflineMessage(offlineMessageList)); HubProxy.On <List <AddFriendRequest> >(ClientEventNames.OnAddFriendRequest, (requestList) => OnAddFriendRequest(requestList)); HubProxy.On <CustomerInfo, bool>(ClientEventNames.OnAddFriendRespond, (respondCustomer, agree) => OnAddFriendRespond(respondCustomer, agree)); HubProxy.On <string>(ClientEventNames.OnUnFriend, (friendId) => OnUnFriend(friendId)); HubProxy.On <string, string>(ClientEventNames.OnChangeCustomerStatus, (customerId, status) => OnChangeCustomerStatus(customerId, status)); HubProxy.On <GroupInfo>(ClientEventNames.OnAddGroup, (group) => OnAddGroup(group)); HubProxy.On <string>(ClientEventNames.OnDeleteGroup, (groupId) => OnDeleteGroup(groupId)); HubProxy.On <string, string>(ClientEventNames.OnAddAdminToGroup, (adminId, groupId) => OnAddAdminToGroup(adminId, groupId)); HubProxy.On <string, string>(ClientEventNames.OnRemoveAdminFromGroup, (adminId, groupId) => OnRemoveAdminFromGroup(adminId, groupId)); HubProxy.On <List <InviteGroupRequest> >(ClientEventNames.OnInviteToGroupRequest, (requestList) => OnInviteToGroupRequest(requestList)); HubProxy.On <string, GroupInfo, bool>(ClientEventNames.OnInviteToGroupRespond, (customerId, group, agree) => OnInviteToGroupRespond(customerId, group, agree)); HubProxy.On <string, string>(ClientEventNames.OnRemoveCustomerFromGroup, (customerId, groupId) => OnRemoveCustomerFromGroup(customerId, groupId)); HubProxy.On <string, GroupInfo>(ClientEventNames.OnJoinGroup, (customerId, groupId) => OnJoinGroup(customerId, groupId)); HubProxy.On <string, string>(ClientEventNames.OnLeaveGroup, (groupId, customerId) => OnLeaveGroup(customerId, groupId)); HubProxy.On <string, GroupInfo>(ClientEventNames.OnUpdateGroup, (updateType, group) => OnUpdateGroup(updateType, group)); HubProxy.On <MessageInfo>(ClientEventNames.OnReceiveMessage, (msg) => OnReceiveMessage(msg)); }
private async void ConnectAsync() { try { Connection = new HubConnection(ServerUri); Connection.Closed += Connection_Closed; // 创建一个集线器代理对象 HubProxy = Connection.CreateHubProxy("FastHub"); // 供服务端调用,将消息输出到消息列表框中 HubProxy.On <string, string>("AddMessage", Receive); await Connection.Start(); } catch (Exception ex) { // 连接失败 richTextBox1.AppendText("Exception:" + ex.Message + "\r"); return; } // 显示聊天控件 richTextBox1.AppendText("连上服务:" + ServerUri + "\r"); }
public async Task <bool> ConnectForSignalAsync(string hubName, TextWriter traceOutput = null) { HubConnection = new Microsoft.AspNet.SignalR.Client.HubConnection("http://serverdown.bogus.address.com", new Dictionary <string, string> { { "bearerToken", "Random" } }); if (traceOutput != null) { HubConnection.TraceLevel = TraceLevels.All; HubConnection.TraceWriter = traceOutput; } HubProxy = HubConnection.CreateHubProxy(hubName); HubProxy.On <object>("OnEventMessage", OnEventMessage); try { await HubConnection.Start(); return(true); } catch (HttpRequestException e) { return(false); } }
public async Task ConnectAsync() { Connection = new HubConnection(ServerUri); Connection.Closed += Connection_Closed; HubProxy = Connection.CreateHubProxy("ChatHub"); HubProxy.On <string, string>("BroadcastMessage", (name, message) => { if (MessageReceived != null) { MessageReceived(this, new MessageEventArgs { Message = message, Name = name }); } } ); try { await Connection.Start(); if (ConnectionOpened != null) { ConnectionOpened(this, new EventArgs()); } } catch (HttpRequestException) { return; } }
private async void ConnectAsync() { Connection = new HubConnection(ServerURI); Connection.Closed += Connection_Closed; HubProxy = Connection.CreateHubProxy("MyHub"); HubProxy.On <string, string>("AddMessage", (name, message) => { Invoke((Action)(() => RichTextBoxConsole.AppendText(string.Format("{0}: {1}" + Environment.NewLine, name, message)) )); string Path = PathSaved + "\\" + DateTime.Now.ToLongDateString() + new Random().Next(214421414) + ".txt"; using (StreamWriter writer = new StreamWriter(Path)) { writer.Write(Name + ":" + message); } } ); try { await Connection.Start(); } catch (HttpRequestException) { StatusText.Text = "Unable to connect to server: Start server before connecting clients."; return; } SignInPanel.Visible = false; ChatPanel.Visible = true; TextBoxMessage.Focus(); RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + Environment.NewLine); }
private static void CheckSignalr() { var server = string.Format("http://{0}/", GetAppConfig("cdmServer")); Connection = new HubConnection(server); HubProxy = Connection.CreateHubProxy("Cdmhub"); TraceLog(string.Format("signalr 查询: {0}", "CreateHubProxy ok")); HubProxy.On <CdmMessage>("VoiceMessage", (mcc) => VoiceMessageProcessing(mcc)); TraceLog(string.Format("signalr 查询: {0}", "HubProxy.On ok")); ConnectSignalr(); do { try { if (Connection.State.Equals(Microsoft.AspNet.SignalR.Client.ConnectionState.Disconnected)) { TraceLog(string.Format("CheckSignalr disconnected, reconnecting:{0}", GetAppConfig("cdmServer"))); ConnectSignalr(); } } catch (Exception ex) { TraceLog(string.Format("CheckSignalr reconnecting error:{0},{1}", GetAppConfig("cdmServer"), ex.Message)); } Thread.Sleep(1000 * 60); } while (true); // ReSharper disable once FunctionNeverReturns }
private async Task <bool> EnsureProxy() { if (HubProxy != null) { return(true); } Connection = new HubConnection(ServerUri); HubProxy = Connection.CreateHubProxy("CustomerHub"); // Register callbacks HubProxy.On <Customer>("Saved", OnCustomerSaved); HubProxy.On <Guid>("Deleted", OnCustomerDeleted); try { await Connection.Start(); return(true); } catch (HttpRequestException) { Connection.Dispose(); Connection = null; MessageBox.Show("Unable to connect to server: Start server before connecting clients."); return(false); } }
/// <summary>設定連線資訊</summary> /// <param name="groupNames">設定所屬群組,無輸入則無群組</param> public virtual void SetConnection(List <string> groupNames = null) { if (groupNames != null && groupNames.Any()) { GroupNames = groupNames; QueryStrs["JsonGroupNames"] = JsonConvert.SerializeObject(groupNames); } QueryStrs["ValidECode"] = ValidECode; QueryStrs["Name"] = Name; HubConn = new HubConnection(HostUrl, QueryStrs); HubProxy = HubConn.CreateHubProxy(ServerHubName); //這邊的擴充可以在子類別覆寫 HubProxy.On <string>( "CmdFinished", (cmdCode) => { CmdFinished(cmdCode); }); HubProxy.On <string, List <object>, string>( "ExecDynamicCmd", (methodName, args, cmdCode) => { ExecDynamicCmd(methodName, args); }); HubConn.StateChanged += OnStateChanged; HubConn.Error += OnError; HubConn.Received += OnReceived; }
public Task ConfigureProxy(HubConnection hubConnection) { HubConnection = hubConnection; HubProxy = HubConnection.CreateHubProxy("MarkHub"); HubProxy.On <Message>("addMessage", message => { ForegroundColor = message.Sender.Color; WriteLine(message.ToString()); ResetColor(); }); HubProxy.On <string>("onConnected", s => { ForegroundColor = ConsoleColor.Red; WriteLine(s + " is connected"); ResetColor(); }); HubProxy.On <string>("onDisconnected", s => { ForegroundColor = ConsoleColor.Red; WriteLine(s + " is disconnected"); ResetColor(); }); return(hubConnection.Start()); }
/// <summary> /// 对各种协议的事件进行处理 /// </summary> private void AddProtocal() { //接收实时信息 HubProxy.On <string>("AddMessage", DealMessage); //连接上触发connected处理 HubProxy.On("logined", () => Invoke((Action)(() => { Text = string.Format("当前用户:{0}", 11111); richTextBox.AppendText(string.Format("以名称【" + 1111 + "】连接成功!" + Environment.NewLine)); InitControlStatus(true); })) ); //服务端拒绝的处理 HubProxy.On("rejected", () => Invoke((Action)(() => { richTextBox.AppendText(string.Format("无法使用名称【" + 1111 + "】进行连接!" + Environment.NewLine)); InitControlStatus(false); CloseHub(); })) ); //客户端收到服务关闭消息 HubProxy.On("SendClose", () => { CloseHub(); }); }
private async void ConnectAsync() { Connection = new HubConnection(ServerURI); Connection.Closed += Disconnect; HubProxy = Connection.CreateHubProxy("GoFish"); //Handle incoming event from server: use Invoke to write to console from SignalR's thread HubProxy.On("YourTurn", () => { } ); HubProxy.On("OpponentConnect", () => { } ); HubProxy.On <List <Card> >("Deal", (cards) => { } ); //try //{ await Connection.Start(); //} //catch (HttpRequestException) //{ // Console.WriteLine("Error Connecting!"); // return; //} }
private async void InitHub() { var queryStringData = new Dictionary <string, string>(); queryStringData.Add("UserName", UserName); //创建连接对象 Connection = new HubConnection(ServerUrl, queryStringData); //绑定一个集线器 HubProxy = Connection.CreateHubProxy("SignalRHub"); HubProxy.On("AddMessage", (m) => { WriteToConsole(m); } ); try { //开始连接 await Connection.Start(); } catch (Exception ex) { WriteToConsole("服务器未连接上,异常为:" + ex.Message); return; } WriteToConsole("服务器已连接上"); }
private async void ConnectAsync() { Connection = new HubConnection(ServerUri); Connection.Closed += Connection_Closed; // 创建一个集线器代理对象 HubProxy = Connection.CreateHubProxy("ChatHub"); // 供服务端调用,将消息输出到消息列表框中 HubProxy.On <string, string>("AddMessage", (name, message) => this.Dispatcher.Invoke(() => RichTextBoxConsole.AppendText(String.Format("{0}: {1}\r", name, message)) )); try { await Connection.Start(); } catch (HttpRequestException) { ChatPanel.Visibility = Visibility.Visible; RichTextBoxConsole.AppendText("请检查服务是否开启:" + ServerUri + "\r"); // 连接失败 return; } // 显示聊天控件 ChatPanel.Visibility = Visibility.Visible; ButtonSend.IsEnabled = true; TextBoxMessage.Focus(); RichTextBoxConsole.AppendText("连上服务:" + ServerUri + "\r"); }
public override void IncomingEvents() { HubProxy.On <Queue>("QueueFinished", (queue) => { // Xử lý status device APIUtils.FormQueueNumber.RefreshQueueNumbers(); }); }
private void AccessCommand()//一些連線的初始化,和指令的接收 { //指令要在他連線的時候就跑過,以後才會執行 Connection = new HubConnection(ServerURI); HubProxy = Connection.CreateHubProxy("MyHub"); HubProxy.On <String, String>("Pass", (GroupName, ComputerName) => this.Invoke((Action)(() => ClientReceiving("Pass", "", GroupName, ComputerName) )) ); HubProxy.On <String, String>("Restart", (GroupName, ComputerName) => this.Invoke((Action)(() => ClientReceiving("Restart", "", GroupName, ComputerName) )) ); HubProxy.On <String, String>("Shutdown", (GroupName, ComputerName) => this.Invoke((Action)(() => ClientReceiving("Shutdown", "", GroupName, ComputerName) )) ); HubProxy.On <String, String, String>("CMDCommand", (CMD, GroupName, ComputerName) => this.Invoke((Action)(() => ClientReceiving("CMDCommand", CMD, GroupName, ComputerName) )) ); }
private async void ConnectAsync() { Connection = new HubConnection(ServerUri); Connection.StateChanged += Connection_StateChanged; Connection.Closed += Connection_Closed; // 创建一个集线器代理对象 HubProxy = Connection.CreateHubProxy("noticeHub"); // 供服务端调用,将消息输出到消息列表框中 HubProxy.On <string, dynamic>("schemeBreakdown", (code, sendData) => this.Dispatcher.Invoke(() => { } ) ); HubProxy.On <string, dynamic>("schemeNew", (code, sendData) => this.Dispatcher.Invoke(() => { } ) ); try { await Connection.Start(); } catch (HttpRequestException) { // 连接失败 return; } }
/// <summary> /// Creates and connects the hub connection and hub proxy. This method /// is called asynchronously from SignInButton_Click. /// </summary> private async void ConnectAsync() { Connection = new HubConnection(ServerURI); Connection.Closed += Connection_Closed; HubProxy = Connection.CreateHubProxy("MyHub"); //Handle incoming event from server: use Invoke to write to console from SignalR's thread HubProxy.On <string, string>("AddMessage", (name, message) => this.Dispatcher.Invoke(() => RichTextBoxConsole.AppendText(String.Format("{0}: {1}\r", name, message)) ) ); try { await Connection.Start(); } catch (HttpRequestException) { StatusText.Content = "Unable to connect to server: Start server before connecting clients."; //No connection: Don't enable Send button or show chat UI return; } //Show chat UI; hide login UI SignInPanel.Visibility = Visibility.Collapsed; ChatPanel.Visibility = Visibility.Visible; ButtonSend.IsEnabled = true; TextBoxMessage.Focus(); RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + "\r"); }
//서버와 클라를 연결하는 매서드 먼저 "http://localhost:2989/signalr" 으로 허브 컨넥션을 만듬 // 그 커넥션을 서버의 MtHub와 허브프록시로 연결 이제부터 모든 것은 허브프록시로 호출 // HubProxy.On을 이용해서 서버에서 1번째 인수 메서드가 호출되면 자동으로 해당 프록시 온 메서드가 클라이언트에서 수행됨 // 두개의 매서드를 지정도 가능하고 각각이 새로운 쓰레드로 돌아간다고 생각하면 쉬움 private async void ConnectAsync() { Connection = new HubConnection(ServerURI); HubProxy = Connection.CreateHubProxy("MyHub"); //스튜던트 객체를 통째로 받는 중 HubProxy.On <Student>("addMessage", (student) => this.Invoke((Action)(() => textBox2.AppendText(String.Format("Name : {0}, Age : {1}, Id : {2}" + Environment.NewLine, student.Name, student.Age, student.Id)) )) ); //비트맵이미지와 숫자를 json형식으로 받아 컨버트함 HubProxy.On <string>("draw", (jsonString) => this.Invoke((Action)(() => pictureBox1.Image = ToBitmap(JsonConvert.DeserializeObject <NowImage>(jsonString).image) ))); HubProxy.On <string>("timerStart", (a) => this.Invoke((Action)(() => timer1.Start()))); // 커넥션을 비동적으로 연결 try { await Connection.Start(); } catch (HttpRequestException) { textBox2.Text = "Unable to connect to server: Start server before connecting clients."; return; } //커넥션 성공 메세지 textBox2.AppendText("Connected to server at " + ServerURI + Environment.NewLine); }
private static void ConnectServer(string clientId) { Console.WriteLine($"{clientId} connecting to server.."); //SignalRConnection = new HubConnection("http://" + ConfigurationManager.AppSettings["ServerUri"] + "/signalr"); SignalRConnection = new HubConnection(ServerUri); HubProxy = SignalRConnection.CreateHubProxy("MyMessageHub"); HubProxy.On <string>("BroadcastMessage", ReceiveMessage); try { SignalRConnection.Start().Wait(); SignalRConnection.StateChanged += delegate(StateChange state) { if (state.NewState == ConnectionState.Connected) { //HubProxy.Invoke("Connect", SignalRConnection.ConnectionId, clientId); Console.WriteLine("Client connected."); } }; Console.WriteLine("Connection Successful."); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } }
private async void ConnectAsync() { this.Invoke((Action)(() => lblStatus.Text = "Connecting to server...")); Connection = new HubConnection(ServerURI); Connection.Closed += Connection_Closed; HubProxy = Connection.CreateHubProxy("MyHub"); HubProxy.On <string, string, string, string>("OnNewNotification", (subject, content, fromUserId, toUserId) => OnNewNotificationHandler(subject, content, fromUserId, toUserId)); try { await Connection.Start(); this.Invoke((Action)(() => btnConnect.Enabled = false)); } catch (HttpRequestException) { this.Invoke((Action)(() => btnConnect.Enabled = true)); this.Invoke((Action)(() => rtbContent.Enabled = false)); this.Invoke((Action)(() => lblStatus.Text = "Unable to connect. The SignalR Server doesn't seem to work. Please reconnect")); // Reconnect again //ConnectAsync(); return; } //Activate UI txtSubject.Enabled = true; rtbContent.Enabled = true; btnSend.Enabled = true; txtSubject.Focus(); lblStatus.Text = "Connected to server at " + ServerURI; }
private async void ConnectAsync() { con = new HubConnection(ServerURI); con.Closed += Connection_Closed; con.Error += Connection_Error; HubProxy = con.CreateHubProxy("MyHub"); //Handle incoming event from server: use Invoke to write to console from SignalR's thread HubProxy.On <string>("getPos", (message) => Dispatcher.BeginInvoke(() => test(message)) ); try { await con.Start(); } catch (HttpRequestException) { //No connection: Don't enable Send button or show chat UI btntrack.Content = "eror"; } catch (HttpClientException) { btntrack.Content = "eror"; } Dispatcher.BeginInvoke(() => { HubProxy.Invoke("Connect", "15"); }); }
private void AddMethod <T>(string methodName, Action <T> action) { if (!_methodsCollection.Contains(methodName)) { HubProxy.On <T>(methodName, action); _methodsCollection.Add(methodName); } }
//Creates and connects the hub connection and hub proxy. //This method is called asynchronously from SignInButton_Click. private async void ConnectAsync() { Connection = new HubConnection(ServerURI, new Dictionary <string, string> { { "UserName", UserName } }); Connection.Closed += Connection_Closed; Connection.Reconnecting += Connection_Reconnecting; Connection.Reconnected += Connection_Reconnected; HubProxy = Connection.CreateHubProxy("ChatHub"); //Handle incoming event from server: use Invoke to write to console from SignalR's thread HubProxy.On <string, string, string>("AddMessage", (name, message, group) => this.Invoke((Action)(() => //RichTextBoxConsole.AppendText(String.Format("{0}: {1}" + Environment.NewLine, name, message)) WriteMessage(name, message, group) )) ); try { await Connection.Start(); } catch (HttpRequestException) { StatusText.Text = "Unable to connect to server: Start server before connecting clients."; //No connection: Don't enable Send button or show chat UI return; } //State oject stores data to be transmitted to the server HubProxy["userName"] = UserName; //Activate UI lblUserName.Text = UserName; lblUserName.Font = new System.Drawing.Font("Arial", 20); SignInPanel.Visible = false; ChatPanel.Visible = true; //btnSend.Enabled = true; //txtMessage.Focus(); RichTextBoxConsole.AppendText("Connected to server at " + ServerURI + Environment.NewLine); //var user = _db.Users.Include("Groups").SingleOrDefault(u => u.ID == UserID); UpdateGroups(); lblUserStatus.ForeColor = System.Drawing.Color.Green; //VAIHDA //foreach (var item in user.Groups) //{ // //TabPage tp = new TabPage(item.GroupName) { Name = item.GroupName , Tag = item.ID}; // //tcGroups.TabPages.Add(tp); // //tp.Controls.Add(new ucChatWindow() {ParentForm = this}); // await HubProxy.Invoke("JoinGroup", item.GroupName); //} }
private async void HubConnectAsync() { Connection = new HubConnection(Strings.ServerUri); HubProxy = Connection.CreateHubProxy("GameHub"); HubProxy.On("UpdateRooms", () => this.Dispatcher.Invoke(UpdateRooms)); await Connection.Start(); }
private void InitializeMethods() { Connection.Closed += ConnectionClosed; Connection.ConnectionSlow += ConnectionSlow; HubProxy.On <Message>("MessageRecived", message => { //notify user }); }
public EchoHub(string uri) : base(uri, "EchoHub") { HubProxy.On <string>("Message", msg => { if (Message != null) { Message(msg); } }); }
public void InvokeEventRaisesEvent() { var connection = new Mock<SignalR.Client.IConnection>(); var hubProxy = new HubProxy(connection.Object, "foo"); bool eventRaised = false; hubProxy.On("foo", () => { eventRaised = true; }); hubProxy.InvokeEvent("foo", new object[] { }); Assert.True(eventRaised); }
public void InvokeEventRaisesEventWithData() { var connection = new Mock<SignalR.Client.IConnection>(); var hubProxy = new HubProxy(connection.Object, "foo"); bool eventRaised = false; hubProxy.On<int>("foo", (i) => { eventRaised = true; Assert.Equal(1, i); }); hubProxy.InvokeEvent("foo", new object[] { 1 }); Assert.True(eventRaised); }
public void InvokeEventRaisesEventWithData() { var connection = new Mock<IHubConnection>(); connection.SetupGet(x => x.JsonSerializer).Returns(new JsonSerializer()); var hubProxy = new HubProxy(connection.Object, "foo"); bool eventRaised = false; hubProxy.On<int>("foo", (i) => { eventRaised = true; Assert.Equal(1, i); }); hubProxy.InvokeEvent("foo", new[] { JToken.FromObject(1) }); Assert.True(eventRaised); }
public void InvokeEventRaisesEvent() { var connection = new Mock<IHubConnection>(); connection.SetupGet(x => x.JsonSerializer).Returns(new JsonSerializer()); var hubProxy = new HubProxy(connection.Object, "foo"); bool eventRaised = false; hubProxy.On("foo", () => { eventRaised = true; }); hubProxy.InvokeEvent("foo", new JToken[] { }); Assert.True(eventRaised); }
public void GetSubscriptionsReturnsListOfSubscriptions() { var connection = new Mock<SignalR.Client.IConnection>(); var hubProxy = new HubProxy(connection.Object, "foo"); hubProxy.On<int>("foo", i => { }); hubProxy.On("baz", () => { }); var subscriptions = hubProxy.GetSubscriptions().ToList(); Assert.Equal(2, subscriptions.Count); Assert.Equal("foo", subscriptions[0]); Assert.Equal("baz", subscriptions[1]); }