public void Connect() { hub.Connect("0"); UpdateClientConnect(LAST); hub.Connect("1"); int i = 0; foreach (ICall call in hub.ReceivedCalls()) { Assert.AreEqual("TestUser" + i + " connected", ((ChatMessage)(call.GetArguments()[0])).Message); Assert.AreEqual("SYSTEM", ((ChatMessage)(call.GetArguments()[0])).User.UserName); i++; } Assert.AreEqual(2, i); // 2 items }
public async Task <ActionResult> Login(LoginModel model, string returnUrl) { if (ModelState.IsValid) { Person person = await UserManager.FindAsync(model.Email, model.Password); if (person == null) { ModelState.AddModelError("", "Неверный логин или пароль."); } else { ClaimsIdentity claim = await UserManager.CreateIdentityAsync(person, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignOut(); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = true }, claim); if (String.IsNullOrEmpty(returnUrl)) { ChatHub hub = new ChatHub(); hub.Connect(person); return(RedirectToAction("Index", "Home")); } return(Redirect(returnUrl)); } } ViewBag.returnUrl = returnUrl; return(View(model)); }
public void CallGroupsAddWithCorrectConnectionId() { // Arrange var mockedService = new Mock <IUsersService>(); var chatHub = new ChatHub(mockedService.Object); var mockedGroups = new Mock <IGroupManager>(); mockedGroups.Setup(x => x.Add(It.IsAny <string>(), It.IsAny <string>())).Verifiable(); chatHub.Groups = mockedGroups.Object; var mockedUserIdentity = new Mock <IIdentity>(); var mockedContext = new Mock <HubCallerContext>(); mockedContext.Setup(x => x.User.Identity).Returns(mockedUserIdentity.Object); var connectionId = "12345"; mockedContext.Setup(x => x.ConnectionId).Returns(connectionId); chatHub.Context = mockedContext.Object; // Act chatHub.Connect("username"); // Assert mockedGroups.Verify(x => x.Add(connectionId, It.IsAny <string>()), Times.Once); }
public void CallGroupsAddWithCorrectGroupName() { // Arrange var mockedService = new Mock <IUsersService>(); var chatHub = new ChatHub(mockedService.Object); var mockedGroups = new Mock <IGroupManager>(); mockedGroups.Setup(x => x.Add(It.IsAny <string>(), It.IsAny <string>())).Verifiable(); chatHub.Groups = mockedGroups.Object; var mockedUserIdentity = new Mock <IIdentity>(); var mockedContext = new Mock <HubCallerContext>(); mockedContext.Setup(x => x.User.Identity).Returns(mockedUserIdentity.Object); chatHub.Context = mockedContext.Object; // caller username is empty string var username = "******"; var groupname = "_" + username; // Act chatHub.Connect(username); // Assert mockedGroups.Verify(x => x.Add(It.IsAny <string>(), groupname), Times.Once); }
private void Start() { chatHub.Connect(); chatHub.OnJoinAction += ChatHub_OnJoin; chatHub.OnLeaveAction += ChatHub_OnLeave; chatHub.OnSendMessageEvent += ChatHub_OnSendMessage; }