コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }