예제 #1
0
        public void RequestBytes_Selector_SendsSelectorValue()
        {
            var tcp    = new Simple(tcpClient);
            var stream = new MemoryStream();

            tcpClient.Connected.Returns(true);
            tcpClient.GetStream().Returns <Stream>(stream);

            tcp.Open("", 0);
            tcp.RequestBytes("info");

            tcpClient.Received(1).GetStream();

            byte[] data = new byte[stream.Length];

            stream.Position = 0;
            stream.Read(data, 0, data.Length);

            var result = new string(Encoding.ASCII.GetChars(data));

            Assert.AreEqual("info", result);
        }
예제 #2
0
        public async Task Request_ListInfo_SendsListCommand()
        {
            var connection = new Async(tcpClient);
            var stream     = new MemoryStream();

            tcpClient.Connected.Returns(true);
            tcpClient.GetStream().Returns <Stream>(stream);

            await connection.OpenAsync("", 0);

            await connection.RequestAsync("info");

            tcpClient.Received(1).GetStream();

            byte[] data = new byte[stream.Length];

            stream.Position = 0;
            stream.Read(data, 0, data.Length);

            var result = new string(Encoding.ASCII.GetChars(data));

            Assert.AreEqual("info", result);
        }