Example #1
0
        public void TestToBytes()
        {
            List <Variable> vList = new List <Variable>
            {
                new Variable(
                    new ObjectIdentifier(new uint[] { 1, 3, 6, 1, 4, 1, 2162, 1001, 21, 0 }),
                    new OctetString("TrapTest"))
            };

            Sequence a = Variable.Transform(vList);

            Assert.Throws <ArgumentNullException>(() => a.AppendBytesTo(null));
            Assert.AreEqual("SNMP SEQUENCE: SNMP SEQUENCE: .1.3.6.1.4.1.2162.1001.21.0; TrapTest; ; ", a.ToString());
            byte[]    bytes = a.ToBytes();
            ISnmpData data  = DataFactory.CreateSnmpData(bytes);

            Assert.AreEqual(SnmpType.Sequence, data.TypeCode);
            Sequence array = (Sequence)data;

            Assert.AreEqual(1, array.Length);
            ISnmpData item = array[0];

            Assert.AreEqual(SnmpType.Sequence, item.TypeCode);
            Sequence v = (Sequence)item;

            Assert.AreEqual(2, v.Length);
            Assert.AreEqual(SnmpType.ObjectIdentifier, v[0].TypeCode);
            ObjectIdentifier o = (ObjectIdentifier)v[0];

            Assert.AreEqual(new uint[] { 1, 3, 6, 1, 4, 1, 2162, 1001, 21, 0 }, o.ToNumerical());
            Assert.AreEqual(SnmpType.OctetString, v[1].TypeCode);
            Assert.AreEqual("TrapTest", v[1].ToString());
        }