Esempio n. 1
0
 public BObjectTransform()
 {
     integerTransform = new IntegerTransform();
     byteStringTransform = new ByteStringTransform();
     listTransform = new ListTransform(this);
     dictionaryTransform = new DictionaryTransform(this);
 }
        public void DecodeByteString_InsaneByteStringLength_Exception()
        {
            var input = "12345678901234567890:123";
            var inputStream = new MemoryStream(Encoding.ASCII.GetBytes(input), false);

            var transform = new ByteStringTransform();
            var bstrObj = transform.Decode(inputStream);
        }
        public void DecodeByteString_NotEnoughBytesInInput_Exception()
        {
            var input = "100:12345";
            var inputStream = new MemoryStream(Encoding.ASCII.GetBytes(input), false);

            var transform = new ByteStringTransform();
            var bstrObj = transform.Decode(inputStream);
        }
        public void DecodeByteString_NoBytesInInput_Positive()
        {
            var inputStream = new MemoryStream(new byte[] { 48, 58 }, false);       // "0:"

            var transform = new ByteStringTransform();
            var bstrObj = transform.Decode(inputStream);

            Assert.AreEqual<long>(0L, bstrObj.Value.Length);
        }
        public void DecodeByteString_SimpleScenario_Positive()
        {
            var inputStream = new MemoryStream(new byte[] { 52, 58, 49, 50, 51, 52 }, false);       // "4:1234"
            var expectedOutput = new byte[] { 49, 50, 51, 52 };

            var transform = new ByteStringTransform();
            var bstrObj = transform.Decode(inputStream);

            Assert.IsTrue(expectedOutput.IsEqualWith(bstrObj.Value), "Outputted bytes are different than expected");
        }
 public void DecodeByteString_NullInputStream_Exception()
 {
     var transform = new ByteStringTransform();
     var bstrObj = transform.Decode(null);
 }
        public void EncodeByteString_SimpleScenario_Positive()
        {
            // Prepare input and expected output value
            byte[] inputBytes = {1,2,3,4};

            byte[] expectedBytes = {0,0,1,2,3,4};
            expectedBytes[0] = EncodingHelper.GetASCIIValue('4');
            expectedBytes[1] = EncodingHelper.GetASCIIValue(':');

            MemoryStream outputStream = new MemoryStream(6);

            // Do encoding
            BByteString bstrObj = new BByteString()
            {
                Value = inputBytes
            };

            var transform = new ByteStringTransform();
            transform.Encode(bstrObj, outputStream);

            // Check results
            Assert.AreEqual<long>(expectedBytes.LongLength, outputStream.Position);         // Ensure 6 bytes were (likely) written

            outputStream.Position = 0;
            byte[] outputtedBytes = outputStream.ToArray();

            Assert.IsTrue(outputtedBytes.IsEqualWith(expectedBytes), "Outputted bytes are different than expected");
        }
        public void EncodeByteString_NullOutputStream_Exception()
        {
            BByteString bstrObj = new BByteString()
            {
                Value = new byte[] { }
            };

            var transform = new ByteStringTransform();
            transform.Encode(bstrObj, null);
        }
        public void EncodeByteString_NullInputObject_Exception()
        {
            MemoryStream outputStream = new MemoryStream();

            var transform = new ByteStringTransform();
            transform.Encode(null, outputStream);
        }
        public void EncodeByteString_NoBytesInInput_Positive()
        {
            // Prepare input and expected output value
            byte[] inputBytes = { };

            byte[] expectedBytes = { 0, 0 };
            expectedBytes[0] = EncodingHelper.GetASCIIValue('0');
            expectedBytes[1] = EncodingHelper.GetASCIIValue(':');

            MemoryStream outputStream = new MemoryStream(6);

            // Do encoding
            BByteString bstrObj = new BByteString()
            {
                Value = inputBytes
            };

            var transform = new ByteStringTransform();
            transform.Encode(bstrObj, outputStream);

            // Check results
            outputStream.Position = 0;
            byte[] outputtedBytes = outputStream.ToArray();

            Assert.IsTrue(outputtedBytes.IsEqualWith(expectedBytes), "Outputted bytes are different than expected");
        }