private IUserInfo Join(bool loggedIn, ConnectionBuffer connection, string nickname, string serverPassword) { connection.SendAsync(new JoinMessage(nickname, serverPassword)); var joinResultMessage = connection.DequeueAndAssertMessage <JoinResultMessage>(); Assert.AreEqual(LoginResultState.Success, joinResultMessage.Result); if (!loggedIn) { connection.DequeueAndAssertMessage <PermissionsMessage>(); } var userJoinedMessage = connection.DequeueAndAssertMessage <UserJoinedMessage>(); IUserInfo user = userJoinedMessage.UserInfo; Assert.AreEqual(nickname, userJoinedMessage.UserInfo.Nickname); Assert.AreEqual(joinResultMessage.UserInfo.Username, userJoinedMessage.UserInfo.Username); Assert.AreEqual(joinResultMessage.UserInfo.UserId, userJoinedMessage.UserInfo.UserId); Assert.AreEqual(joinResultMessage.UserInfo.CurrentChannelId, userJoinedMessage.UserInfo.CurrentChannelId); //connection.Client.DequeueAndAssertMessage<ChannelListMessage>(); //var usermsg = connection.Client.DequeueAndAssertMessage<UserInfoListMessage>(); //Assert.IsNotNull (usermsg.Users.FirstOrDefault (u => u.UserId == userJoinedMessage.UserInfo.UserId)); //connection.Client.DequeueAndAssertMessage<SourceListMessage>(); return(user); }
private ConnectionBuffer Login(string username, string password) { ConnectionBuffer connection = Connect(); connection.SendAsync(new LoginMessage { Username = username, Password = password }); var loginResultMessage = connection.DequeueAndAssertMessage <LoginResultMessage>(); Assert.IsTrue(loginResultMessage.Result.Succeeded); connection.DequeueAndAssertMessage <PermissionsMessage>(); return(connection); }
private ConnectionBuffer Connect() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new ConnectMessage { ProtocolVersion = GablarskiProtocol.Instance.Version, Host = "test", Port = 42912 }); connection.DequeueAndAssertMessage <ServerInfoMessage>(); connection.DequeueAndAssertMessage <ChannelListMessage>(); connection.DequeueAndAssertMessage <UserInfoListMessage>(); connection.DequeueAndAssertMessage <SourceListMessage>(); return(connection); }
public void ServerInfo() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new ConnectMessage { ProtocolVersion = GablarskiProtocol.Instance.Version }); var msg = connection.DequeueAndAssertMessage <ServerInfoMessage>(); Assert.AreEqual(this.settings.Name, msg.ServerInfo.Name); Assert.AreEqual(this.settings.Description, msg.ServerInfo.Description); Assert.IsNull(msg.ServerInfo.Logo); }
public void RequestChannelList() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new RequestChannelListMessage()); Message message = connection.DequeueMessage(); Assert.IsInstanceOf <ChannelListMessage> (message); var list = (ChannelListMessage)message; Assert.AreEqual(GenericResult.Success, list.Result); Assert.IsNotNull(list.Channels); CollectionAssert.IsNotEmpty(list.Channels); }
public void OldVersionReject() { var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new ConnectMessage { ProtocolVersion = 0 }); Message message = connection.DequeueMessage(); Assert.IsInstanceOf <ConnectionRejectedMessage> (message); var rejected = (ConnectionRejectedMessage)message; Assert.AreEqual(ConnectionRejectedReason.IncompatibleVersion, rejected.Reason); }
public void RedirectMatch() { server.AddRedirector(new MockRedirector("monkeys.com", new IPEndPoint(IPAddress.Any, 6113))); var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new ConnectMessage { ProtocolVersion = GablarskiProtocol.Instance.Version, Host = "monkeys.com", Port = 42912 }); var msg = connection.DequeueAndAssertMessage <RedirectMessage>(); Assert.AreEqual(IPAddress.Any.ToString(), msg.Host); Assert.AreEqual(6113, msg.Port); }
public void RedirectNoMatch() { server.AddRedirector(new MockRedirector("monkeys.com", new IPEndPoint(IPAddress.Any, 6113))); var cs = provider.GetConnections(GablarskiProtocol.Instance); var connection = new ConnectionBuffer(cs.Item1); connection.SendAsync(new ConnectMessage { ProtocolVersion = GablarskiProtocol.Instance.Version, Host = "monkeys2.com", Port = 42912 }); var msg = connection.DequeueAndAssertMessage <ServerInfoMessage>(); Assert.AreEqual(this.settings.Name, msg.ServerInfo.Name); Assert.AreEqual(this.settings.Description, msg.ServerInfo.Description); Assert.IsNull(msg.ServerInfo.Logo); }