예제 #1
0
 public BObjectTransform()
 {
     integerTransform = new IntegerTransform();
     byteStringTransform = new ByteStringTransform();
     listTransform = new ListTransform(this);
     dictionaryTransform = new DictionaryTransform(this);
 }
예제 #2
0
        public void ListDecode_EmptyList_Positive()
        {
            BList expectedList = new BList() { Value = new IBObject[] { } };

            var inputBytes = "le".GetASCIIBytes();
            var inputStream = new MemoryStream(inputBytes);

            var transform = new ListTransform(new BObjectTransform());
            BList actualList = transform.Decode(inputStream);

            Assert.AreEqual<BObjectType>(expectedList.BType, actualList.BType);
            Assert.AreEqual<int>(actualList.Value.Length, expectedList.Value.Length);
        }
예제 #3
0
        public void ListDecode_NestedList_Positive()
        {
            BList expectedList = new BList()
            {
                Value = new IBObject[]
                {
                    new BList() { Value = new IBObject[] { } }
                }
            };

            var inputBytes = "llee".GetASCIIBytes();
            var inputStream = new MemoryStream(inputBytes);

            var transform = new ListTransform(new BObjectTransform());
            BList actualList = transform.Decode(inputStream);

            // Validate outer list:
            Assert.AreEqual<BObjectType>(expectedList.BType, actualList.BType);
            Assert.AreEqual<int>(1, actualList.Value.Length);

            // Validate nested list:
            Assert.AreEqual<BObjectType>(BObjectType.List, actualList.Value[0].BType);
            Assert.AreEqual<int>(0, ((BList)actualList.Value[0]).Value.Length);
        }
예제 #4
0
        public void ListDecode_RegularList_Positive()
        {
            BList expectedList = new BList()
            {
                Value = new IBObject[]
                {
                    new BInteger(9L), new BByteString() { Value = "spam".GetASCIIBytes() }
                }
            };

            var inputBytes = "li9e4:spame".GetASCIIBytes();
            var inputStream = new MemoryStream(inputBytes);

            var transform = new ListTransform(new BObjectTransform());
            BList actualList = transform.Decode(inputStream);

            Assert.AreEqual<BObjectType>(expectedList.BType, actualList.BType);
            Assert.AreEqual<int>(expectedList.Value.Length, actualList.Value.Length);

            Assert.AreEqual<BObjectType>(expectedList.Value[0].BType, actualList.Value[0].BType);

            Assert.AreEqual<long>(
                ((BInteger)expectedList.Value[0]).Value,
                ((BInteger)actualList.Value[0]).Value);

            Assert.AreEqual<string>(
                ((BByteString)expectedList.Value[1]).ConvertToText(Encoding.ASCII),
                ((BByteString)actualList.Value[1]).ConvertToText(Encoding.ASCII));
        }
예제 #5
0
 public void ListDecode_NullListParam_Exception()
 {
     var transform = new ListTransform(new BObjectTransform());
     transform.Decode(null);
 }
예제 #6
0
 public void ListTransform_ValidCtorParam_Positive()
 {
     var transform = new ListTransform(new BObjectTransform());      // test that this does not cause exception
     Assert.IsNotNull(transform);
 }
예제 #7
0
 public void ListTransform_NullCtorParam_Exception()
 {
     var transform = new ListTransform(null);
 }
예제 #8
0
        public void ListEncode_PopulatedList_Positive()
        {
            BList inputList = new BList()
            {
                Value = new IBObject[]
                {
                    new BInteger(9L), new BByteString() { Value = "spam".GetASCIIBytes() }
                }
            };

            var expectedBytes = "li9e4:spame".GetASCIIBytes();
            var outputStream = new MemoryStream();

            var transform = new ListTransform(new BObjectTransform());

            transform.Encode(inputList, outputStream);

            outputStream.Position = 0;
            var actualBytes = outputStream.ToArray();

            Assert.IsTrue(expectedBytes.IsEqualWith(actualBytes), "Bytes returned does not match expected bytes");
        }
예제 #9
0
        public void ListEncode_NullOutputStream_Exception()
        {
            BList inputList = new BList() { Value = new IBObject[] { } };
            var transform = new ListTransform(new BObjectTransform());

            transform.Encode(inputList, null);
        }
예제 #10
0
        public void ListEncode_NullListParam_Exception()
        {
            var outputStream = new MemoryStream();
            var transform = new ListTransform(new BObjectTransform());

            transform.Encode(null, outputStream);
        }
예제 #11
0
        public void ListEncode_NestedList_Positive()
        {
            // A list with an empty list as it's only item:
            BList inputList = new BList()
            {
                Value = new IBObject[]
                {
                    new BList()
                    {
                        Value = new IBObject[] { }
                    }
                }
            };

            var expectedBytes = "llee".GetASCIIBytes();
            var outputStream = new MemoryStream();

            var transform = new ListTransform(new BObjectTransform());

            transform.Encode(inputList, outputStream);

            outputStream.Position = 0;
            var actualBytes = outputStream.ToArray();

            Assert.IsTrue(expectedBytes.IsEqualWith(actualBytes), "Bytes returned does not match expected bytes");
        }