Example #1
0
        public void Load_ShouldIgnoreDataWhenItsLengthIsGreatherThanItsActualBytes()
        {
            var ssh = new SshDataStream(1);
            ssh.WriteByte(2); // Type
            ssh.Write(5u); // Data length
            ssh.Write(new byte[3]); // Data

            var ignoreMessageBytes = ssh.ToArray();

            var ignoreMessage = new IgnoreMessage();
            ignoreMessage.Load(ignoreMessageBytes, 1, ignoreMessageBytes.Length - 1);
            Assert.IsNotNull(ignoreMessage.Data);
            Assert.AreEqual(0, ignoreMessage.Data.Length);
        }
Example #2
0
        public void Load()
        {
            var ignoreMessage = new IgnoreMessage(_data);
            var bytes = ignoreMessage.GetBytes();
            var target = new IgnoreMessage();

            target.Load(bytes);

            Assert.IsNotNull(target.Data);
            Assert.AreEqual(_data.Length, target.Data.Length);
            Assert.IsTrue(target.Data.SequenceEqual(_data));
        }
Example #3
0
        public void Load_ShouldThrowNotSupportedExceptionWhenDataLengthIsGreaterThanInt32MaxValue()
        {
            var ssh = new SshDataStream(1);
            ssh.WriteByte(2); // Type
            ssh.Write(uint.MaxValue); // Data length
            ssh.Write(new byte[3]);

            var ignoreMessageBytes = ssh.ToArray();
            var ignoreMessage = new IgnoreMessage();

            try
            {
                ignoreMessage.Load(ignoreMessageBytes, 1, ignoreMessageBytes.Length - 1);
                Assert.Fail();
            }
            catch (NotSupportedException ex)
            {
                Assert.IsNull(ex.InnerException);
                Assert.AreEqual(string.Format(CultureInfo.CurrentCulture, "Data longer than {0} is not supported.", int.MaxValue), ex.Message);
            }
        }