Exemplo n.º 1
0
        public void SetListenPort_Constructs_The_Correct_Message(int port)
        {
            var a   = new SetListenPort(port);
            var msg = a.ToByteArray();

            var reader = new MessageReader <MessageCode.Server>(msg);
            var code   = reader.ReadCode();

            Assert.Equal(MessageCode.Server.SetListenPort, code);
            Assert.Equal(port, reader.ReadInteger());
        }
Exemplo n.º 2
0
        public async Task LoginAsync_Sets_Listen_Port_On_Success_If_Set(string user, string password, int port)
        {
            var waiter = new Mock <IWaiter>();

            waiter.Setup(m => m.Wait <LoginResponse>(It.IsAny <WaitKey>(), null, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(new LoginResponse(true, string.Empty)));

            var conn = new Mock <IMessageConnection>();

            using (var s = new SoulseekClient("127.0.0.1", 1, serverConnection: conn.Object, waiter: waiter.Object, options: new ClientOptions(listenPort: port)))
            {
                s.SetProperty("State", SoulseekClientStates.Connected);

                await s.LoginAsync(user, password);

                Assert.Equal(SoulseekClientStates.Connected | SoulseekClientStates.LoggedIn, s.State);
                Assert.Equal(user, s.Username);
            }

            var expectedBytes = new SetListenPort(port).ToByteArray();

            conn.Verify(m => m.WriteAsync(It.Is <byte[]>(b => b.Matches(expectedBytes)), It.IsAny <CancellationToken?>()));
        }
Exemplo n.º 3
0
        public void SetListenPort_Instantiates_Properly(int port)
        {
            var a = new SetListenPort(port);

            Assert.Equal(port, a.Port);
        }