Ejemplo n.º 1
0
        public void GetBytes()
        {
            var random = new Random();

            var localChannelNumber = (uint) random.Next(0, int.MaxValue);
            var data = new byte[random.Next(10, 20)];
            random.NextBytes(data);
            var offset = random.Next(2, 4);
            var size = random.Next(5, 9);

            var target = new ChannelDataMessage(localChannelNumber, data, offset, size);

            var bytes = target.GetBytes();

            var expectedBytesLength = 1; // Type
            expectedBytesLength += 4; // LocalChannelNumber
            expectedBytesLength += 4; // Data length
            expectedBytesLength += size; // Data

            Assert.AreEqual(expectedBytesLength, bytes.Length);

            var sshDataStream = new SshDataStream(bytes);

            Assert.AreEqual(ChannelDataMessage.MessageNumber, sshDataStream.ReadByte());
            Assert.AreEqual(localChannelNumber, sshDataStream.ReadUInt32());
            Assert.AreEqual((uint) size, sshDataStream.ReadUInt32());

            var actualData = new byte[size];
            sshDataStream.Read(actualData, 0, size);
            Assert.IsTrue(actualData.SequenceEqual(data.Take(offset, size)));

            Assert.IsTrue(sshDataStream.IsEndOfData);
        }
Ejemplo n.º 2
0
        public void Load()
        {
            var random = new Random();

            var localChannelNumber = (uint) random.Next(0, int.MaxValue);
            var data = new byte[random.Next(10, 20)];
            random.NextBytes(data);

            var offset = random.Next(2, 4);
            var size = random.Next(5, 9);
            var channelDataMessage = new ChannelDataMessage(localChannelNumber, data, offset, size);
            var bytes = channelDataMessage.GetBytes();
            var target = new ChannelDataMessage();

            target.Load(bytes);

            Assert.IsTrue(target.Data.SequenceEqual(data.Take(offset, size)));
            Assert.AreEqual(0, target.Offset);
            Assert.AreEqual(size, target.Size);
        }