public void LeaveRoom() { if (Session["UserAccountName"] != null) { UserInfo userInfo = (UserInfo)HttpRuntime.Cache[Session["UserAccountName"].ToString()]; _chatHub.LeaveRoom(userInfo.DisplayName); } }
public void LeaveRoom_ShouldNot_ErrorOnBlankNullRoomName() { var repo = new Mock <IMessageRepository>(); var mockGroups = new Mock <IGroupManager>(); var target = new ChatHub(repo.Object) { Groups = mockGroups.Object }; try { target.LeaveRoom(null); target.LeaveRoom(""); } catch { Assert.Fail("Null/empty string should be ignored"); } }
public void LeaveRoom_Should_CallRemoveFromGroup() { const string roomname = "room_to_leave"; const string connectionId = "LeaveRoomTestConnection"; var repo = new Mock <IMessageRepository>(); var mockGroups = new Mock <IGroupManager>(); var mockContext = new Mock <HubCallerContext>(); mockContext.SetupGet(c => c.ConnectionId).Returns(connectionId); var target = new ChatHub(repo.Object) { Groups = mockGroups.Object, Context = mockContext.Object }; //Calling this should invoke the AddToGroupAsync method only once, and for the room name we send in target.LeaveRoom(roomname); mockGroups.Verify(g => g.RemoveFromGroupAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()), Times.Once); mockGroups.Verify(g => g.RemoveFromGroupAsync(It.Is <string>(i => i == connectionId), It.Is <string>(r => r == roomname), It.IsAny <CancellationToken>()), Times.Once); }